From 56fdbef85167afa48f7cd45e0ceedafc1643e1d7 Mon Sep 17 00:00:00 2001 From: Cloud Wu Date: Mon, 21 Apr 2014 19:48:29 +0800 Subject: [PATCH] remove snax global set limit --- lualib/snax_interface.lua | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lualib/snax_interface.lua b/lualib/snax_interface.lua index 2dbb06b2..03e6f5e5 100644 --- a/lualib/snax_interface.lua +++ b/lualib/snax_interface.lua @@ -31,7 +31,8 @@ return function (name , G, loader) assert(G.response == nil) end - local env = {} + local temp_global = {} + local env = setmetatable({} , { __index = temp_global }) local func = {} local system = { "init", "exit", "hotfix" } @@ -47,11 +48,15 @@ return function (name , G, loader) env.response = func_id(func, "response") local function init_system(t, name, f) - local index = assert(system[name] , string.format("Not support global var %s", name)) - if type(f) ~= "function" then - error (string.format("%s must be a function", name)) + local index = system[name] + if index then + if type(f) ~= "function" then + error (string.format("%s must be a function", name)) + end + func[index][4] = f + else + temp_global[name] = f end - func[index][4] = f end setmetatable(G, { __index = env , __newindex = init_system }) @@ -81,5 +86,9 @@ return function (name , G, loader) setmetatable(G, nil) + for k,v in pairs(temp_global) do + G[k] = v + end + return func end