mirror of
https://github.com/rxi/lovebird.git
synced 2024-11-15 22:54:21 +00:00
Moved compilation of page templates to lovebird.init()
All the page templates are now compiled into functions when lovebird is inited. This avoids having to interpret a page template each time it is requested.
This commit is contained in:
parent
188d052d34
commit
62db558f4c
@ -379,9 +379,11 @@ end
|
||||
|
||||
|
||||
function lovebird.init()
|
||||
-- Init server
|
||||
lovebird.server = assert(socket.bind(lovebird.host, lovebird.port))
|
||||
lovebird.addr, lovebird.port = lovebird.server:getsockname()
|
||||
lovebird.server:settimeout(0)
|
||||
-- Wrap print
|
||||
if lovebird.wrapprint then
|
||||
local oldprint = print
|
||||
print = function(...)
|
||||
@ -389,6 +391,10 @@ function lovebird.init()
|
||||
lovebird.print(...)
|
||||
end
|
||||
end
|
||||
-- Compile page templates
|
||||
for k, page in pairs(lovebird.pages) do
|
||||
lovebird.pages[k] = lovebird.template(page, "lovebird, req")
|
||||
end
|
||||
lovebird.inited = true
|
||||
end
|
||||
|
||||
@ -498,8 +504,7 @@ function lovebird.onrequest(req, client)
|
||||
local str
|
||||
xpcall(function()
|
||||
str = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n" ..
|
||||
lovebird.template(lovebird.pages[page],
|
||||
"lovebird, req")(lovebird, req)
|
||||
lovebird.pages[page](lovebird, req)
|
||||
end, lovebird.onerror)
|
||||
return str
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user