summaryrefslogtreecommitdiffhomepage
path: root/libs/web/luasrc/template.lua
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2008-06-14 14:12:12 +0000
committerSteven Barth <steven@midlink.org>2008-06-14 14:12:12 +0000
commit855b7582d3576f45693e3a48fdb253c813cf4dce (patch)
treeb912f63dc43f3b696385083542c801dba8c53976 /libs/web/luasrc/template.lua
parent50fd29841540bb8b1735291b72853454679e9e62 (diff)
* Rewrote Luci to be coroutine-safe allowing the use of non-forking webservers
* Setting base version to 0.7
Diffstat (limited to 'libs/web/luasrc/template.lua')
-rw-r--r--libs/web/luasrc/template.lua14
1 files changed, 8 insertions, 6 deletions
diff --git a/libs/web/luasrc/template.lua b/libs/web/luasrc/template.lua
index 61e4e39ec9..29aedcdadd 100644
--- a/libs/web/luasrc/template.lua
+++ b/libs/web/luasrc/template.lua
@@ -44,9 +44,10 @@ compiler_mode = luci.config.template.compiler_mode or "memory"
-- Define the namespace for template modules
+context = luci.util.threadlocal()
+
viewns = {
- write = io.write,
- include = function(name) Template(name):render(getfenv(2)) end,
+ include = function(name) Template(name):render(getfenv(2)) end,
}
-- Compiles a given template into an executable Lua module
@@ -113,7 +114,7 @@ end
-- Oldstyle render shortcut
function render(name, scope, ...)
scope = scope or getfenv(2)
- local s, t = pcall(Template, name)
+ local s, t = luci.util.copcall(Template, name)
if not s then
error(t)
else
@@ -141,9 +142,10 @@ function Template.__init__(self, name)
self.viewns = {}
-- Copy over from general namespace
- for k, v in pairs(viewns) do
- self.viewns[k] = v
- end
+ luci.util.update(self.viewns, viewns)
+ if context.viewns then
+ luci.util.update(self.viewns, context.viewns)
+ end
-- If we have a cached template, skip compiling and loading
if self.template then