Skip to content

Instantly share code, notes, and snippets.

@katlogic
Created August 11, 2016 17:39
Show Gist options
  • Save katlogic/c9e640ec34394064ae878518406c911f to your computer and use it in GitHub Desktop.
Save katlogic/c9e640ec34394064ae878518406c911f to your computer and use it in GitHub Desktop.
local mt
local sidetab = {}
mt = {
__index = function(self,k)
local l = rawget(mt,k)
if l then return l end
return sidetab[self] and sidetab[self][k] or nil
end,
__newindex = function(self,k,v)
local t = sidetab[self] or {}
t[k] = v
sidetab[self] = t
end
}
setmetatable(sidetab, {__mode="k"})
-- this can be c function as well
function mt:method()
print('hello')
end
-------
l=newproxy()
debug.setmetatable(l,mt)
l:method()
l.x = 1
l2=newproxy()
debug.setmetatable(l2,mt)
l2.x = 2
print(l.x)
print(l2.x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment