class documentation
class Compiler: (source)
Constructor: Compiler(resolver, src_rt, bin_rt, dbg_rt, ...)
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 |
Undocumented |
Method | _load |
Undocumented |
Method | _write |
Undocumented |
Class Variable | _instance |
Undocumented |
Instance Variable | _bin |
Undocumented |
Instance Variable | _bin |
Undocumented |
Instance Variable | _cb |
Undocumented |
Instance Variable | _cb |
Undocumented |
Instance Variable | _comp |
Undocumented |
Instance Variable | _dbg |
Undocumented |
Instance Variable | _dbg |
Undocumented |
Instance Variable | _encoding |
Undocumented |
Instance Variable | _lib |
Undocumented |
Instance Variable | _ncs |
Undocumented |
Instance Variable | _ndb |
Undocumented |
Instance Variable | _resolver |
Undocumented |
Instance Variable | _src |
Undocumented |
Instance Variable | _src |
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[ | 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 | The resource type for the source file. |
bin | The resource type for the binary file. |
dbg | The resource type for the debug file. |
langspec | The language specification. |
debug | Whether 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 | The maximum include depth. |
encoding | The encoding to use for filenames (defaults to the configured nwn encoding). |
optimizations:set[ | A set of optimizations to apply. The default is to use whatever the linked library defaults to. |
Raises | |
FileNotFoundError | If the library cannot not be found, either bundled or in the system library path. |
OSError | If the library could not be loaded. |
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 | |
scriptstr | The 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[ | 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 | |
CompilationError | If the compilation fails. |
ValueError | If the script name is invalid. |