lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Oct 30, 2013, at 4:17 PM, Jose Torre-Bueno <jtorrebueno@cox.net> wrote:

> 
> Poking about I discovered that the metatable for _G (or _ENV) has a table called __declared whose keys are the names of user defined objects and value is always true.  This seems a useful thing for testing whether a function has been defined or a table exists. 

Even stranger sometimes I can get the metatable for _G and sometimes not as shown in this interpreter record:

Lua 5.2.0  Copyright (C) 1994-2011 Lua.org, PUC-Rio
> =getmetatable(_G)
nil
> require'utilities'
> =getmetatable(_G)
nil
> require'evolve2'
> = getmetatable(_G)
table: 0x100130730
> 

utilities is 658 lines of Lua and evolve2 is 1533 lines, neither makes any C calls, also just loading them w/o running any functions is enough to make the metatable visible.

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