Implemented dispatching tree modifiers
This commit is contained in:
parent
7086a166e4
commit
f96de2586a
1 changed files with 23 additions and 0 deletions
|
@ -354,9 +354,11 @@ function createtree()
|
||||||
|
|
||||||
local ctx = context
|
local ctx = context
|
||||||
local tree = {nodes={}}
|
local tree = {nodes={}}
|
||||||
|
local modi = {}
|
||||||
|
|
||||||
ctx.treecache = setmetatable({}, {__mode="v"})
|
ctx.treecache = setmetatable({}, {__mode="v"})
|
||||||
ctx.tree = tree
|
ctx.tree = tree
|
||||||
|
ctx.modifiers = modi
|
||||||
|
|
||||||
-- Load default translation
|
-- Load default translation
|
||||||
require "luci.i18n".loadc("default")
|
require "luci.i18n".loadc("default")
|
||||||
|
@ -369,9 +371,30 @@ function createtree()
|
||||||
v()
|
v()
|
||||||
end
|
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
|
return tree
|
||||||
end
|
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.
|
--- Clone a node of the dispatching tree to another position.
|
||||||
-- @param path Virtual path destination
|
-- @param path Virtual path destination
|
||||||
-- @param clone Virtual path source
|
-- @param clone Virtual path source
|
||||||
|
|
Loading…
Reference in a new issue