I'm creating program with loadable scripts. User should be able to load several scripts from files. But there is a problem. Can I use different instances of QScriptEngine per script or maybe is better way for this?
I'm creating program with loadable scripts. User should be able to load several scripts from files. But there is a problem. Can I use different instances of QScriptEngine per script or maybe is better way for this?
Yes, you can. However it's probably better to only have one engine.
but how can I obtain clean environment for each script file? By QScriptEngine::pushContext() ? And what happens if I attach QScriptEngineDebugger to that one engine?
Last edited by lukass; 1st March 2012 at 11:27.
I don't understand what you mean.
For example you could set a new global object for the engine.And are there other ways? If so, how?
Let's make something clear -- one script engine only allows one script to be ran at the same time. If you want to run more (long running) scripts concurrently, you need separate engines however doing that in a single thread doesn't make much sense. Doing that in different threads requires you to synchronize access to all data shared between those scripts and also between your main program flow (aka "GUI thread").
For example I loaded three scripts by:
I can unload last script by engine.popContext() but how can I unload first script?Qt Code:
engine.evaluate(script1); engine.pushContext(); engine.evaluate(script2); engine.pushContext(); engine.evaluate(script3);To copy to clipboard, switch view to plain text mode
The code you pasted doesn't make sense. The following should be fine:
Qt Code:
engine.pushContext(); engine.evaluate(script1); engine.popContext(); engine.pushContext(); engine.evaluate(script2); engine.popContext(); engine.pushContext(); engine.evaluate(script3); engine.popContext();To copy to clipboard, switch view to plain text mode
You don't "unload" scripts. When a script has finished executing you don't have to do anything more with it.
Bookmarks