pub struct ScriptWriter { /* private fields */ }Expand description
Writes compiled scripts to script.dat and script.idx in the output directory.
Implementations§
Source§impl ScriptWriter
impl ScriptWriter
pub fn new(output_dir: String) -> Self
Sourcepub fn write_all(&self, scripts: &[CompiledScript]) -> Result<()>
pub fn write_all(&self, scripts: &[CompiledScript]) -> Result<()>
Write all compiled scripts to script.dat and script.idx.
File layout is sparse by script.id: the idx has one entry per
slot from 0..max_id; slots without a compiled script write length
0 and contribute no bytes to the dat. The loader (rs-engine)
mirrors this — empty-length slots become no-op Script stubs so
the script at array-index N matches compile-time id N.
Packing contiguously (old behaviour) misaligned runtime array
indices with compile-time ids, so bytecode GOSUB 2405 (intended
chatnpc_page) resolved to chatnpc at runtime — infinite
recursion.
Sourcepub fn write_encoded(&self, encoded: &[Vec<u8>]) -> Result<()>
pub fn write_encoded(&self, encoded: &[Vec<u8>]) -> Result<()>
Write script.dat + script.idx from pre-encoded per-slot byte blobs
(encoded[slot] is that script’s bytes; empty for unused slots). Lets the
streaming recompile path produce output without ever holding the full
Vec<CompiledScript> — it encodes each script as it re-compiles, places
the bytes by id, then calls this. Byte-identical to write_all.
Sourcepub fn build_encoded(&self, encoded: &[Vec<u8>]) -> (Vec<u8>, Vec<u8>)
pub fn build_encoded(&self, encoded: &[Vec<u8>]) -> (Vec<u8>, Vec<u8>)
Build script.dat + script.idx bytes in memory from pre-encoded per-slot
blobs — the in-memory counterpart of ScriptWriter::write_encoded, used
by the recompile pipeline’s in-memory entry point. Uses the identical
header + sparse-by-id layout, so it is byte-for-byte equal to build_all
for the same scripts.