lpack Reference
Module defined in `lua/common/lpack.lua`. Fast Lua de/serializer supporting three formats: packed text, binary (using `string.buffer`), and Lua source. Handles tables, numbers, strings, booleans, vec3
Module defined in lua/common/lpack.lua. Fast Lua de/serializer supporting three formats: packed text, binary (using string.buffer), and Lua source. Handles tables, numbers, strings, booleans, vec3, and quat.
Exports
Functions
M.encode(v)
Encodes a Lua value into a compact packed text format.
- Parameters:
v- any - Value to encode (table, number, string, boolean, vec3, quat)
- Returns: string - Packed encoding (starts with 'a')
M.decode(is)
Decodes a packed or binary-encoded string back to a Lua value. Auto-detects format.
- Parameters:
- Returns:
table- Parsed result - Returns: any - Decoded Lua value
M.encodeBin(v)
Encodes a Lua value into binary format using string.buffer.
- Parameters:
v- any - Value to encode
- Returns: string - Binary encoding (starts with 'b')
M.encodeBinWorkBuffer(v)
Like encodeBin but returns the work buffer directly (avoids a string copy).
- Parameters:
v- any - Value to encode
- Returns: buffer - String buffer object
M.encodeLua(v)
Encodes a Lua value as valid Lua source code that can be loadstring'd.
- Parameters:
v- any - Value to encode
- Returns: string - Lua source string
M.decodeLua(s)
Decodes a Lua source string by executing it.
- Parameters:
s- string|nil - Lua source (fromencodeLua)
- Returns: any - Decoded value
M.encodeDoubleArray(tbl)
Encodes a Lua number array as raw binary double array via FFI.
- Parameters:
tbl- table - Array of numbers
- Returns: string - Raw binary data (8 bytes per number)
M.decodeDoubleArray(sda, tbl)
Decodes a raw binary double array back to a Lua table.
- Parameters:
sda- string - Binary data fromencodeDoubleArraytbl- table|nil - Optional table to populate
- Returns: table - Array of numbers
Internal Notes
- Three encoding formats: packed text ('a' prefix), binary ('b' prefix), and Lua source
decode()auto-detects format by checking the first byte- Packed format uses dispatch tables keyed by character codes for fast encoding/decoding
- Binary format leverages LuaJIT
string.bufferencode/decode for native type serialization - Temporarily stops GC during decode for performance
- Type markers in packed format:
-(positive number),=(negative number),[(array),{(dict),|(true),~(false),^(vec3),&(quat),A-J(strings by length digits)
kdtreepoint3d Reference
Module defined in `lua/common/kdtreepoint3d.lua`. K-d tree implementation for 3D points with range queries AND nearest-neighbor (closest point) queries.
luaBinding Reference
Module defined in `lua/common/luaBinding.lua`. Core C++/Lua binding infrastructure implementing property getters/setters, inheritance chains, and SimObject field access for engine-bound classes.