[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: getglobal()
- From: "Joshua Jensen" <jjensen@...>
- Date: Mon, 4 Feb 2002 19:44:29 -0700
You can simulate the behavior you want below with the following
function:
function FullLookup(table, variableName)
local lastPos = 1
while 1 do
local curPos = strfind(variableName, "%.", lastPos)
if not curPos then
local var = strsub(variableName, lastPos)
local num = tonumber(var)
if num then
var = num
end
return table[var]
end
local var = strsub(variableName, lastPos, curPos - 1)
local num = tonumber(var)
if num then
var = num
end
lastPos = curPos + 1
table = table[var]
if not table then
return nil
end
end
end
value = FullLookup(globals(), 'Lol.'..Name..'.Version')
Josh
> Lol={}
> Lol.Write={}
> Lol.Write.Version=001
> print(Lol.Write.Version) --> print expected 1
> Name='Write'
> print(getglobal('Lol.'..Name..'.Version')) --> print nil ???
>
> Needed for Robertos Ierusalimschy library suggestion (simple example):
>
> do
>
> if Lol==nil then Lol={}
>
> local Public,Private={},{}
>
> Lol.Write=Public
>
> function Public.Initialise()
>
> %Public.Version = 001
>
> end
>
> end
>
>
> As also suggsted by Roberto I wouldn't like to use dostring()
> instead of
> getglobal()
>
>
> Markus
>
>
>