local decorated = false local m = setmetatable({}, {__newindex = function(t, k, v) if'function' == type(v) and decorated then localfunctionwrapper(x) print(string.format('call %s', k)) returnstring.format("The 2nd power of %s is %s", x, v(x)) end decorated = false rawset(t, k, wrapper) else rawset(t, k, v) end end})
local decorators = {} local m = setmetatable({}, {__newindex = function(t, k, v) if'function' == type(v) then for i = #decorators, 1, -1do v = decorators[i](k, v) decorators[i] = nil end end rawset(t, k, v) end})
localfunctionAT(f) table.insert(decorators, f) end
localfunctiondecorator() AT(function(fname, f) returnfunction(x) print(string.format('call %s', fname)) returnstring.format("The 2nd power of %s is %s", x, f(x)) end end) end