Sign in to follow this  
Jedive

consts in switch and string parameter for entry function

Recommended Posts

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?

Share this post


Link to post
Share on other sites
You'll use the method SetArgObject() to pass the string to the script function.


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

Share this post


Link to post
Share on other sites
If you happen to use the preprocessor available on the addon page, you can #define constants. They don't need to be in the script file - theres a feature aimed specifically at this sort of thing.

Preprocessor::define("SOME_CONSTANT SOME_VALUE");

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this