Commit 1ae4698a authored by Jan Möbius's avatar Jan Möbius

Added printToFile scripting function

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@12442 383ad7c9-94d9-4d36-a494-682f7c89f535
parent d1e87a38
......@@ -429,7 +429,9 @@ Core::init() {
printFunction.setProperty("textedit",scriptEngine_.newQObject(this));
scriptEngine_.globalObject().setProperty("print", printFunction);
// Register print to file function :
QScriptValue printToFileFunc = scriptEngine_.newFunction(printToFileFunction);
scriptEngine_.globalObject().setProperty("printToFile", printToFileFunc);
// Register IdList Type to scripting Engine
qScriptRegisterSequenceMetaType< IdList >(&scriptEngine_);
......
......@@ -1395,6 +1395,9 @@ private slots:
/// Special print function for core logger
QScriptValue myPrintFunction(QScriptContext *context, QScriptEngine *engine);
/// Special print function for sending output to a file
QScriptValue printToFileFunction(QScriptContext *context, QScriptEngine *engine);
//=============================================================================
#endif // MVIEWWIDGET_HH defined
//=============================================================================
......
......@@ -326,3 +326,29 @@ QScriptValue myPrintFunction(QScriptContext *context, QScriptEngine *engine)
return engine->undefinedValue();
}
QScriptValue printToFileFunction(QScriptContext *context, QScriptEngine *engine)
{
if ( context->argumentCount() < 2 ) {
context->throwError( QScriptContext::SyntaxError, "Error! printToFileFunction needs at least two arguments, filename and what should be printed" );
return engine->undefinedValue();
}
QString result;
for (int i = 1; i < context->argumentCount(); ++i) {
if (i > 1)
result.append(" ");
result.append(context->argument(i).toString());
}
QFile file(context->argument(0).toString());
file.open(QIODevice::Append);
QTextStream stream(&file);
stream << result << "\n";
file.close();
return engine->undefinedValue();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment