Created
August 11, 2016 17:39
-
-
Save katlogic/c9e640ec34394064ae878518406c911f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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