@buxton said in Reactor scope issues:
In many of Patrick's plugins, he uses a global lua table to hold plugin data and functions. He assigns shorthand names that call common luup functions, then stores those truncated names in the table.
Umm... no, I don't think I do. That actually sounds like something I would very specifically not do. Not a big fan of globals; I only use them where Luup forces me to.
Can you post some code that shows what you think that is?
Here, for example, is the definition of the log function L() commonly used in Reactor, which is a model/function I use frequently...
local function L(msg, ...) -- luacheck: ignore 212 local str local level = defaultLogLevel or 50 if type(msg) == "table" then str = tostring(msg.prefix or _PLUGIN_NAME) .. ": " .. tostring(msg.msg or msg[1]) level = msg.level or level else str = _PLUGIN_NAME .. ": " .. tostring(msg) end str = string.gsub(str, "%%(%d+)", function( n ) n = tonumber(n, 10) if n < 1 or n > #arg then return "nil" end local val = arg[n] if type(val) == "table" then return dump(val) elseif type(val) == "string" then return string.format("%q", val) elseif type(val) == "number" and math.abs(val-os.time()) <= 86400 then return tostring(val) .. "(" .. os.date("%Y-%m-%d.%X", val) .. ")" end return tostring(val) end ) luup.log(str, math.max(1,level)) --[[ ???dev if level <= 2 then local f = io.open( "/etc/cmh-ludl/Reactor.log", "a" ) if f then f:write( str .. "\n" ) f:close() end end --]] if level == 0 then if debug and debug.traceback then luup.log( debug.traceback(), 1 ) end error(str, 2) end endIt's just a plain local function. No global in a table Luup function reassignment magic anything, just a straight function that gets use in a vanilla way:
L("Sensor %1 (%2) first run, setting up new instance...", tdev, luup.devices[tdev].description)