Makes conversion between JS and C++ objects This only works with C++ classes that are already wrapped to JS code Example: ClassWrapper rectWrapper(context, "Nimble.Rectf"); Nimble::Rectf * rect = new Nimble::Rectf(); v8::Local<v8::Value> wrappedRect = widgetWrapper.wrap(rect); or in another direction: Nimble::Rectf * rect = wrappedRect.unwrap<Nimble::Rectf>(wrappedRect); if (rect) { ...
More...
#include <JS/Context.hpp>
|
| template<typename T > |
| static T * | unwrap (v8::Local< v8::Value > value) |
| | Unwraps C++ object from JS object. More... |
| |
Makes conversion between JS and C++ objects This only works with C++ classes that are already wrapped to JS code Example: ClassWrapper rectWrapper(context, "Nimble.Rectf"); Nimble::Rectf * rect = new Nimble::Rectf(); v8::Local<v8::Value> wrappedRect = widgetWrapper.wrap(rect); or in another direction: Nimble::Rectf * rect = wrappedRect.unwrap<Nimble::Rectf>(wrappedRect); if (rect) { ...
}
Template parameter must always be the base class. For example MultiWidgets::Widgets can be converted through Serializable: v8::Local<v8::Value> wrappedWidget = ...; auto tmp = ClassWrapper::unwrap<Valuable::Serializable>(wrappedWidget); MultiWidgets::WidgetPtr w(dynamic_cast<MultiWidgets::Widget*>(tmp));
| Scripting::ClassWrapper::ClassWrapper |
( |
const QString & |
name | ) |
|
Creates a new wrapper object using the default JS context.
- Parameters
-
| name | Javascript name for the wrapped object, for example "MultiWidgets.ImageWidget" |
Creates a new wrapper object.
- Parameters
-
| context | JS context that contains the object with given name |
| name | Javascript name for the wrapped object, for example "MultiWidgets.ImageWidget" |
template<typename T >
| static T* Scripting::ClassWrapper::unwrap |
( |
v8::Local< v8::Value > |
value | ) |
|
|
inlinestatic |
Unwraps C++ object from JS object.
- Template Parameters
-
| T | C++ type, always use the base class for inherited types, and then use dynamic_cast with the result |
- Parameters
-
- Returns
- wrapped C++ object or null if conversion fails, or if the wrapped object is null
template<typename T >
| v8::Local<v8::Value> Scripting::ClassWrapper::wrap |
( |
T * |
t | ) |
|
|
inline |
Wraps C++ pointer to v8 object.
- Parameters
-