consts in switch and string parameter for entry function
I am embedding AngelScript into my application. The host application calls the main() function into the script. I have no problems passing the int and float parameters to it with asIScriptContext::SetArgDWord() and asIScriptContext::SetArgFloat(), but... how do I pass a string parameter to the main function? The other question: I need to export some defines to the scripts. As AngelScript do not supports them, what I am doing is exporting constants which hold the value (const int EV_INIT = 1, const int EV_FRAME = 2, etc). They do the job, but the problem is that they cannot be used in a switch loop. Do you know any solution for this?
You'll use the method SetArgObject() to pass the string to the script function.
How are you exporting the constants, with RegisterGlobalProperty()? If the script compiler is to use a constant in a switch case the constant must have been declared in the script. Thus, my suggestion for exporting constants from the application to scripts is to construct a script section and add it to the module together with the real script.
I will implement a way to register constants and enums directly with the engine, but it has quite low priority at the moment since the above works.
Regards,
Andreas
ctx->Prepare(funcId);asCScriptString str("my string");ctx->SetArgObject(0, &str);ctx->Execute();
How are you exporting the constants, with RegisterGlobalProperty()? If the script compiler is to use a constant in a switch case the constant must have been declared in the script. Thus, my suggestion for exporting constants from the application to scripts is to construct a script section and add it to the module together with the real script.
const char *constants = "const int a = 1; const float pi = 3.14f;";engine->AddScriptSection("module", "constants", constants, strlen(constants), 0, false);engine->AddScriptSection("module", "the script", script, strlen(script), 0, false);engine->Build("module");
I will implement a way to register constants and enums directly with the engine, but it has quite low priority at the moment since the above works.
Regards,
Andreas
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
Popular Topics
Advertisement
Recommended Tutorials
Advertisement