Home » Extra libraries, Code snippets, applications etc. » U++ Esc Interpreter, Esc Macros and templates » How to add global var to Esc from cpp-files?
|
Re: How to add global var to Esc from cpp-files? [message #25527 is a reply to message #25526] |
Sat, 27 February 2010 23:09 |
|
Sc0rch wrote on Sat, 27 February 2010 20:30 | Hello all.
How to add global var to Esc from cpp-files? Is there opportunity/functions to do this?
Thank you!
Anton.
|
Hi Anton,
I'm not sure if it is possible directly. I tried some time ago and did not succeed. But I can show you a workaround that I used. The trick was a function to set the variable before anything else executes.
ArrayMap<String, EscValue> global;
Vector<EscValue> args;
Scan(global,"SetX(){:X=yourvalue;}");
p=global.Find("SetX");
if(p>=0) Execute(global, NULL, global[p],args);
//the rest of your code
Regards,
Honza
PS: I haven't tested the code, just extracted it from my older project... Hope it works.
|
|
|
Re: How to add global var to Esc from cpp-files? [message #25530 is a reply to message #25527] |
Sun, 28 February 2010 00:04 |
Sc0rch
Messages: 99 Registered: February 2008 Location: Russia, Rubtsovsk
|
Member |
|
|
dolik.rce wrote on Sun, 28 February 2010 04:09 |
PS: I haven't tested the code, just extracted it from my older project... Hope it works.
|
Hello, Honza!
It works. I've created a function for it:
bool SetGlobalVar(ArrayMap<String, EscValue>& global, const String& var,
const String& param, const String& value)
{
Vector<EscValue> args;
try {
Scan(global, "SetGlobalVar(){:" + var + (param.IsEmpty() ? "" : "[\"") + param
+ (param.IsEmpty() ? "" : "\"]") + "=" + value + ";}");
Execute(global, NULL, global.Get("SetGlobalVar"), args);
global.Remove(global.Find("SetGlobalVar"));
}
catch(CParser::Error e)
{
LOG("ERROR: " + e);
return false;
}
return true;
}
Thanks for support!
Anton.
|
|
|
Goto Forum:
Current Time: Fri Apr 26 21:21:28 CEST 2024
Total time taken to generate the page: 0.01619 seconds
|