From b1e131a3db1b6ec2ceecb5df4a224f3de2735e6d Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Tue, 27 May 2008 20:39:48 +0000 Subject: * Optimized dispatching model --- libs/web/luasrc/dispatcher.lua | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'libs/web/luasrc') diff --git a/libs/web/luasrc/dispatcher.lua b/libs/web/luasrc/dispatcher.lua index 6a6bceb29b..202e073321 100644 --- a/libs/web/luasrc/dispatcher.lua +++ b/libs/web/luasrc/dispatcher.lua @@ -137,7 +137,11 @@ function dispatch() if c and type(c.target) == "function" then dispatched = c - + stat, mod = pcall(require, c.module) + if stat then + luci.util.updfenv(c.target, mod) + end + stat, err = pcall(c.target) if not stat then error500(err) @@ -222,12 +226,7 @@ function createtree() for k, v in pairs(index) do luci.util.updfenv(v, _M) - - local stat, mod = pcall(require, k) - if stat then - luci.util.updfenv(v, mod) - end - + luci.util.extfenv(v, "_NAME", k) pcall(v) end @@ -242,6 +241,7 @@ function entry(path, target, title, order, add) c.target = target c.title = title c.order = order + c.module = getfenv(2)._NAME for k,v in pairs(add) do c[k] = v @@ -260,7 +260,7 @@ function node(...) for k,v in ipairs(arg) do if not c.nodes[v] then - c.nodes[v] = {nodes={}} + c.nodes[v] = {nodes={}, module=getfenv(2)._NAME} end c = c.nodes[v] @@ -278,6 +278,10 @@ function alias(...) end end +function call(name) + return function() getfenv()[name]() end +end + function template(name) require("luci.template") return function() luci.template.render(name) end -- cgit v1.2.3