Jump to content
  • Advertisement
Sign in to follow this  
kaysik

const broken?

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

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?

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!