diff options
author | Steven Barth <steven@midlink.org> | 2008-11-11 18:55:07 +0000 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2008-11-11 18:55:07 +0000 |
commit | f96de2586a80eb94060fbeef5d92703bd6db7a4b (patch) | |
tree | 284e2a8c7e57382e5b80b0632e4d7b5f03361d37 /libs/web/luasrc | |
parent | 7086a166e4bbbd39165fb05668e5abeb4cc1ebff (diff) |
Implemented dispatching tree modifiers
Diffstat (limited to 'libs/web/luasrc')
-rw-r--r-- | libs/web/luasrc/dispatcher.lua | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/libs/web/luasrc/dispatcher.lua b/libs/web/luasrc/dispatcher.lua index 2323cf8d2..b48b58487 100644 --- a/libs/web/luasrc/dispatcher.lua +++ b/libs/web/luasrc/dispatcher.lua @@ -354,9 +354,11 @@ function createtree() local ctx = context local tree = {nodes={}} + local modi = {} ctx.treecache = setmetatable({}, {__mode="v"}) ctx.tree = tree + ctx.modifiers = modi -- Load default translation require "luci.i18n".loadc("default") @@ -369,9 +371,30 @@ function createtree() v() end + local function modisort(a,b) + return modi[a].order < modi[b].order + end + + for _, v in util.spairs(modi, modisort) do + scope._NAME = v.module + setfenv(v.func, scope) + v.func() + end + return tree end +--- Register a tree modifier. +-- @param func Modifier function +-- @param order Modifier order value (optional) +function modifier(func, order) + context.modifiers[#context.modifiers+1] = { + func = func, + order = order or 0, + module = getfenv(2)._NAME + } +end + --- Clone a node of the dispatching tree to another position. -- @param path Virtual path destination -- @param clone Virtual path source |