diff options
Diffstat (limited to 'doc/src/snippets/code/src_script_qscriptcontext.cpp')
-rw-r--r-- | doc/src/snippets/code/src_script_qscriptcontext.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/doc/src/snippets/code/src_script_qscriptcontext.cpp b/doc/src/snippets/code/src_script_qscriptcontext.cpp new file mode 100644 index 0000000..a2f18158 --- /dev/null +++ b/doc/src/snippets/code/src_script_qscriptcontext.cpp @@ -0,0 +1,28 @@ +//! [0] +foo(20.5, "hello", new Object()) +//! [0] + + +//! [1] +QScriptValue Person_prototype_fullName(QScriptContext *context, QScriptEngine *engine) +{ + QScriptValue self = context->thisObject(); + QString result; + result += self.property("firstName").toString(); + result += QLatin1String(" "); + result += self.property("lastName").toString(); + return result; +} +//! [1] + + +//! [2] +QScriptValue myInclude(QScriptContext *ctx, QScriptEngine *eng) +{ + QString fileName = ctx->argument(0).toString(); + QString contents = readTheFile(fileName); + ctx->setActivationObject(ctx->parentContext()->activationObject()); + ctx->setThisObject(ctx->parentContext()->thisObject()); + return eng->evaluate(contents, fileName); +} +//! [2] |