Sign in to follow this  
TcShadowWalker

Variable Arguments for reference types

Recommended Posts

TcShadowWalker    138

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

Share this post


Link to post
Share on other sites
TcShadowWalker    138

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this