local skynet = require"skynet" require"skynet.manager" local db = {} local command = {}
-- 增加了这里 localfunctiontest(msg) print(msg) end -- 增加了这里 functioncommand.do_test(msg) test(msg) end
skynet.start(function() skynet.dispatch("lua", function(session, address, cmd, ...) local f = command[string.upper(cmd)] if f then skynet.ret(skynet.pack(f(...))) else error(string.format("Unknown command %s", tostring(cmd))) end end) -- 增加了这里 skynet.fork(function() whiletruedo skynet.sleep(100) command.do_test("itest!") end end) skynet.register "SIMPLEDB" end)
ifnot _P then print("hotfix fail, no _P define") return end
print("hotfix begin")
-- 用于获取函数变量 localfunctionget_up(f) local u = {} ifnot f then return u end local i = 1 whiletruedo local name, value = debug.getupvalue(f, i) if name == nilthen return u end u[name] = value i = i + 1 end return u end
-- 获取原来的函数地址,及函数变量 local command = _P.lua.command local upvs = get_up(command.do_test) local test = upvs.test
command.do_test = function(msg) test('New ' .. msg) end