]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/lua: use rawget/rawset to avoid metatable evaluation
authorMarek Vavruša <marek.vavrusa@nic.cz>
Thu, 23 Apr 2015 12:33:17 +0000 (14:33 +0200)
committerMarek Vavruša <marek.vavrusa@nic.cz>
Thu, 23 Apr 2015 12:33:17 +0000 (14:33 +0200)
daemon/lua/sandbox.lua

index 9217796f0129320649c78a6c92317c2aa0403c3d..0bad92a7045b489dd9a2a80e5d61ca6bf7a5bb88 100644 (file)
@@ -25,12 +25,13 @@ setmetatable(net, {
 -- `modules.<name> = <config>`
 setmetatable(modules, {
        __newindex = function (t,k,v)
-               modules.load(k)
-               if _G[k] then
-                       local config_call = _G[k]['config']
-                       if config_call and config_call[''] then
-                               config_call(v)
+               if not rawget(_G, k) then
+                       modules.load(k)
+                       local mod = rawget(_G, k)
+                       if mod and mod['config'] then
+                               mod['config'](v)
                        end
+
                end
        end
 })
@@ -42,12 +43,12 @@ function modules_register(module)
                __index = function (t, k)
                        local  v = rawget(t, k)
                        if     v     then return v
-                       elseif t.get then return t.get(k)
+                       elseif rawget(t, 'get') then return t.get(k)
                        end
                end,
                __newindex = function (t, k, v)
                        local  old_v = rawget(t, k)
-                       if not old_v and t.set then
+                       if not old_v and rawget(t, 'set') then
                                t.set(k..' '..v)
                        end
                end