From 3e9e582572bbb893aba4240708b7fabd3a2accaa Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Fri, 5 Sep 2008 18:34:46 +0000 Subject: [PATCH] Heavy memory/performance optimizations #1 --- libs/cbi/luasrc/cbi.lua | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/libs/cbi/luasrc/cbi.lua b/libs/cbi/luasrc/cbi.lua index 3a6c6d7aa..ac8d8b5b3 100644 --- a/libs/cbi/luasrc/cbi.lua +++ b/libs/cbi/luasrc/cbi.lua @@ -47,7 +47,7 @@ REMOVE_PREFIX = "cbi.rts." -- Loads a CBI map from given file, creating an environment and returns it function load(cbimap, ...) require("luci.fs") - require("luci.i18n") + local i18n = require "luci.i18n" require("luci.config") require("luci.util") @@ -57,11 +57,16 @@ function load(cbimap, ...) luci.i18n.loadc("cbi") - luci.util.resfenv(func) - luci.util.updfenv(func, luci.cbi) - luci.util.extfenv(func, "translate", luci.i18n.translate) - luci.util.extfenv(func, "translatef", luci.i18n.translatef) - luci.util.extfenv(func, "arg", {...}) + local env = { + translate=i18n.translate, + translatef=i18n.translatef, + arg={...} + } + + setfenv(func, setmetatable(env, {__index = + function(tbl, key) + return rawget(tbl, key) or _M[key] or _G[key] + end})) local maps = {func()} -- 2.25.1