[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: __declared
- From: Graham Wakefield <wakefield@...>
- Date: Mon, 2 Dec 2013 22:13:35 +0900
I may be missing something, but a routine to print all globals is
for k, v in pairs(_G) do
print(k, v)
-- insert recursion if desired here…
end
(Obviously a fancier printer would memoize, handle loops, trace metatables, format prettily etc… but my point is that strict.lua isn't required to find globals.)
On Oct 31, 2013, at 10:09 AM, Jose Torre-Bueno <jtorrebueno@cox.net> wrote:
> On Oct 30, 2013, at 5:06 PM, Paige DePol <lual@serfnet.org> wrote:
>
>>
>> I patched the parser and added a 'global' keyword for the explicit declaration of global variables, though instead of storing my table in _G I stored it in the registry.
>>
>> -Paige
>
> Given that strict had created the __declared table inside _G I was able to make a function to list all globals like so:
>
> function listglobals()
> local t = getmetatable(_G)
> for i,_ in pairs(t.__declared) do
> local ty = type(_G[i])
> local sz = 0
> if ty == 'table' then sz = #_G[i] end
> printf('%20s, %10s, %4d',i, ty, sz)
> end
> end
>
> Its remarkable how easy it is to do things like this in Lua.
>
>
>
> Jose de la Torre-Bueno, Ph.D.
> Empowered Energy Solutions Inc.
> Intellectual Property & Technology Management
> T (619) 977-0553
> F (760) 295-7119
> jtorrebueno@cox.net
>
>
>
>
>
>
>
>