Sign in to follow this  

Variable Arguments for reference types

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

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

This topic is 1210 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.

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