🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

problem with "RegisterGlobalFunction(...)"

Started by
5 comments, last by WitchLord 18 years, 4 months ago
The following code gives me problems (r=-10): ... void moo(std::string& s) { // .... } int r = engine->RegisterGlobalFunction("void _moo(std::string&)", asFUNCTIONPR(moo, (std::string&), void), asCALL_CDECL); assert( r >= 0 ); Any idea why this is failing ? Btw, i dont want to use the "using namespace std".
Advertisement
Did you check the return code? It should be tossing 'invalid declaration', which I believe is -10. AngelScript has no idea what std::string is. You can register std::string - but you can't give it a name with :: in it. Assuming you properly bound std::string to as with the type name 'string', your code would be

int r = engine->RegisterGlobalFunction("void _moo(string& inout)", asFUNCTIONPR(moo, (std::string&), void), asCALL_CDECL); assert( r >= 0 );

I was suspecting "std::string" too, so i tried it with "using namespace std" and just "string", got the same result : -10 (which means INVALID DECLARATION).
Not sure of that but :
replace RegisterGlobalFunction("void _moo(std::string&)"...
with RegisterGlobalFunction("void NothingElseThanATozInFirstPlaceChar_moo(std::string&)"

It might help, but not sure.

AbrKen.
AngelScript doesn't understand namespaces at the moment, so the 'std::' part of the declaration must be left out.

The 'string' type is also not a built-in type in AngelScript, so it must be registered before you can register any functions using it. How did you register the 'string' type? For an example on how a string type can be registered, look at the scriptstring.cpp in the add_on folder.

Finally when registering a function parameter as a reference, you must also specify one of the keywords 'in', 'out', or 'inout'. Otherwise AngelScript will give an error since it must know how you intend to use the value in the reference.

If you set the message stream, with SetCommonMessageStream(), before calling the RegisterGlobalFunction() method you'll get more information about the error that you have.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

... I believe I already said that WL.
Indeed you did. Your statement correctly identified the problem. I was just trying to give more information, to help him move forward with his project. [smile]

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement