Fix rewrite and alias functions

This commit is contained in:
Steven Barth 2008-10-30 19:09:52 +00:00
parent 3f66d4e5fc
commit 2d4f21e955

View file

@ -440,8 +440,12 @@ end
--- Create a redirect to another dispatching node. --- Create a redirect to another dispatching node.
-- @param ... Virtual path destination -- @param ... Virtual path destination
function alias(...) function alias(...)
local req = arg local req = {...}
return function() return function(...)
for _, r in ipairs({...}) do
req[#req+1] = r
end
dispatch(req) dispatch(req)
end end
end end
@ -450,17 +454,23 @@ end
-- @param n Number of path values to replace -- @param n Number of path values to replace
-- @param ... Virtual path to replace removed path values with -- @param ... Virtual path to replace removed path values with
function rewrite(n, ...) function rewrite(n, ...)
local req = arg local req = {...}
return function() return function(...)
local dispatched = util.clone(context.dispatched)
for i=1,n do for i=1,n do
table.remove(context.path, 1) table.remove(dispatched, 1)
end end
for i,r in ipairs(req) do for i, r in ipairs(req) do
table.insert(context.path, i, r) table.insert(dispatched, i, r)
end end
dispatch() for _, r in ipairs({...}) do
dispatched[#dispatched+1] = r
end
dispatch(dispatched)
end end
end end