Class IJSScriptRunner

Inheritance Relationships

Derived Type

Class Documentation

class IJSScriptRunner

Subclassed by csp::systems::ScriptSystem

Public Functions

virtual ~IJSScriptRunner() = default

Virtual destructor.

inline virtual bool RunScript(int64_t ContextId, const String &ScriptText)

Attempts to execute a script in a given context.

Parameters
  • ContextId – int64_t : The Id of the CSP script context in which to run the script. If the provided context does not exist, the script run will fail.

  • ScriptTextString& : The text of the script to be executed by the javascript engine.

Returns

Whether the script was successfully run.

inline virtual void RegisterScriptBinding(IScriptBinding *ScriptBinding)

Register a binding object with the script runner.

The script runner should store this for use.

Parameters

ScriptBinding – IScriptBinding* : Object capable of binding a script. The binding is eventually used to call back into IJSScriptRunner.

inline virtual void UnregisterScriptBinding(IScriptBinding *ScriptBinding)

Unregister a binding object with the script runner.

Parameters

ScriptBindingIScriptBinding : Object capable of binding a script.

Pre

ScriptBinding has been registered via RegisterScriptBinding

inline virtual bool BindContext(int64_t ContextId)

Perform the script binding on any bindings registered via RegisterScriptBinding.

Parameters

ContextId – int64_t : The Id of the CSP script context in which to run the script. If the provided context does not exist, the script bind will fail.

Returns

Whether the context was successfully bound.

inline virtual bool ResetContext(int64_t ContextId)

Reset the script context.

This will likely shutdown and re-initialize any modules in the context.

Parameters

ContextId – int64_t : The Id of the CSP script context in which to run the script. If the provided context does not exist, the script reset will fail.

Returns

Whether the context was successfully reset.

inline virtual void *GetContext(int64_t ContextId)

Get the script context object.

Parameters

ContextId – int64_t : The Id of the CSP script context in which to run the script.

Returns

The script context object. This specific type of this is implementation defined. However, if using CSP’s ScriptSystem at time of writing, it will be a csp::systems::ScriptContext*, which you should cast to. Returns nullptr if the provided context does not exist.

inline virtual void *GetModule(int64_t ContextId, const String &ModuleName)

Get a script module object within a context.

Parameters
  • ContextId – int64_t : The Id of the CSP script context in which to run the script.

  • ModuleNameString& : Name of the module to return.

Returns

The script module. This specific type of this is implementation defined. However, if using CSP’s ScriptSystem at time of writing, it will be a csp::systems::ScriptModule*, which you should cast to. Returns nullptr if the specified module does not exist in the context.

inline virtual bool CreateContext(int64_t ContextId)

Create a new context with specified ID.

Parameters

ContextId – int64_t : The Id of the context to create, must be unique to other contexts.

Returns

Whether the context was created successfully.

inline virtual bool DestroyContext(int64_t ContextId)

Destroy a pre-existing context with specified ID.

Parameters

ContextId – int64_t : The Id of the context to destroy.

Returns

Whether the context was destroyed successfully.

inline virtual void SetModuleSource(csp::common::String ModuleUrl, csp::common::String Source)

Set the javascript source code of a particular module.

Parameters
  • ModuleUrlString : The URL of the module. This is an arbitrary accessor. It may be a good idea to use something like the scenegraph path of an entity when setting up a module on any particular entity.

  • SourceString: The javascript source code to set.

Pre

ModuleURL must be unique.

inline virtual void ClearModuleSource(csp::common::String ModuleUrl)

Clear the javascript source code of a particular module, leaving it empty.

Parameters

ModuleUrlString : The URL of the module to clear.

Pre

ModuleURL must already exist via setting it with SetModuleSource.

Protected Functions

IJSScriptRunner() = default