lua-users home
lua-l archive

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


Jose,

I do not believe that is part of the Lua core. I could not find any reference to '__declared' in the lua-5.2.2 code base and a grep for just 'declared' only returns results that are comments. I also looked in my own environment table and could not find a '__declared' field.

Perhaps you have a patched Lua and/or some other module is creating the '__declared' key in your environment?

-Paige



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. 
> 
> I am not aware of any documentation of this feature, __declared does not appear in the Lua 5.2 reference manual or in the index of PiL 3rd edition.  Is this a documented feature of Lua? Can I rely on this in the future?  Also do the __newindex and __index functions in the metatable do anything other than maintain __declared?
> 
> I discovered this in the process of studying whether I could create a function that incremented a counter for every access of a function.  I have in mind a function installed as the __index function of the metatable that would maintain a table similar to __declared except that it would increment a counter for the called function every time it was called.  if this function ended by calling the preexisting __index function would that work without breaking 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
> 
>