Metatable Spec (spec/metatable/)
This directory defines the Lua-visible layout of ZLua type tables, static metatables (SMT), and instance metatables (IMT), plus __index / __newindex member-dispatch semantics. Content is normative: Mono and Il2Cpp runtimes must behave the same; concrete implementations (Mono three-table Lua indexer, Il2Cpp native Dispatch*, etc.) live under impl/metatable/.
Document index
| File | Content |
|---|---|
| 01-LAYOUT.md | SMT / IMT, ByVal·ByObj dual instance metatables, type-table keys (LuaConsts.h) |
| 02-INDEX.md | __index / __newindex algorithm, three-table roles, miss semantics |
| 03-BINDING.md | public visibility, Bind-time inheritance flattening, member classification |
| 04-SPECIAL-TYPES.md | enum, Nullable, struct, array, delegate special cases |
Boundaries with other specs
- Type naming,
CSharppaths, generic/array type entry points → ../02-TYPE-SYSTEM.md - C# ↔ Lua value shapes and Push/Pop → ../marshal/
- Method overload dispatch,
register_method→ ../04-METHOD-OVERLOAD.md - Event: no dedicated metatable subtable; scripts use ordinary methods
add_EventName/remove_EventName(see 03-BINDING.md)
Core semantics (quick view)
- Static and instance each have a three-table set (method / fieldGetter / fieldSetter), held by the indexer closure.
__indexmiss →nil;__newindexmiss → error`; no C# reflection fallback.- Inheritance is flattened into the three tables at EnsureBinding; runtime does not walk the chain.
- structs provide both
__byval_instance_mtand__byobj_instance_mt; reference types are ByObj only.