Variable Arguments for reference types

Started by
0 comments, last by TcShadowWalker 9 years, 8 months ago

Hi,

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

http://www.angelcode.com/angelscript/sdk/docs/manual/doc_adv_var_type.html

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->SetDefaultNamespace("Engine");
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 :)

Advertisement

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

This topic is closed to new replies.

Advertisement