class documentation

VM Script Executor for running NWScript bytecode.

Supports the following type mappings:

  • int <> int (32 bit on the nwscript side)
  • float <> float (32 bit on the nwscript side)
  • str <> string: in the current encoding (get_nwn_encoding())
  • Object <> object
  • Vector <> vector
  • Location <> location
  • custom structs <> dict: unset keys will push the type default value; extra keys are ignored.
  • Engine structure support is very preliminary and incomplete
Method __init__ Create a new VM.
Method call Call a NWScript function.
Method ip.setter Manually set the instruction pointer.
Method object_self.setter Set/change the object ID that the script is running on.
Method proxy Return a proxy object that can directly invoke NWScript functions from the python side.
Method run Start running code.
Method sp.setter Set the current stack pointer. Currently used internally.
Instance Variable ip Return the current instruction pointer (offset into bytecode).
Property impl Return the implementation object that this VM was created with.
Property object_self Return the object ID that the script is running on. Defaults to INVALID.
Property sp Get the current stack pointer.
Property spec Return the language spec that this VM was created with.
Method _exec Execute a single instruction.
Method _pop_ndb_type Undocumented
Method _push_ndb_type Undocumented
Instance Variable _bp Undocumented
Instance Variable _impl Undocumented
Instance Variable _ncs Undocumented
Instance Variable _ndb Undocumented
Instance Variable _object_self Undocumented
Instance Variable _ret Undocumented
Instance Variable _save_bp Undocumented
Instance Variable _save_ip Undocumented
Instance Variable _save_sp Undocumented
Instance Variable _script Undocumented
Instance Variable _spec Undocumented
Instance Variable _stack Undocumented
Instance Variable _stop_before_main Undocumented
def __init__(self, script: Script, spec: LanguageSpec, impl): (source)

Create a new VM.

You need one VM per script. You can reuse spec and impl between them.

The implementation must be a class that has the methods that correspond to the VM command names. The methods must accept the same number of arguments as the VM command expects, mapped to the corresponding python types.

After creating the VM, you can call the run method to execute the script, or use call() or proxy() to call NWScript functions directly.

Parameters
script:ScriptThe script to run.
spec:LanguageSpecThe language spec your script was compiled against.
implThe implementation of the script.
def call(self, fn, *args): (source)

Call a NWScript function.

This will only work if NDB information is present.

Parameters
fnThe function name.
*argsThe arguments to the function.
Raises
ValueErrorIf the function is not found, or if the number of arguments does not match the function signature.
@ip.setter
def ip(self, v): (source)

Manually set the instruction pointer.

Currently used internally. Must set on a instruction boundary.

@object_self.setter
def object_self(self, v): (source)

Set/change the object ID that the script is running on.

Changing this will affect the OBJECT_SELF constant in the script.

def proxy(self): (source)

Return a proxy object that can directly invoke NWScript functions from the python side.

This will only work if NDB information is present.

def run(self, from_start=True): (source)

Start running code.

Parameters
from_startIf True, start from the beginning of the script.
@sp.setter
def sp(self, v): (source)

Set the current stack pointer. Currently used internally.

@property
ip = (source)

Return the current instruction pointer (offset into bytecode).

@property
impl = (source)

Return the implementation object that this VM was created with.

@property
object_self = (source)

Return the object ID that the script is running on. Defaults to INVALID.

@property
sp = (source)

Get the current stack pointer.

@property
spec = (source)

Return the language spec that this VM was created with.

def _exec(self, i): (source)

Execute a single instruction.

def _pop_ndb_type(self, ty, idx=-1): (source)

Undocumented

def _push_ndb_type(self, ty, value=None): (source)

Undocumented

_bp: int = (source)

Undocumented

Undocumented

Undocumented

Undocumented

_object_self = (source)

Undocumented

_ret: list = (source)

Undocumented

_save_bp: int = (source)

Undocumented

_save_ip: int = (source)

Undocumented

_save_sp: int = (source)

Undocumented

Undocumented

Undocumented

Undocumented

_stop_before_main: bool = (source)

Undocumented