Created
July 8, 2014 12:56
-
-
Save akirayu101/bd92ece93bb6654087f3 to your computer and use it in GitHub Desktop.
method missing
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
hook_tb = {} | |
local function hook_index(o, key) | |
print("get", key) | |
if type(o["data"][key]) ~= "table" then | |
return o["data"][key] | |
else | |
local tb = hook_tb:create() | |
tb["data"] = o["data"][key] | |
return tb | |
end | |
end | |
local function hook_newindex(o, key, value) | |
print("set", key, value) | |
o["data"][key] = value | |
end | |
function hook_tb:create() | |
print("create tb") | |
local tb = {} | |
tb["data"] = {} | |
setmetatable(tb,{__index = hook_index,__newindex = hook_newindex }) | |
return tb | |
end | |
t = hook_tb:create() | |
print(t.hello) | |
t.hello = 1 | |
t.hello = {1,2,3} | |
print(t.hello[1]) | |
local st = t.hello | |
print(st[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment