// Register our Creep
r = m_engine->RegisterObjectType("Creep", 0, asOBJ_APP_CLASS );
r = m_engine->RegisterObjectMethod("Creep", "int health() const", asMETHOD(Creep,Creep::health), asCALL_THISCALL); assert( r >= 0 );
Registering functions with overloads?
Now I have a second question, And I can't seem to find this around.
I'm trying to register a Class. Objects of this type will be passed to the script. But I don't want them to be managed by GC or be created inside the scripts.
So, so far this is what I have:
My problem though is, "int health()" has an overload: "void health( int )", how do I specify which overload to get?
You can use the asMETHODPR() macro instead of asMETHOD(). Ex:
asMETHODPR(Creep, health, (int), void)
Ok, I changed it to:
But I'm still getting a compile time error:
I'm compiling with MinGW GCC 4.3.5
// Register our Creep r = m_engine->RegisterObjectType("Creep", 0, asOBJ_APP_CLASS ); r = m_engine->RegisterObjectMethod("Creep", "int health()", asMETHODPR(Creep, health, (int), void), asCALL_THISCALL); assert( r >= 0 );
But I'm still getting a compile time error:
Quote:
|error: address of overloaded function with no contextual type information|
I'm compiling with MinGW GCC 4.3.5
What does your Creep class look like? This code:
Compiles fine under both MSVC 2008 and gcc 3.4.4.
struct Creep { int health(void) const { return 0; }; void health(int) {};};int main(int, char **) { asIScriptEngine * engine; int r; // Register our Creep r = engine->RegisterObjectType("Creep", 0, asOBJ_APP_CLASS ); r = engine->RegisterObjectMethod("Creep", "void health(int)", asMETHODPR(Creep, health, (int), void), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectMethod("Creep", "int health()", asMETHODPR(Creep, health, (void) const, int), asCALL_THISCALL); assert( r >= 0 );}
Compiles fine under both MSVC 2008 and gcc 3.4.4.
Aaahhh it was my bad, the function signature was a short, not an int :/
Thanks for the help!
Btw, are shorts registered by default?
Or do I need to register them?
Thanks for the help!
Btw, are shorts registered by default?
Or do I need to register them?
It compiles now, but fails to register with error code: -21
Also, i am registering short like so:
r = m_engine->RegisterObjectMethod("Creep", "short health()", asMETHODPR(Creep, health, (void), short), asCALL_THISCALL); assert( r >= 0 );
Also, i am registering short like so:
r = m_engine->RegisterObjectType("short", sizeof(short), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_PRIMITIVE); assert( r >= 0 );
You don't need to register short. The AngelScript type that corresponds to short is int16.
If you wish to use the name short you can register a typedef for int16. Example:
If you register 'short' as a new type rather than a typedef, you won't have the benefit of implicit conversions between number types. Unless you also register the cast operators for this.
Also, AngelScript currently allocates all registered types on the heap, so until I get a chance to fix this you'll have a rather large performance hit due to lots of dynamic memory allocations.
Manual: Datatypes in AngelScript and C++
Regards,
Andreas
If you wish to use the name short you can register a typedef for int16. Example:
engine->RegisterTypedef("short", "int16");
If you register 'short' as a new type rather than a typedef, you won't have the benefit of implicit conversions between number types. Unless you also register the cast operators for this.
Also, AngelScript currently allocates all registered types on the heap, so until I get a chance to fix this you'll have a rather large performance hit due to lots of dynamic memory allocations.
Manual: Datatypes in AngelScript and C++
Regards,
Andreas
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
Oh, I didn't see that DataTypes page in the docs that ship with the lib, good resource though.
I'll move to using int16 right away :)
Also, are there any docs around about Control Groups (or was it Config Groups?) for exposing different interfaces to different scripts?
[Edited by - Wavesonics on January 16, 2009 3:39:31 PM]
I'll move to using int16 right away :)
Also, are there any docs around about Control Groups (or was it Config Groups?) for exposing different interfaces to different scripts?
[Edited by - Wavesonics on January 16, 2009 3:39:31 PM]
Only what's in the API reference I'm afraid. Manual: BeginConfigGroup
I'll gladly help you with any doubts you may have on them though.
I'll gladly help you with any doubts you may have on them though.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement