I solved the first idea by implementing the C++ preparser, basically before I pass a QScript to QScriptEngine.evaluate() I do the following:
1) Begin reading from source script.
2) I look for any instances of 'include("somefile.js");
3) If an include exists I open the include file, and stream the contents into the current TextStream -- this is recursive, if it isn't an include I just stream it as normal
4) Once I've processed the entire script I'm able to do the following
//IncludedScript.js
function magicalFunction()
{
print ("Executed included function");
}
//IncludedScript.js
function magicalFunction()
{
print ("Executed included function");
}
To copy to clipboard, switch view to plain text mode
//Init.js
include("IncludedScript.js");
function init()
{
print ("Calling Included Script");
magicalFunction();
print ("End Call");
}
//Init.js
include("IncludedScript.js");
function init()
{
print ("Calling Included Script");
magicalFunction();
print ("End Call");
}
To copy to clipboard, switch view to plain text mode
//C++
preprocess("init.js");
engine.evaluate(processedResults);
engine.evaluate("init();");
////Output
Calling Included Script
Executed included function
End Call
//C++
preprocess("init.js");
engine.evaluate(processedResults);
engine.evaluate("init();");
////Output
Calling Included Script
Executed included function
End Call
To copy to clipboard, switch view to plain text mode
Bookmarks