Changeset 947


Ignore:
Timestamp:
Feb 8, 2014, 1:01:18 AM (11 years ago)
Author:
s10k
Message:

XmlTools
Custom_code fix, allows the user exit a procedure prematurely using "return"

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XmlTools2/trunk/xmlpatch.cpp

    r935 r947  
    210210
    211211    UtilXmlTools::displaySuccessMessage(1,"@COMMAND");
     212}
     213
     214QScriptValue echo(QScriptContext *context, QScriptEngine *engine)
     215{
     216    std::cout << context->argument(0).toString().toUtf8().constData() << std::endl;
     217
     218    return "";
    212219}
    213220
     
    229236    QFile jsxmlfile(":/resources/libs/jsxml.js");
    230237
     238    // Add echo function so user can debug the code
     239    QScriptValue echoFunction = engine.newFunction(echo);
     240    engine.globalObject().setProperty("echo", echoFunction);
     241
    231242    filesToProcess=UtilXmlTools::getAllXmlFilesByWildcard(filesWildcard);
    232243
     
    263274        engine.globalObject().setProperty("$xmlData",currXmlFileString);
    264275
    265         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
    266278
    267279#ifdef _USE_OLD_JS_ENGINE
Note: See TracChangeset for help on using the changeset viewer.