summaryrefslogtreecommitdiffhomepage
path: root/libs/web/luasrc/dispatcher.lua
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2008-09-05 18:35:09 +0000
committerSteven Barth <steven@midlink.org>2008-09-05 18:35:09 +0000
commit6a6edda0491119cbba249bae847986313f8c09e0 (patch)
tree2cf995deb214d9451a9cad6a75ab5fc4d4dc7cc6 /libs/web/luasrc/dispatcher.lua
parent37b5ef40df48bb7d4023e66f09a68c1c0e229b8d (diff)
Heavy memory/performance optimizations #4
Diffstat (limited to 'libs/web/luasrc/dispatcher.lua')
-rw-r--r--libs/web/luasrc/dispatcher.lua13
1 files changed, 11 insertions, 2 deletions
diff --git a/libs/web/luasrc/dispatcher.lua b/libs/web/luasrc/dispatcher.lua
index 09e99e7dec..599d652f4c 100644
--- a/libs/web/luasrc/dispatcher.lua
+++ b/libs/web/luasrc/dispatcher.lua
@@ -160,9 +160,10 @@ function dispatch(request)
-- Init template engine
if not track.notemplate then
local tpl = require("luci.template")
- local viewns = {}
+ local viewns = setmetatable({}, {__index=_G})
tpl.context.viewns = viewns
viewns.write = luci.http.write
+ viewns.include = function(name) tpl.Template(name):render(getfenv(2)) end
viewns.translate = function(...) return require("luci.i18n").translate(...) end
viewns.striptags = util.striptags
viewns.controller = luci.http.getenv("SCRIPT_NAME")
@@ -219,7 +220,15 @@ function dispatch(request)
context.dispatched = c
util.copcall(function()
- util.updfenv(c.target, require(c.module))
+ local oldenv = getfenv(c.target)
+ local module = require(c.module)
+ local env = setmetatable({}, {__index=
+
+ function(tbl, key)
+ return rawget(tbl, key) or module[key] or oldenv[key]
+ end})
+
+ setfenv(c.target, env)
end)
c.target(unpack(args))