Search code examples
c++angelscript

Angelscript - Expected ',' or ')'


So it would appear that Angelscript is being rather inconsistent with what functions it will allow me to handle. I'm trying to declare a global function thusly:

scrpEngine->RegisterGlobalFunction("float sin(float in)", asFUNCTION(sinCallback), asCALL_CDECL);

My sin callback function (which is to call the sin function without worrying about it being overloaded) looks something like this:

float sinCallback(float in) {
    return sin(in);
}

Whenever I compile the script, I get errors, specifically these:

ERROR: System function (1:17) : Expected ')' or ','
ERROR:  (0:0) : Failed in call to function 'RegisterGlobalFunction' with 'float sin(float in)' (Code: -10)

Checking the documentation and header files, this error code pertains to invalid syntax..however the syntax of the function declaration definitely SHOULD be valid. Anyone have any ideas?


Solution

  • I think the problem is the signature you are registering your function with: float sin(float in).
    I'm assuming "in" is supposed to be the name of the parameter as per your C++ function, but AngelScript has the in/out/inout specifiers for references, i.e. float sin(float &in).

    This might be a bug, or it might be documented somewhere that you can't use these keywords as function parameter names.

    If you just change the name of the parameter in the signature (no change necessary in your callback function) ( e.g. float sin(float f)) or drop it entirely (float sin(float), since it's not required in the signature at all), your function should register fine.