From: Steven Barth Date: Fri, 24 Jul 2009 15:45:29 +0000 (+0000) Subject: Revert external tree usage X-Git-Tag: 0.10.0~1313 X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fluci.git;a=commitdiff_plain;h=2655871d397d70eabe10cc45fb822d6e44923499 Revert external tree usage --- diff --git a/libs/web/luasrc/dispatcher.lua b/libs/web/luasrc/dispatcher.lua index 8c3320b0f..c863d9ff7 100644 --- a/libs/web/luasrc/dispatcher.lua +++ b/libs/web/luasrc/dispatcher.lua @@ -108,7 +108,7 @@ end --- Dispatch an HTTP request. -- @param request LuCI HTTP Request object -function httpdispatch(request, prefix, ext_tree) +function httpdispatch(request) luci.http.context.request = request context.request = {} local pathinfo = http.urldecode(request:getenv("PATH_INFO") or "", true) @@ -118,7 +118,7 @@ function httpdispatch(request, prefix, ext_tree) end local stat, err = util.coxpcall(function() - dispatch(context.request, ext_tree) + dispatch(context.request) end, error500) luci.http.close() @@ -128,7 +128,7 @@ end --- Dispatches a LuCI virtual path. -- @param request Virtual path -function dispatch(request, ext_tree) +function dispatch(request) --context._disable_memtrace = require "luci.debug".trap_memtrace("l") local ctx = context ctx.path = request @@ -151,14 +151,12 @@ function dispatch(request, ext_tree) end require "luci.i18n".setlanguage(lang) - if ext_tree then - ctx.index, ctx.tree, ctx.treecache, ctx.modifiers = unpack(ext_tree) - elseif not ctx.tree then - createtree() - end - local c = ctx.tree local stat + if not c then + c = createtree() + end + local track = {} local args = {} ctx.args = args @@ -226,13 +224,13 @@ function dispatch(request, ext_tree) end tpl.context.viewns = setmetatable({ - write = luci.http.write; - include = function(name) tpl.Template(name):render(getfenv(2)) end; - translate = function(...) return require("luci.i18n").translate(...) end; - striptags = util.striptags; - media = media; - theme = fs.basename(media); - resource = luci.config.main.resourcebase + write = luci.http.write; + include = function(name) tpl.Template(name):render(getfenv(2)) end; + translate = function(...) return require("luci.i18n").translate(...) end; + striptags = util.striptags; + media = media; + theme = fs.basename(media); + resource = luci.config.main.resourcebase }, {__index=function(table, key) if key == "controller" then return build_url() @@ -364,9 +362,9 @@ function createindex() local suff = { ".lua", ".lua.gz" } if luci.util.copcall(require, "luci.fastindex") then - return createindex_fastindex(path, suff) + createindex_fastindex(path, suff) else - return createindex_plain(path, suff) + createindex_plain(path, suff) end end @@ -374,7 +372,7 @@ end -- @param path Controller base directory -- @param suffixes Controller file suffixes function createindex_fastindex(path, suffixes) - local index = {} + index = {} if not fi then fi = luci.fastindex.new("index") @@ -388,8 +386,6 @@ function createindex_fastindex(path, suffixes) for k, v in pairs(fi.indexes) do index[v[2]] = v[1] end - - return index end --- Generate the dispatching index using the native file-cache based strategy. @@ -424,7 +420,7 @@ function createindex_plain(path, suffixes) end end - local index = {} + index = {} for i,c in ipairs(controllers) do local module = "luci.controller." .. c:sub(#path+1, #c):gsub("/", ".") @@ -445,24 +441,21 @@ function createindex_plain(path, suffixes) f:writeall(util.get_bytecode(index)) f:close() end - - return index end --- Create the dispatching tree from the index. -- Build the index before if it does not exist yet. function createtree() - local ctx = context - local tree = {nodes={}} - local cache = setmetatable({}, {__mode="v"}) - local modi = {} - - if not ctx.index then - ctx.index = createindex() + if not index then + createindex() end - ctx.tree = tree - ctx.treecache = cache + local ctx = context + local tree = {nodes={}} + local modi = {} + + ctx.treecache = setmetatable({}, {__mode="v"}) + ctx.tree = tree ctx.modifiers = modi -- Load default translation @@ -470,10 +463,10 @@ function createtree() local scope = setmetatable({}, {__index = luci.dispatcher}) - for k, v in pairs(ctx.index) do + for k, v in pairs(index) do scope._NAME = k setfenv(v, scope) - pcall(v) + v() end local function modisort(a,b) @@ -483,10 +476,10 @@ function createtree() for _, v in util.spairs(modi, modisort) do scope._NAME = v.module setfenv(v.func, scope) - pcall(v.func) + v.func() end - return { index, tree, cache, modi } + return tree end --- Register a tree modifier.