Created
December 18, 2012 07:17
-
-
Save prafulliu/4325773 to your computer and use it in GitHub Desktop.
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
t = {} | |
--keep a private access to the original table | |
local _t = t | |
--create proxy | |
t = {} | |
--create metatable | |
local mt = { | |
__index = function ( t, k ) | |
print("*access to element " .. tostring(k)) | |
return _t[k] --access the original table | |
end, | |
__newindex = function(t, k, v) | |
print("update of element " .. tostring(k) .. | |
" to " .. tostring(v)) | |
_t[k] = v --update original table | |
end | |
} | |
setmetatable(t, mt) | |
t[2] = "hello" | |
print(t[2]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment