class documentation

A class to compile NWScript using the NWScript compiler.

Method __del__ Undocumented
Method __init__ Create a new compiler instance.
Method compile Compile the given script filename.
Class Method _load_library Undocumented
Method _load_file Undocumented
Method _write_file Undocumented
Class Variable _instance Undocumented
Instance Variable _bin_ext Undocumented
Instance Variable _bin_rt Undocumented
Instance Variable _cb_load Undocumented
Instance Variable _cb_write Undocumented
Instance Variable _comp Undocumented
Instance Variable _dbg_ext Undocumented
Instance Variable _dbg_rt Undocumented
Instance Variable _encoding Undocumented
Instance Variable _lib Undocumented
Instance Variable _ncs Undocumented
Instance Variable _ndb Undocumented
Instance Variable _resolver Undocumented
Instance Variable _src_ext Undocumented
Instance Variable _src_rt Undocumented
def __del__(self): (source)

Undocumented

def __init__(self, resolver: Callable[[str], str | bytes | None], src_rt=2009, bin_rt=2010, dbg_rt=2064, langspec=b'nwscript', debug_info=True, max_include_depth=16, encoding=None, optimizations: set[Optimization] | int | None = None): (source)

Create a new compiler instance.

This will load the compiler library, and immediately request the langspec file (e.g. nwscript.nss).

Re-use the compiler instance for increased performance.

Parameters
resolver:Callable[[str], str | bytes | None]A callable that resolves the filename to a str, or None. The filename will always have the source restype extension appended. (e.g. "myscript.nss", not "myscript").
src_rtThe resource type for the source file.
bin_rtThe resource type for the binary file.
dbg_rtThe resource type for the debug file.
langspecThe language specification.
debug_infoWhether to write debug information. Generating NDB is usually cheap and useful for debugging, so the recommendation is to generate and store this info alongside the NCS file.
max_include_depthThe maximum include depth.
encodingThe encoding to use for filenames (defaults to the configured nwn encoding).
optimizations:set[Optimization] | int | NoneA set of optimizations to apply. The default is to use whatever the linked library defaults to.
Raises
FileNotFoundErrorIf the library cannot not be found, either bundled or in the system library path.
OSErrorIf the library could not be loaded.
def compile(self, script_name: str) -> tuple[bytes, str]: (source)

Compile the given script filename.

This will invoke multiple callbacks to load the script and any includes. The script will be compiled to bytecode and debug information.

Parameters
script_name:strThe script to compile. It will be requested from the resolver. The source restype extension is optionally stripped; other extensions will raise a ValueError.
Returns
tuple[bytes, str]A tuple of (bytecode, debug data). The bytecode is a bytes object, and the debug data is a string; or None if no debug data was requested.
Raises
CompilationErrorIf the compilation fails.
ValueErrorIf the script name is invalid.
@classmethod
def _load_library(cls) -> ct.CDLL: (source)

Undocumented

def _load_file(self, script_name: bytes, res_type: int): (source)

Undocumented

def _write_file(self, _fn, res_type: int, data: bytes, size: int, is_binary: bool): (source)

Undocumented

_instance: ct.CDLL | None = (source)

Undocumented

_bin_ext = (source)

Undocumented

Undocumented

_cb_load = (source)

Undocumented

_cb_write = (source)

Undocumented

Undocumented

_dbg_ext = (source)

Undocumented

Undocumented

_encoding = (source)

Undocumented

Undocumented

Undocumented

Undocumented

_resolver = (source)

Undocumented

_src_ext = (source)

Undocumented

Undocumented