Skip to main content

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

FileContent
01-LAYOUT.mdSMT / IMT, ByVal·ByObj dual instance metatables, type-table keys (LuaConsts.h)
02-INDEX.md__index / __newindex algorithm, three-table roles, miss semantics
03-BINDING.mdpublic visibility, Bind-time inheritance flattening, member classification
04-SPECIAL-TYPES.mdenum, Nullable, struct, array, delegate special cases

Boundaries with other specs

Core semantics (quick view)

  • Static and instance each have a three-table set (method / fieldGetter / fieldSetter), held by the indexer closure.
  • __index miss → nil; __newindex miss → 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_mt and __byobj_instance_mt; reference types are ByObj only.