assert(media, "No valid theme found")
end
- local function ifattr(cond, key, val)
+ local function _ifattr(cond, key, val)
if cond then
- local env = getfenv(1)
+ local env = getfenv(3)
+ local scope = (type(env.self) == "table") and env.self
return string.format(
' %s="%s"', tostring(key),
luci.util.pcdata(tostring( val
or (type(env[key]) ~= "function" and env[key])
+ or (scope and type(scope[key]) ~= "function" and scope[key])
or "" ))
)
else
write = luci.http.write;
include = function(name) tpl.Template(name):render(getfenv(2)) end;
translate = i18n.translate;
+ translatef = i18n.translatef;
export = function(k, v) if tpl.context.viewns[k] == nil then tpl.context.viewns[k] = v end end;
striptags = util.striptags;
pcdata = util.pcdata;
media = media;
theme = fs.basename(media);
resource = luci.config.main.resourcebase;
- ifattr = ifattr;
- attr = function(...) return ifattr(true, ...) end
+ ifattr = function(...) return _ifattr(...) end;
+ attr = function(...) return _ifattr(true, ...) end;
}, {__index=function(table, key)
if key == "controller" then
return build_url()
local user
if sdat then
- sdat = loadstring(sdat)
- setfenv(sdat, {})
- sdat = sdat()
if not verifytoken or ctx.urltoken.stok == sdat.token then
user = sdat.user
end
local sid = sess or luci.sys.uniqueid(16)
if not sess then
local token = luci.sys.uniqueid(16)
- sauth.write(sid, util.get_bytecode({
+ sauth.reap()
+ sauth.write(sid, {
user=user,
token=token,
secret=luci.sys.uniqueid(16)
- }))
+ })
ctx.urltoken.stok = token
end
luci.http.header("Set-Cookie", "sysauth=" .. sid.."; path="..build_url())
local function _call(self, ...)
+ local func = getfenv()[self.name]
+ assert(func ~= nil,
+ 'Cannot resolve function "' .. self.name .. '". Is it misspelled or local?')
+
+ assert(type(func) == "function",
+ 'The symbol "' .. self.name .. '" does not refer to a function but data ' ..
+ 'of type "' .. type(func) .. '".')
+
if #self.argv > 0 then
- return getfenv()[self.name](unpack(self.argv), ...)
+ return func(unpack(self.argv), ...)
else
- return getfenv()[self.name](...)
+ return func(...)
end
end