Registering functions with overloads?

Started by
14 comments, last by dxj19831029 15 years, 2 months ago
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:

    // 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 );


My problem though is, "int health()" has an overload: "void health( int )", how do I specify which overload to get?
==============================
A Developers Blog | Dark Rock Studios - My Site
Advertisement
You can use the asMETHODPR() macro instead of asMETHOD(). Ex:
asMETHODPR(Creep, health, (int), void)
Ok, I changed it to:

    // 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
==============================
A Developers Blog | Dark Rock Studios - My Site
What does your Creep class look like? This code:
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?
==============================
A Developers Blog | Dark Rock Studios - My Site
It compiles now, but fails to register with error code: -21

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 );
==============================
A Developers Blog | Dark Rock Studios - My Site
I got things working here.
==============================
A Developers Blog | Dark Rock Studios - My Site
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:

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]
==============================
A Developers Blog | Dark Rock Studios - My Site
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.

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