|
Ultralight C++ API 2.0.0
|
#include <Ultralight/js/Holder.h>
Non-owning holder for bound-class singletons and program-lifetime objects.
An Eternal wraps a pointer to a native object that lives for the entire run of the application and is never destroyed, such as an engine subsystem or a global singleton. It lets page scripts interact with the native instance through a standard JavaScript wrapper without reference counting or ownership transfers.
You'll typically specialize js::ClassHolder with Eternal beside the class declaration so every file that binds or converts the class includes it. This makes Eternal the class's canonical holder, allowing you to assign the singleton directly to an API path.
This example exposes a game's world singleton to the page as app.world:
Both a T* and an Eternal leave ownership with you, but they differ in how they can cross the bridge:
Public Member Functions | |
| constexpr | Eternal ()=default |
| Create an empty Eternal. | |
| constexpr | Eternal (T *instance) |
| Create an Eternal for an instance. | |
| T * | get () const |
| Get the instance (NULL when empty). | |
| operator bool () const | |
| Whether or not this holds an instance. | |
|
constexprdefault |
Create an empty Eternal.
|
inlineexplicitconstexpr |
Create an Eternal for an instance.
| instance | The instance, which must never be destroyed. |
|
inline |
Get the instance (NULL when empty).
|
inlineexplicit |
Whether or not this holds an instance.