diff options
author | Ted Trask <ttrask01@yahoo.com> | 2015-01-12 16:11:26 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2015-01-12 16:11:26 +0000 |
commit | af55ecb73277b61a8642fc6bea091291ecc926bf (patch) | |
tree | 4b5eceb2c44db9cf2e73ae9a93d62905821d681a /provisioning-model.lua | |
parent | 207a204bb95ceba5017a91c340b53ef12c0811d8 (diff) | |
download | acf-provisioning-af55ecb73277b61a8642fc6bea091291ecc926bf.tar.bz2 acf-provisioning-af55ecb73277b61a8642fc6bea091291ecc926bf.tar.xz |
Remove setfenv call for Lua 5.2 compatibility
Diffstat (limited to 'provisioning-model.lua')
-rw-r--r-- | provisioning-model.lua | 51 |
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 |