Advertisement

const broken?

Started by March 14, 2005 03:49 AM
1 comment, last by kaysik 19 years, 8 months ago
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()

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);
}



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

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

Advertisement
Sweet - that would explain it. All seems to be working fine now without const, i'll just have to remember to put it back in when the next version comes out. Good luck with that too, you've timed it almost perfectly because I've just started working on putting scripting into my stuff.

This topic is closed to new replies.

Advertisement