Jump to content
  • Advertisement
Sign in to follow this  
TcShadowWalker

Variable Arguments for reference types

This topic is 1426 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
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);

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!