Skip to content

Instantly share code, notes, and snippets.

@toriaezunama
Created December 24, 2013 00:56
Show Gist options
  • Save toriaezunama/8107250 to your computer and use it in GitHub Desktop.
Save toriaezunama/8107250 to your computer and use it in GitHub Desktop.
Lua metatable masking
local t = {}
local mt = { x = 5 }
setmetatable( t, { __index = mt } )
-- No t.x so metatable referenced
print( 1, t.x ) --> 5
-- Add t.x (masking mt.x)
t.x = 4
print( 2, t.x ) --> 4
print( 3, mt.x ) --> 5
t.x = nil
-- Remove t.x (un-masking mt.x)
print( 4, t.x ) --> 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment