Jump to content
  • Advertisement
Sign in to follow this  
Schrompf

Possible bug report: constant to const reference binding

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

Hello there,

I registered the following function at an AngelScript engine

RegisterGlobalFunction( "void DoSomething( const float&)", asFUNCTIONPR( Helper::DoSomething, (const float&), void), AS_CDECL));


which results in an error "Not a valid reference" when I tried to compile the following statement

DoSomething( 1.0f);


The const float& parameter isn't exactly necessary here, it was just the consequence of a template function specialised to float. After writing a little wrapper to take the parameter by value:

RegisterGlobalFunction( "void DoSomething( float)", asFUNCTIONPR( Helper::DoSomething, (float), void), AS_CDECL));


the script statement compiles fine. So it seems to me as if AngelScript can't bind number literals to a constant reference. Is this intentional behaviour or an omission? I've solved it for myself now, but it might be useful for others, as well.

Best regards

Bye, Thomas

Share this post


Link to post
Share on other sites
Advertisement
I assume you forgot to include the 'in' when typing the post, otherwise the registration of the function should have failed, unless you've configured the engine to allow unsafe references.

A reference to a literal constant would indeed be invalid, however as it is a const reference it would be possible to make an implicit variable and reference that instead. I'll analyse this for a future release.

Share this post


Link to post
Share on other sites
Sorry for reporting so late. You are right - I keep forgetting the "in" at all reference parameters, and I have activated "unsafe references" at the engine. It still does not work with number literals, even with the "in" keyword attached, but you already explained that, too. Thanks for your response!

Even though the topic is done, may I ask why the "in" is necessary at const references? Those can never be anything else but "in" parameters. Or do I miss something here?

Share this post


Link to post
Share on other sites
You're right a const reference cannot be anything else but an 'in' reference. The in keyword is only there for consistency sake.

In version 3.0 I plan to change the syntax on how function parameters are declared &in won't be necessary. It doesn't really matter to the script writer if a function takes a parameter as const &in, &in, or just by value. To the calling function it is all the same, so it shouldn't be necessary for the script writer to have to write the &. It will still be necessary to inform it for the application registered functions though, so the script engine knows how to call them.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!