Sign in to follow this  

@+& fails

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

Hey I've got this case where I want to pass a reference of an object out of a method through a reference argument. I.e. I have something like this: bool Raycast(blah, blah, Entity* &hitEntity, blah, blah) { ... hitEntity = someEntity; ... } I'd kinda like to register this to AngelScript like "Raycast(blah, Entity@+ &out, blah)", but it seems the engine won't accept that. Is there some better way of doing this? My current workaround is a wrapper that just increases the reference counter to the passed entity instead, and just register it as "Raycast(blah, Entity@ &out, blah)", but I'd rather not have to do that. Thanks in advance

Share this post


Link to post
Share on other sites
i've noticed too that defining a script function with an object passed as reference to a handle (@&), when accessing the object, i get a segfault in the vm instead of getting an exception... i dunnow if i'm doing something wrong or the @& case isn't handled correctly...

Share this post


Link to post
Share on other sites
i think i'm a bit cludging with the library possibilities, i can't post the
initial script that made me discover this (it's in angeljuice), but i've taken
the test_scriptstring.cpp and i've modified those bits:

original working file

engine->RegisterGlobalFunction("void set(string@)", asFUNCTION(SetString), asCALL_GENERIC);
// ...
printOutput = "";
engine->ExecuteString(0, "string a; set(@a); print(a);");
if( printOutput != "Handle to a string" ) fail = true;



this is working also

engine->RegisterGlobalFunction("void set(string@)", asFUNCTION(SetString), asCALL_GENERIC);
// ...
printOutput = "";
engine->ExecuteString(0, "string a; set(a); print(a);");
if( printOutput != "Handle to a string" ) fail = true;



this is reporting a test failed

engine->RegisterGlobalFunction("void set(string@ &in)", asFUNCTION(SetString), asCALL_GENERIC);
// ...
printOutput = "";
engine->ExecuteString(0, "string a; set(@a); print(a);");
if( printOutput != "Handle to a string" ) fail = true;



this is segfaulting

engine->RegisterGlobalFunction("void set(string@ &in)", asFUNCTION(SetString), asCALL_GENERIC);
// ...
printOutput = "";
engine->ExecuteString(0, "string a; set(a); print(a);");
if( printOutput != "Handle to a string" ) fail = true;



ah, trying to make the test_features in linux (gnuc makefile) with revision 76 the TestFor unit test is left out in the makefile itself (so it will not compile), and adding that it will not pass the unit testing at all...

Share this post


Link to post
Share on other sites


engine->RegisterGlobalFunction("void set(string@)", asFUNCTION(SetString), asCALL_GENERIC);
// ...
printOutput = "";
engine->ExecuteString(0, "string a; set(a); print(a);");
if( printOutput != "Handle to a string" ) fail = true;


This is working because AngelScript implicitly converts the argument to a handle.


engine->RegisterGlobalFunction("void set(string@ &in)", asFUNCTION(SetString), asCALL_GENERIC);
// ...
printOutput = "";
engine->ExecuteString(0, "string a; set(@a); print(a);");
if( printOutput != "Handle to a string" ) fail = true;


This is not working because you need to change the SetString() implementation. You're now actually receiving a pointer to a pointer to a asCScriptString object.


engine->RegisterGlobalFunction("void set(string@ &in)", asFUNCTION(SetString), asCALL_GENERIC);
// ...
printOutput = "";
engine->ExecuteString(0, "string a; set(a); print(a);");
if( printOutput != "Handle to a string" ) fail = true;


This should probably have given the same error as the previous, as the compiler should have implicitly converted the argument to a reference to a handle. I'll have to verify why that didn't work.

Ah, the TestFor is currently reproducing a bug in AngelScript that I need to fix. You'll need to skip this test for now.

Regards,
Andreas

Share this post


Link to post
Share on other sites
yes i know that i need to modify the SetString emthod as is changed the way the object is passed on that function, that's obvious. but i was just stating that instead of exiting with an exception like the third test, the fourth case was reporting a segmentation fault (but imho test 3 and 4 are equals, even if the compiler converts the variable or not).

;)

Share this post


Link to post
Share on other sites

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