• Advertisement
Sign in to follow this  

Variable Arguments for reference types

This topic is 1305 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



I'm trying to use variable arguments for a function, as mentioned here:


However, this does not seem to work with reference types:

asIScriptEngine *e = ...;
e->RegisterObjectType("GameObject", 0, asOBJ_REF)
e->RegisterObjectBehaviour("GameObject", asBEHAVE_ADDREF, "void f()", asMETHOD(...), asCALL_THISCALL);
e->RegisterObjectBehaviour("GameObject", asBEHAVE_RELEASE, "void f()", asMETHOD(...), asCALL_THISCALL);
// There are no copy-constructors or factory functions defined for GameObject.
e->RegisterGlobalFunction("void setAiPackage(::GameObject@, ?&in, ?&in)",
                                 asFUNCTION(setAiPackage), asCALL_GENERIC, 0);
void setAiPackage (asIScriptGeneric *gen) {
     // This works, since argument is passed by handle: "GameObject@"
     GameObject *s1 = (GameObject*)gen->GetArgObject(0);
     // However, this does not work:
     GameObject *s2 = (GameObject*)gen->GetArgAddress(1);
     // s2 points to some address, but is not a valid GameObject. It's also not the same as s1.

AngelScript Code:

void test (GameObject @game_obj) {
    Engine::setAiPackage(game_obj, @game_obj, null);

My problem is in the setAiPackage function. How to handle the reference type parameters?

I tried fiddling with CScriptHandle, but that did not work.

I presume that gen->GetArgAddress(1) is an asIScriptObject. But I can't use that from the application, can I?


Thanks in advance :)

Share this post

Link to post
Share on other sites

Ok, fixed it.

Took a lot of time until I realized that I actually have a reference to a handle.

Which, of course, is a pointer to a pointer. Solution:

GameObject *s2 = *(GameObject**)gen->GetArgAddress(1);

Share this post

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

  • Advertisement