summaryrefslogtreecommitdiffstats
path: root/provisioning-model.lua
diff options
context:
space:
mode:
Diffstat (limited to 'provisioning-model.lua')
-rw-r--r--provisioning-model.lua51
1 files changed, 34 insertions, 17 deletions
diff --git a/provisioning-model.lua b/provisioning-model.lua
index ee13fb8..2d08f0b 100644
--- a/provisioning-model.lua
+++ b/provisioning-model.lua
@@ -160,15 +160,22 @@ validateparamcoded = function(p, top)
end
if p.validate and p.validate ~= "" then
-- We have Lua validation code
+ local f
local env = {}
setmetatable (env, {__index = _G})
- -- loadfile loads into the global environment
- -- so we set env 0, not env 1
- setfenv (0, env)
- local f = loadstring(p.validate)
+ local IS_52_LOAD = pcall(load, '')
+ if IS_52_LOAD then
+ f = load(p.validate, nil, "bt", env)
+ else
+ -- loadfile loads into the global environment
+ -- so we set env 0, not env 1
+ setfenv (0, env)
+ f = loadstring(p.validate)
+ setfenv (0, _G)
+ end
if (f) then
functions.logevent = mymodule.logevent
- local res, err = pcall(function()
+ local res, err = pcall(function()
p.value, p.errtxt = f(p.value, functions, top)
if p.errtxt then success = false end
end)
@@ -177,19 +184,25 @@ validateparamcoded = function(p, top)
p.errtxt = "Exception in validate code\n"..err
end
end
- setfenv (0, _G)
end
return success
end
local function callscript(script, ...)
local result={}
+ local f
local env = {}
setmetatable (env, {__index = _G})
- -- loadfile loads into the global environment
- -- so we set env 0, not env 1
- setfenv (0, env)
- local f = loadfile(script)
+ local IS_52_LOAD = pcall(load, '')
+ if IS_52_LOAD then
+ f = loadfile(script, "bt", env)
+ else
+ -- loadfile loads into the global environment
+ -- so we set env 0, not env 1
+ setfenv (0, env)
+ f = loadfile(script)
+ setfenv (0, _G)
+ end
if f then
functions.logevent = mymodule.logevent
local res, err = pcall(function(...)
@@ -202,7 +215,6 @@ local function callscript(script, ...)
-- file exists, but wouldn't load
error("Failed to load "..script, 0)
end
- setfenv (0, _G)
return unpack(result)
end
@@ -210,17 +222,22 @@ local function validateluacode(code)
local success = true
-- Validate that contents are valid lua code
+ local f,errtxt
local env = {}
setmetatable (env, {__index = _G})
- -- loadfile loads into the global environment
- -- so we set env 0, not env 1
- setfenv (0, env)
- local f,errtxt = loadstring(code)
+ local IS_52_LOAD = pcall(load, '')
+ if IS_52_LOAD then
+ f = load(code, nil, "bt", env)
+ else
+ -- loadfile loads into the global environment
+ -- so we set env 0, not env 1
+ setfenv (0, env)
+ f,errtxt = loadstring(code)
+ setfenv (0, _G)
+ end
if not f then
success = false
end
- setfenv (0, _G)
- -- setmetatable (self.conf.app_hooks, {})
return success, errtxt
end