JavaScript entry point to Cornerstone applications.
More...
#include <JS/Context.hpp>
|
const v8::Persistent
< v8::Context > & | context () const |
| |
|
void | eval (const QString &src) |
| | Evaluate given snippet of JavaScript-code. |
| |
| v8::Local< v8::Value > | evalValue (const QString &src) |
| | Evaluate given snippet of JavaScript-code. More... |
| |
| | JSContext (int &argc, char *argv[]) |
| | Creates a new JS context with node.js. More... |
| |
| bool | load (const QString &filename) |
| | Load and execute JavaScript-code from file. More... |
| |
| v8::Local< v8::Value > | loadValue (const QString &filename, bool *ok=nullptr) |
| | Load and execute JavaScript-code from file and returns the same object that the script returns. More... |
| |
| template<typename T > |
| Radiant::IntrusivePtr< T > | loadWidget (const QString &filename, bool *ok=nullptr) |
| | Load and execute JavaScript-code from file and returns the returned object as WidgetPtr. More... |
| |
| void | makeDefault () |
| | Makes this JS context the default context. More... |
| |
| void | update () |
| | Run one iteration of nodejs/libuv main loop, should be called periodically. More... |
| |
|
virtual | ~JSContext () |
| | Deinitializes node.js and v8 and deletes the context. |
| |
JavaScript entry point to Cornerstone applications.
MultiWidgets::Application creates and manages one instance of this by default, usually there is no need to use this class directly, except the eval and load -functions.
| Scripting::JSContext::JSContext |
( |
int & |
argc, |
|
|
char * |
argv[] |
|
) |
| |
Creates a new JS context with node.js.
- Parameters
-
| [in,out] | argc | length of argv, will be modified if argv is changed |
| [in,out] | argv | application command line arguments, v8-specific arguments are automatically removed |
| const v8::Persistent<v8::Context>& Scripting::JSContext::context |
( |
| ) |
const |
- Returns
- wrapped v8 context
| static JSContext* Scripting::JSContext::defaultContext |
( |
| ) |
|
|
static |
- Returns
- a pointer to default context, if there is any
| v8::Local<v8::Value> Scripting::JSContext::evalValue |
( |
const QString & |
src | ) |
|
Evaluate given snippet of JavaScript-code.
You can use ClassWrapper to convert the type to Cornerstone object
- Returns
- result of the evaluation as v8 value
| bool Scripting::JSContext::load |
( |
const QString & |
filename | ) |
|
Load and execute JavaScript-code from file.
- Returns
- false if there were some errors when loading or executing the file
| v8::Local<v8::Value> Scripting::JSContext::loadValue |
( |
const QString & |
filename, |
|
|
bool * |
ok = nullptr |
|
) |
| |
Load and execute JavaScript-code from file and returns the same object that the script returns.
- Parameters
-
| filename | file to load |
| [out] | ok | nullptr or pointer to bool that will be set to true if loading succeeds or false if there are any errors |
- Returns
- value that v8 returns
template<typename T >
| Radiant::IntrusivePtr< T > Scripting::JSContext::loadWidget |
( |
const QString & |
filename, |
|
|
bool * |
ok = nullptr |
|
) |
| |
Load and execute JavaScript-code from file and returns the returned object as WidgetPtr.
For example: auto w = context.loadWidget<MultiWidgets::Widget>("file.js");
- Parameters
-
| filename | file to load |
| [out] | ok | nullptr or pointer to bool that will be set to true if loading succeeds or false if there are any errors |
| void Scripting::JSContext::makeDefault |
( |
| ) |
|
| static QString Scripting::JSContext::parseError |
( |
const v8::TryCatch & |
trycatch | ) |
|
|
static |
Converts v8 exception error string to QString.
- Parameters
-
- Returns
- error as string
| static void Scripting::JSContext::setCurrentStackLimit |
( |
int |
bytes | ) |
|
|
static |
Sets v8 stack limit to given size, starting from current point at the C++ stack.
- Parameters
-
| void Scripting::JSContext::update |
( |
| ) |
|
Run one iteration of nodejs/libuv main loop, should be called periodically.
MultiWidgets::Application calls this automatically every frame