Skip to content

Instantly share code, notes, and snippets.

@prafulliu
Created December 18, 2012 07:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prafulliu/4325773 to your computer and use it in GitHub Desktop.
Save prafulliu/4325773 to your computer and use it in GitHub Desktop.
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