class ScriptObjectWrapper

Extends IScriptObjectWrapper by keeping a strong reference to the script object, and releasing it as needed.

As well as providing an interface for script reload functionality. See IScriptObjectWrapper.

Public

Constructors

ScriptObjectWrapper

ScriptObjectWrapper(IScriptExportable *nativeObject)

Methods

~ScriptObjectWrapper

virtual ~ScriptObjectWrapper() noexcept

GetScriptObject

MonoObject *GetScriptObject() const

BindToScriptObject

virtual void BindToScriptObject(MonoObject *scriptObject) = 0

Stores a pointer to the wrapper in the script object.

This ensures that calls to GetScriptObjectWrapper() can return the script object wrapper associated with the script object.

GetNativeObjectReferenceCount

virtual u32 GetNativeObjectReferenceCount() const

Returns the number of strong references on the underlying native object.

RegisterEvents

virtual void RegisterEvents()

Used by derived classes to connect callbacks to native object events.

UnregisterEvents

virtual void UnregisterEvents()

Used by derived classes to disconnect callbacks to native object events.

NotifyScriptObjectDestroyed

void NotifyScriptObjectDestroyed(bool isDestroyedDueToScriptReload) override

Notifies the wrapper that the script object is about to be destroyed.

NotifyNativeObjectDestroyed

void NotifyNativeObjectDestroyed() override

Notifies the wrapper that the native object it is managing is about to be destroyed.

ReleaseScriptObjectHandle

void ReleaseScriptObjectHandle()

Releases the currently held script object strong handle, if any.

GetLifetimeTrackingMode

virtual ScriptObjectLifetimeTrackingMode GetLifetimeTrackingMode() const

Determines how is script object lifetime tracked, and when should the native object be destroyed.

TransitionToWeakScriptObjectHandle

virtual void TransitionToWeakScriptObjectHandle()

Changes the internal script object handle from strong to weak.

If the handle is already weak does nothing. Only relevant if lifetime tracking mode is using garbage collection.

TransitionToStrongScriptObjectHandle

virtual void TransitionToStrongScriptObjectHandle()

Changes the internal script object handle from weak to strong.

If the handle is already strong does nothing. Only relevant if lifetime tracking mode is using garbage collection.

HasStrongScriptObjectHandle

bool HasStrongScriptObjectHandle() const

Returns true if the currently held script object handle is strong (preventing the script GC from releasing the object).

ShouldPersistScriptReload

virtual bool ShouldPersistScriptReload() const

If true, the object will be given an opportunity to back up its data before a script reload operation, and its script object will be automatically recreated once script reload ends, and given an opportunity to restore the backed up data.

If false, the script object and its wrapper will be destroyed on script reload.

NotifyScriptWillReload

virtual void NotifyScriptWillReload()

Called on all script object wrappers before script object reload happens.

BackupDataBeforeScriptReload

virtual TOptional<ScriptObjectReloadPersistentData> BackupDataBeforeScriptReload()

Called on all script object wrappers when script reload is about to happen.

Allows the script object to back up its current state so it may be restored after reload completes. Only relevant for script objects that persist script reload (i.e. ShouldPersistScriptReload() returns true).

RecreateScriptObjectAfterScriptReload

virtual void RecreateScriptObjectAfterScriptReload()

Called on all script object wrappers after script assemblies have been reloaded.

This needs to recreate the internal script object using the new assemblies, as the old one will have been destroyed during the reload. Only relevant for script objects that persist script reload (i.e. ShouldPersistScriptReload() returns true).

RestoreDataAfterScriptReload

virtual void RestoreDataAfterScriptReload(const ScriptObjectReloadPersistentData &data)

Called on all script object wrappers after script objects have been created in RecreateScriptObjectAfterScriptReload().

Allows you to restore data backed up in BackupDataBeforeScriptReload() call to the newly created script object. Only relevant for script objects that persist script reload (i.e. ShouldPersistScriptReload() returns true).

NotifyScriptReloadFinished

virtual void NotifyScriptReloadFinished()

Called on all script object wrappers as the final step in script reload, after RestoreDataAfterScriptReload().

Allows you to perform actions that require the entire scripting world to be fully recreated.

Protected

Methods

CreateScriptObjectHandle

void CreateScriptObjectHandle(MonoObject *scriptObject)

Creates a new handle to the provided script object.

Previous handle must be released.

Fields

mScriptObjectHandle

u32 mScriptObjectHandle

mHoldsStrongScriptObjectHandle

bool mHoldsStrongScriptObjectHandle