API reference / @jsprismarine/script-host / shape/binding / ScriptApiContext
Class: ScriptApiContext
Defined in: script-host/src/shape/binding.ts:144
One pack's view of the Script API in an engine. It installs each module the pack resolves into a namespace object, with every class, enum, constant and error class of the served version, and dispatches every member to its registered implementation. A member with none throws NotImplementedError, and the context logs it the first time the pack uses it.
Constructors
Constructor
new ScriptApiContext(
engine,options):ScriptApiContext
Defined in: script-host/src/shape/binding.ts:167
Evaluates the binding's runtime in the engine and gives it this context's host function.
Parameters
engine
options
Returns
ScriptApiContext
Throws
When the engine cannot run the runtime.
Methods
bind()
bind(
shape):ScriptHandle
Defined in: script-host/src/shape/binding.ts:197
Installs a served version of a module, after the modules it depends on, and returns its namespace. The context owns the handle and frees it in destroy.
Parameters
shape
Returns
Throws
When the pack already has another version of the module.
create()
create(
module,className,tag?,state?):ScriptHandle
Defined in: script-host/src/shape/binding.ts:233
Makes an instance of a bound class without running its constructor, for an implementation to return. The caller frees the handle.
Parameters
module
string
className
string
tag?
number = 0
What the instance stands for, which every call of its members receives as ScriptCall.tag, such as an index into the host's own table.
state?
string = ''
What the instance holds, which every call of its members receives as ScriptCall.state, such as an entity's id. It lives as long as the instance does.
Returns
Throws
When the module or the class is not bound.
destroy()
destroy():
void
Defined in: script-host/src/shape/binding.ts:282
Frees the context's handles. The engine keeps what scripts still refer to.
Returns
void
identify()
identify(
value):HostInstance|undefined
Defined in: script-host/src/shape/binding.ts:246
The tag and the state the host gave an instance when it made it, such as the entity a Player passed to a member carries.
Parameters
value
Returns
HostInstance | undefined
Undefined for a value the host did not make, which a script made with Object.create or a constructor the host did not run.
makeError()
makeError(
error):ScriptHandle
Defined in: script-host/src/shape/binding.ts:267
Makes an instance of one of the API's error classes without throwing it, such as the error a promise rejects with. The caller frees the handle.
Parameters
error
Returns
Throws
When the engine cannot make it.
namespace()
namespace(
module):ScriptHandle|undefined
Defined in: script-host/src/shape/binding.ts:220
The namespace of a bound module.
Parameters
module
string
Returns
ScriptHandle | undefined
setState()
setState(
value,state):void
Defined in: script-host/src/shape/binding.ts:258
Replaces the state of an instance the host made, outside a call into one of its members, such as a drawn debug shape whose timeLeft the tick counts down. Leaves any other value alone.
Parameters
value
state
string
Returns
void