ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/XmlTools2/trunk/xmlpatch.cpp
(Generate patch)

Comparing XmlTools2/trunk/xmlpatch.cpp (file contents):
Revision 935 by s10k, Thu Feb 6 13:05:39 2014 UTC vs.
Revision 947 by s10k, Sat Feb 8 00:01:18 2014 UTC

# Line 211 | Line 211 | void XmlPatch::executeCommandOperation(c
211      UtilXmlTools::displaySuccessMessage(1,"@COMMAND");
212   }
213  
214 + QScriptValue echo(QScriptContext *context, QScriptEngine *engine)
215 + {
216 +    std::cout << context->argument(0).toString().toUtf8().constData() << std::endl;
217 +
218 +    return "";
219 + }
220 +
221   void XmlPatch::executeCustomCommandOperation(const QString &jsString, const QString &filesWildcard){
222  
223      QStringList filesToProcess;
# Line 228 | Line 235 | void XmlPatch::executeCustomCommandOpera
235      QFile rexmlfile(":/resources/libs/rexml.js");
236      QFile jsxmlfile(":/resources/libs/jsxml.js");
237  
238 +    // Add echo function so user can debug the code
239 +    QScriptValue echoFunction = engine.newFunction(echo);
240 +    engine.globalObject().setProperty("echo", echoFunction);
241 +
242      filesToProcess=UtilXmlTools::getAllXmlFilesByWildcard(filesWildcard);
243  
244      if(filesToProcess.isEmpty()){
# Line 262 | Line 273 | void XmlPatch::executeCustomCommandOpera
273  
274          engine.globalObject().setProperty("$xmlData",currXmlFileString);
275  
276 <        engineResult=engine.evaluate(jsString);
276 >        // main needs to be called so the user code is evaluated
277 >        engineResult=engine.evaluate("main(); function main() {"+jsString+"}"); // main funtion allows to use return to exit prematurely from user code
278  
279   #ifdef _USE_OLD_JS_ENGINE
280          if (engine.hasUncaughtException()) {

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)