From 87a02ffe72be68ded1addf879f1cc4199a64a7bc Mon Sep 17 00:00:00 2001 From: Cloud Wu Date: Thu, 7 Aug 2014 18:06:08 +0800 Subject: [PATCH] don't check imported function in snax.hotfix --- HISTORY.md | 1 + lualib/snax/hotfix.lua | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 23303874..63dcced0 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -4,6 +4,7 @@ Dev version * bugfix: service exit before init would not report back * add skynet.response and check multicall skynet.ret * skynet.newservice throw error when lanuch faild +* Don't check imported function in snax.hotfix v0.5.0 (2014-7-28) ----------- diff --git a/lualib/snax/hotfix.lua b/lualib/snax/hotfix.lua index e0cc2a7f..1a60383a 100644 --- a/lualib/snax/hotfix.lua +++ b/lualib/snax/hotfix.lua @@ -3,7 +3,21 @@ local io = io local hotfix = {} -local function collect_uv(f , uv) +local function envid(f) + local i = 1 + while true do + local name, value = debug.getupvalue(f, i) + if name == nil then + return + end + if name == "_ENV" then + return debug.upvalueid(f, i) + end + i = i + 1 + end +end + +local function collect_uv(f , uv, env) local i = 1 while true do local name, value = debug.getupvalue(f, i) @@ -18,7 +32,9 @@ local function collect_uv(f , uv) uv[name] = { func = f, index = i, id = id } if type(value) == "function" then - collect_uv(value, uv) + if envid(value) == env then + collect_uv(value, uv, env) + end end end @@ -30,7 +46,7 @@ local function collect_all_uv(funcs) local global = {} for _, v in pairs(funcs) do if v[4] then - collect_uv(v[4], global) + collect_uv(v[4], global, envid(v[4])) end end