* Fixed dispatcher to correctly support fastindex
for i in $(MODULES); do make -C$$i clean; done
host: build
for i in $(MODULES); do make -C$$i clean; done
host: build
- mkdir -p host/luci
- for i in $(MODULES); do cp $$i/dist$(LUCI_INSTALLDIR) host/ -R 2>/dev/null || true; done
+ mkdir -p host
+ for i in $(MODULES); do cp $$i/dist/* host/ -R 2>/dev/null || true; done
+ ln -sf .$(LUCI_INSTALLDIR) host/luci
hostclean: clean
rm host -rf
hostclean: clean
rm host -rf
#!/usr/bin/haserl --shell=luac
#!/usr/bin/haserl --shell=luac
-require("luci.dispatcher").createindex()
-luci.dispatcher.httpdispatch()
\ No newline at end of file
+require("luci.dispatcher").httpdispatch()
\ No newline at end of file
for i in $$(find dist -name .svn); do rm $$i -rf; done
compile: source
for i in $$(find dist -name .svn); do rm $$i -rf; done
compile: source
- for i in $$(find dist -name *.lua); do $(LUAC) $(LUAC_OPTIONS) -o $$i $$i; done
+ for i in $$(find dist -name *.lua -not -name debug.lua); do $(LUAC) $(LUAC_OPTIONS) -o $$i $$i; done
-- Local dispatch database
local tree = {nodes={}}
-- Local dispatch database
local tree = {nodes={}}
+-- Index table
+local index = {}
+
-- Global request object
request = {}
-- Active dispatched node
dispatched = nil
-- Global request object
request = {}
-- Active dispatched node
dispatched = nil
+-- Status fields
+built_index = false
+built_tree = false
+
-- Builds a URL
function build_url(...)
-- Builds a URL
function build_url(...)
--- Dispatches a request depending on the PATH_INFO variable
+-- Creates a request object for dispatching
function httpdispatch()
local pathinfo = luci.http.env.PATH_INFO or ""
local c = tree
function httpdispatch()
local pathinfo = luci.http.env.PATH_INFO or ""
local c = tree
+ if not built_tree then
+ createtree()
+ end
+
local c = tree
local track = {}
local c = tree
local track = {}
-- Generates the dispatching tree
function createindex()
-- Generates the dispatching tree
function createindex()
local path = luci.sys.libpath() .. "/controller/"
local suff = ".lua"
local path = luci.sys.libpath() .. "/controller/"
local suff = ".lua"
else
createindex_plain(path, suff)
end
else
createindex_plain(path, suff)
end
end
-- Uses fastindex to create the dispatching tree
end
-- Uses fastindex to create the dispatching tree
fi.scan()
for k, v in pairs(fi.indexes) do
fi.scan()
for k, v in pairs(fi.indexes) do
- local stat, mod = pcall(require, v[2])
-
- luci.util.updfenv(v[1], luci.dispatcher)
- pcall(v[1])
stat, mod = pcall(require, c)
if stat and mod and type(mod.index) == "function" then
stat, mod = pcall(require, c)
if stat and mod and type(mod.index) == "function" then
- luci.util.updfenv(mod.index, luci.dispatcher)
- pcall(mod.index)
+-- Creates the dispatching tree from the index
+function createtree()
+ if not built_index then
+ createindex()
+ end
+
+ 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
+
+ pcall(v)
+ end
+
+ built_tree = true
+end
+
-- Shortcut for creating a dispatching node
function entry(path, target, title, order, add)
add = add or {}
-- Shortcut for creating a dispatching node
function entry(path, target, title, order, add)
add = add or {}