TLDR; My functions are not callable from the _G scope, and I want them to be so I can call functions by parsing a list of strings. This could be exacerbated by a package.seeall
required by the framework.
I am working in the luci framework, which is an UCI front end for OpenWRT routers. In an attempt to create customized functions that are called when specific UCI values are parsed I have created functions that share the name of the return value which are called through _G.
The parsed data looks something like this:
data = {Name="value"}
I code looks like this:
function main()
local pageValues={modules={}}
for i,x in pairs(data) do
--here is the part that throws the error
pageValues.modules[x]=_G[x]()
--also throws error when "newValue=_G[x]()
end
end
function value()
--also does not work with "local function value()"
return 'YEA'
end
The error I am getting returned to me is attempt to call field '?' (a nil value)
When I directly pass it the string "value" with pageValues.modules['value']=_G['value']()
I receive attempt to call field 'value' (a nil value)
When is create a dummy variable as such
dummy = 'value'
pageValues.modules[dummy]=_G[dummy]()
I receive attempt to call field '?' (a nil value)
. This is the same if I use local dummy = 'value'
When I parse _G
to see if any of my functions are in it I find that they are not. NOTE Luci automatically calls package.seeall
, and I don't know if that is what is messing with my global's. But, it may be important in answering this question.
My most urgent need is to get this function running correctly. My secondary interest is in how I can determine the scope in Lua to be able to troubleshot sand-boxing issues in LuCI in the future.