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
----------
Gonna try that "Indie" stuff I keep hearing about. Let's start with Splatter.
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.
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?
----------
Gonna try that "Indie" stuff I keep hearing about. Let's start with Splatter.
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.