* Reworked host-Target for global Makefile

* Fixed dispatcher to correctly support fastindex
This commit is contained in:
Steven Barth 2008-05-26 12:16:16 +00:00
parent 5f40074c0e
commit d4399bf618
4 changed files with 43 additions and 12 deletions

View file

@ -15,8 +15,9 @@ clean:
for i in $(MODULES); do make -C$$i clean; done for i in $(MODULES); do make -C$$i clean; done
host: build host: build
mkdir -p host/luci mkdir -p host
for i in $(MODULES); do cp $$i/dist$(LUCI_INSTALLDIR) host/ -R 2>/dev/null || true; done for i in $(MODULES); do cp $$i/dist/* host/ -R 2>/dev/null || true; done
ln -sf .$(LUCI_INSTALLDIR) host/luci
hostclean: clean hostclean: clean
rm host -rf rm host -rf

View file

@ -1,3 +1,2 @@
#!/usr/bin/haserl --shell=luac #!/usr/bin/haserl --shell=luac
require("luci.dispatcher").createindex() require("luci.dispatcher").httpdispatch()
luci.dispatcher.httpdispatch()

View file

@ -9,7 +9,7 @@ source:
for i in $$(find dist -name .svn); do rm $$i -rf; done for i in $$(find dist -name .svn); do rm $$i -rf; done
compile: source 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
clean: clean:
rm dist -rf rm dist -rf

View file

@ -31,12 +31,19 @@ require("luci.fs")
-- Local dispatch database -- Local dispatch database
local tree = {nodes={}} local tree = {nodes={}}
-- Index table
local index = {}
-- Global request object -- Global request object
request = {} request = {}
-- Active dispatched node -- Active dispatched node
dispatched = nil dispatched = nil
-- Status fields
built_index = false
built_tree = false
-- Builds a URL -- Builds a URL
function build_url(...) function build_url(...)
@ -68,7 +75,7 @@ function error500(message)
return false return false
end end
-- Dispatches a request depending on the PATH_INFO variable -- Creates a request object for dispatching
function httpdispatch() function httpdispatch()
local pathinfo = luci.http.env.PATH_INFO or "" local pathinfo = luci.http.env.PATH_INFO or ""
local c = tree local c = tree
@ -80,7 +87,12 @@ function httpdispatch()
dispatch() dispatch()
end end
-- Dispatches a request
function dispatch() function dispatch()
if not built_tree then
createtree()
end
local c = tree local c = tree
local track = {} local track = {}
@ -131,6 +143,7 @@ end
-- Generates the dispatching tree -- Generates the dispatching tree
function createindex() function createindex()
index = {}
local path = luci.sys.libpath() .. "/controller/" local path = luci.sys.libpath() .. "/controller/"
local suff = ".lua" local suff = ".lua"
@ -139,6 +152,8 @@ function createindex()
else else
createindex_plain(path, suff) createindex_plain(path, suff)
end end
built_index = true
end end
-- Uses fastindex to create the dispatching tree -- Uses fastindex to create the dispatching tree
@ -149,10 +164,7 @@ function createindex_fastindex(path, suffix)
fi.scan() fi.scan()
for k, v in pairs(fi.indexes) do for k, v in pairs(fi.indexes) do
local stat, mod = pcall(require, v[2]) index[v[2]] = v[1]
luci.util.updfenv(v[1], luci.dispatcher)
pcall(v[1])
end end
end end
@ -168,12 +180,31 @@ function createindex_plain(path, suffix)
stat, mod = pcall(require, c) stat, mod = pcall(require, c)
if stat and mod and type(mod.index) == "function" then if stat and mod and type(mod.index) == "function" then
luci.util.updfenv(mod.index, luci.dispatcher) index[c] = mod.index
pcall(mod.index)
end end
end end
end end
-- 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 -- Shortcut for creating a dispatching node
function entry(path, target, title, order, add) function entry(path, target, title, order, add)
add = add or {} add = add or {}