Advertisement

Overloaded functions with objet parameters

Started by January 07, 2010 04:11 PM
0 comments, last by WitchLord 15 years, 1 month ago
I'm new to AngelScript so I have some dumb questions. How can I register an overloaded function with objects as parameters?

m_pASEngine->RegisterGlobalFunction("bool LoadScene(const string ∈)", asFUNCTIONPR(LoadScene, (string), bool), asCALL_CDECL);
It won't work because the object triggers the cast instead. One more question, what's the best way to register constants to the script? Can I do like engine->RegisterGlobalProperty("const unsigned long SPACE_KEY", &number); Thanks in advance.
...
What do you mean that 'the object triggers the cast'?


The function signature in your code doesn't match what you tell AngelScript, so this would cause errors when the function is called from the script. It should be:

m_pASEngine->RegisterGlobalFunction("bool LoadScene(const string ∈)", asFUNCTIONPR(LoadScene, (const string&), bool), asCALL_CDECL);


or

m_pASEngine->RegisterGlobalFunction("bool LoadScene(string)", asFUNCTIONPR(LoadScene, (string), bool), asCALL_CDECL);


You need to check what the real signature is for the LoadScene function.



If you want the script compiler to treat the constants as real constants, instead of just read-only variables, then the best way is either to register them as enums (only for integer constants) or declare them in the script. The application can add an extra script section to all modules that are compiled that holds the constants.

engine->RegisterEnum("EKEY");engine->RegisterEnumValue("EKEY", "SPACE_KEY", SPACE_KEY);


alternative:

// Add the constants as a hidden script sectionconst char *constDecl = "const uint32 SPACE_KEY = 32;";mod->AddScriptSection("Constants", constDecl);// Then add the other sections normally and build the script


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

This topic is closed to new replies.

Advertisement