Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Extra libraries, Code snippets, applications etc. » U++ Esc Interpreter, Esc Macros and templates » How to add global var to Esc from cpp-files?
How to add global var to Esc from cpp-files? [message #25526] Sat, 27 February 2010 20:30 Go to next message
Sc0rch is currently offline  Sc0rch
Messages: 99
Registered: February 2008
Location: Russia, Rubtsovsk
Member

Hello all.
How to add global var to Esc from cpp-files? Is there opportunity/functions to do this?

Thank you!
Anton.
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 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1757
Registered: August 2008
Location: Czech Republic
Senior Contributor

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 Go to previous message
Sc0rch is currently offline  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.
Previous Topic: Problem with script translation
Next Topic: Creating classes for Esc and using in Esc.
Goto Forum:
  


Current Time: Thu Apr 18 12:31:45 CEST 2019

Total time taken to generate the page: 0.00778 seconds