Created
December 2, 2014 11:00
Revisions
-
akirayu101 created this gist
Dec 2, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,57 @@ require "src/modules/traceback.lua" hook_tb = {} local function hook_index(o, key) local function_name, filename, line = traceback.getsource(4) logger:fatal("access hook_tb in funtion[%s] filename[%s] line[%d]", function_name, filename, line) 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) local function_name, filename, line = traceback.getsource(4) logger:fatal("modify hook_tb in funtion[%s] filename[%s] line[%d]", function_name, filename, line) print("set", key, value) o["__data"][key] = value end function hook_tb:create() local tb = {} tb["__data"] = {} setmetatable(tb,{__index = hook_index,__newindex = hook_newindex }) return tb end function hook_tb:create_from_native_table(native_table) local tb = hook_tb:create() tb['__data'] = native_table return tb end function hook_test() 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]) end