From af55ecb73277b61a8642fc6bea091291ecc926bf Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Mon, 12 Jan 2015 16:11:26 +0000 Subject: Remove setfenv call for Lua 5.2 compatibility --- config/delete_device.lua | 16 +++++++++++----- config/update_device.lua | 16 +++++++++++----- 2 files changed, 22 insertions(+), 10 deletions(-) (limited to 'config') diff --git a/config/delete_device.lua b/config/delete_device.lua index edf9cf2..59c8c89 100644 --- a/config/delete_device.lua +++ b/config/delete_device.lua @@ -50,11 +50,17 @@ for name,val in pairs(params.value) do end -- Then call the other script +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("/etc/provisioning/update_device_params.lua") +local IS_52_LOAD = pcall(load, '') +if IS_52_LOAD then + f = loadfile("/etc/provisioning/update_device_params.lua", "bt", env) +else + -- loadfile loads into the global environment + -- so we set env 0, not env 1 + setfenv (0, env) + f = loadfile("/etc/provisioning/update_device_params.lua") + setfenv (0, _G) +end if (f) then f(functions, params, oldparams) end -setfenv (0, _G) diff --git a/config/update_device.lua b/config/update_device.lua index 302b3a7..cb575e9 100644 --- a/config/update_device.lua +++ b/config/update_device.lua @@ -4,11 +4,17 @@ local functions, device, olddevice, params, oldparams = ... --functions.logevent("got to update_device script") -- We'll handle the changing of the device by handling the resulting changing of the params +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("/etc/provisioning/update_device_params.lua") +local IS_52_LOAD = pcall(load, '') +if IS_52_LOAD then + local f = loadfile("/etc/provisioning/update_device_params.lua", "bt", env) +else + -- loadfile loads into the global environment + -- so we set env 0, not env 1 + setfenv (0, env) + local f = loadfile("/etc/provisioning/update_device_params.lua") + setfenv (0, _G) +end if (f) then f(functions, params, oldparams) end -setfenv (0, _G) -- cgit v1.2.3