void echoF(const float val)
{
// print the float value to my console
con->log(LT_NORM, "Val = [%f]", val);
}
// i register that function in init() like so
{
asEng = asCreateScriptEngine(ANGELSCRIPT_VERSION);
if (asEng == NULL)
{
con->log(LT_ERROR, "AS Engine could not be created");
return false;
}
int r = asEng->RegisterGlobalFunction("void echoF(const float val)", asFUNCTION(echoF), asCALL_CDECL);
// r is always -10, which always makes the app die
assert(r >= 0);
}
🎉 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!
const broken?
I'm just starting to finally get around to putting scripting into my game and for about an hour I've been trying to work out why I couldn't register a global function. After alot of mucking about it seems that if the function declaration has a const parameter it borks when I try to register it. This code always produces a value of -10 when i use a "const float" with RegisterGlobalFunction()
I can't find anywhere that it says const parameters aren't legal, but maybe I missed it. If I simple take out the const on the function dec and registration so echoF() accepts a float instead of a const float then it all works fine. Its not a huge deal, but I'm wondering if I've forgotten something really simple or if its meant to be this way?
I temporarily removed const for objects (in AS 2.0.0) as they weren't fully implemented. It was for example possible to change the objects properties even though the object was const. Somewhere along the way I also removed const for parameters (I can't remember the reason for that though).
However, I'm working on reimplementing const for both objects and parameters for the next release. This time it will be fully implemented, where it will be possible to do const-overloading for object methods and behaviours, etc. It's almost finished though it was a bit more complicated than I first thought it would be. I originally thought it would be finished last weekend, but I'm now estimating the coming weekend instead.
Regards,
Andreas
However, I'm working on reimplementing const for both objects and parameters for the next release. This time it will be fully implemented, where it will be possible to do const-overloading for object methods and behaviours, etc. It's almost finished though it was a bit more complicated than I first thought it would be. I originally thought it would be finished last weekend, but I'm now estimating the coming weekend instead.
Regards,
Andreas
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement