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.
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.
Exports
All exports are global functions (called by the C++ binding system).
Functions
__luaBindIndex(t, k)
Metatable __index handler for C++-bound instance objects. Searches: metatable → getters → super chain.
- Parameters:
t- userdata - The bound objectk- string - Property/method name
__luaBindIndexStatic(t, k)
Metatable __index handler for C++-bound static classes. Similar to __luaBindIndex but calls getters without self.
__luaBindNewindex(t, k, v)
Metatable __newindex handler for C++-bound instance objects. Searches setters in current and super metatables.
- Parameters:
t- userdata - The bound objectk- string - Property namev- any - Value to set
__luaBindNewindexStatic(t, k, v)
Metatable __newindex handler for static classes (no self parameter).
__finalizeLuaBindings(classes, luaVMname)
Called after all C++ classes are registered. Optimizes metatables: flattens SimObject hierarchies, sets up field accessors, removes unnecessary indirection.
- Parameters:
classes- table - Map of class names to metatable tablesluaVMname- string - Lua VM type (e.g., "vlua", "game")
testBindings()
Unit test for the binding system using TestNamespace.TestClassA/B.
Internal Notes
- Metatable structure:
mt[1]= getters table,mt[2]= setters table,mt[3]= super metatable - Getter/setter functions are cached in the origin metatable after first lookup for O(1) subsequent access
- SimObject types (identified by
isSubClassOfand key starting with 'd') get special handling:- Flattened metatable (all super methods/getters merged)
- Custom
__index/__newindexthat falls through togetStaticDataFieldbyName/getDynDataFieldbyName - Fields
mt[4-7]store data field accessor functions
- Optimization pass: when a class has no super, no getters, or no setters, unnecessary metatable entries are removed
- Function names are hardcoded and must not be changed (referenced from C++)
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
luaCore Reference
Module defined in `lua/common/luaCore.lua`. Adds core language features and polyfills used throughout the codebase - optional require, module reload, table utilities, and FFI initialization.