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 |
Manually set the instruction pointer. |
Method | object |
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 |
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 |
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 |
Undocumented |
Method | _push |
Undocumented |
Instance Variable | _bp |
Undocumented |
Instance Variable | _impl |
Undocumented |
Instance Variable | _ncs |
Undocumented |
Instance Variable | _ndb |
Undocumented |
Instance Variable | _object |
Undocumented |
Instance Variable | _ret |
Undocumented |
Instance Variable | _save |
Undocumented |
Instance Variable | _save |
Undocumented |
Instance Variable | _save |
Undocumented |
Instance Variable | _script |
Undocumented |
Instance Variable | _spec |
Undocumented |
Instance Variable | _stack |
Undocumented |
Instance Variable | _stop |
Undocumented |
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:Script | The script to run. |
spec:LanguageSpec | The language spec your script was compiled against. |
impl | The implementation of the script. |
Call a NWScript function.
This will only work if NDB information is present.
Parameters | |
fn | The function name. |
*args | The arguments to the function. |
Raises | |
ValueError | If the function is not found, or if the number of arguments does not match the function signature. |
Manually set the instruction pointer.
Currently used internally. Must set on a instruction boundary.
Set/change the object ID that the script is running on.
Changing this will affect the OBJECT_SELF constant in the script.
Return a proxy object that can directly invoke NWScript functions from the python side.
This will only work if NDB information is present.