Sign in to follow this  
maximegriot

Passing reference as parameter

Recommended Posts

Hello,

 

I am trying to pass an exiting object as a reference to a function but I can't get it to work...

I have tried NPC@ and NPC& as type and nothing seems to work...

I use SetArgObject and give it a pointer to my object (I don't want to copy it because I want to be able to call functions on that object).

If I put the object in a global variable it works just fine...

 

Could you give me some insights ?

 

Thanks !

Share this post


Link to post
Share on other sites

Here it is :

 

NPC npc;
context->Prepare(func);
context->SetArgObject(0, &npc);
context->Execute();
context->Unprepare();

 

And the AS code :

 

void OnNew(NPC @npc)
{
print(npc.GetName());
}

 

 Note that it does work if I set mt NPC to a global parameter so there is nothing wrong with my GetName() :(

Share this post


Link to post
Share on other sites

The code you showed should work. For parameters by handle, like in your case, SetArgObject will call Addref on the object and put the pointer on the stack.

 

Is any of the calls to context's methods returning an error? i.e. a negative value?

Share this post


Link to post
Share on other sites

The thing being I don't have ref counting on these objects (my application manages everything).

 

And no no negative value what's so ever :s

 

My bad, my variadic template call was actually doing a hard copy of the object and passing a stack address that had been deleted.

 

Here is my code if someone wants an easy way to start : https://github.com/yamashi/SkyrimOnline/blob/master/Client/Src/Server/Src/Game/ScriptEngine.hpp

Edited by yamashi-

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