Go to file
rtlhq 8cbe567e82 changed debian/source/format to native 2022-11-15 12:40:29 +08:00
debian changed debian/source/format to native 2022-11-15 12:40:29 +08:00
docs Import Upstream version 5.92.0 2022-10-06 21:49:26 +08:00
examples Import Upstream version 5.92.0 2022-10-06 21:49:26 +08:00
po Import Upstream version 5.92.0 2022-10-06 21:49:26 +08:00
src Import Upstream version 5.92.0 2022-10-06 21:49:26 +08:00
.gitignore Import Upstream version 5.92.0 2022-10-06 21:49:26 +08:00
.gitlab-ci.yml Import Upstream version 5.92.0 2022-10-06 21:49:26 +08:00
.kde-ci.yml Import Upstream version 5.92.0 2022-10-06 21:49:26 +08:00
AUTHORS Import Upstream version 5.92.0 2022-10-06 21:49:26 +08:00
CMakeLists.txt Import Upstream version 5.92.0 2022-10-06 21:49:26 +08:00
COPYING.LIB Import Upstream version 5.92.0 2022-10-06 21:49:26 +08:00
KF5JsEmbedConfig.cmake.in Import Upstream version 5.92.0 2022-10-06 21:49:26 +08:00
README.md Import Upstream version 5.92.0 2022-10-06 21:49:26 +08:00
metainfo.yaml Import Upstream version 5.92.0 2022-10-06 21:49:26 +08:00

README.md

KJSEmbed

Binding Javascript object to QObjects

Introduction

KSJEmbed provides a method of binding JavaScript objects to QObjects, so you can script your applications.

Usage

If you are using CMake, you need to have

find_package(KF5JsEmbed NO_MODULE)

(or similar) in your CMakeLists.txt file, and you need to link to KF5::JsEmbed.

The KJSEmbed::Engine class provides the main interface for running embedded Javascript.

KJSEmbed::Engine *engine = new KJSEmbed::Engine();
KJS::Interpreter *interpreter = engine->interpreter();
interpreter->setShouldPrintExceptions(true);
KJS::ExecState *exec = interpreter->globalExec();
KJS::UString code("print(\"Hello World\")");
KJSEmbed::Engine::ExitStatus exitstatus = engine->execute(code);
KJS::Completion completion = engine->completion();
if (exitstatus != KJSEmbed::Engine::Success) {
    KJS::JSValue* value = completion.value();
    qDebug() << value->toString(exec).qstring();
}