Created
December 24, 2013 00:56
-
-
Save toriaezunama/8107250 to your computer and use it in GitHub Desktop.
Lua metatable masking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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