Class ScriptSystem

Inheritance Relationships

Base Type

Class Documentation

class ScriptSystem : public csp::common::IJSScriptRunner

A JavaScript based scripting system that can be used to create advanced behaviours and interactions between entities in spaces.

Public Functions

void Initialise()

Starts up the JavaScript runtime context.

void Shutdown()

Shuts down and deletes the JavaScript runtime context.

virtual bool RunScript(int64_t ContextId, const csp::common::String &ScriptText) override

Attempts to execute a script in a given context.

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

  • ScriptText – : The script to execute.

Returns

a boolean representing success running the script.

bool RunScriptFile(int64_t ContextId, const csp::common::String &ScriptFilePath)

Attempts to execute a script from a given file path in the given context.

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

  • ScriptFilePath – : The file path of the script to execute.

Returns

a boolean representing success running the script.

virtual bool CreateContext(int64_t ContextId) override

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.

virtual bool DestroyContext(int64_t ContextId) override

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.

virtual bool BindContext(int64_t ContextId) override

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.

virtual bool ResetContext(int64_t ContextId) override

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.

bool ExistsInContext(int64_t ContextId, const csp::common::String &ObjectName)
virtual void *GetContext(int64_t ContextId) override

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.

virtual void *GetModule(int64_t ContextId, const csp::common::String &ModuleName) override

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.

  • ModuleName – String& : 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.

virtual void RegisterScriptBinding(csp::common::IScriptBinding *ScriptBinding) override

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.

virtual void UnregisterScriptBinding(csp::common::IScriptBinding *ScriptBinding) override

Unregister a binding object with the script runner.

Parameters

ScriptBinding – IScriptBinding : Object capable of binding a script.

Pre

ScriptBinding has been registered via RegisterScriptBinding

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

Set the javascript source code of a particular module.

Parameters
  • ModuleUrl – String : 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.

  • Source – String: The javascript source code to set.

Pre

ModuleURL must be unique.

void AddModuleUrlAlias(const csp::common::String &ModuleUrl, const csp::common::String &ModuleUrlAlias)
bool GetModuleUrlAlias(const csp::common::String &ModuleUrl, csp::common::String &OutModuleUrlAlias)
virtual void ClearModuleSource(csp::common::String ModuleUrl) override

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

Parameters

ModuleUrl – String : The URL of the module to clear.

Pre

ModuleURL must already exist via setting it with SetModuleSource.

csp::common::String GetModuleSource(csp::common::String ModuleUrl)
size_t GetNumImportedModules(int64_t ContextId) const
const char *GetImportedModule(int64_t ContextId, size_t Index) const