Jump to content
  • Advertisement
Sign in to follow this  
Wavesonics

Registering functions with overloads?

This topic is 3441 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
You can use the asMETHODPR() macro instead of asMETHOD(). Ex:

asMETHODPR(Creep, health, (int), void)

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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 );


Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!