lua-users home
lua-l archive

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


2016-05-05 14:56 GMT+02:00 Roberto Ierusalimschy <roberto@inf.puc-rio.br>:
>> On 4 May 2016 at 21:30, Luiz Henrique de Figueiredo
>> <lhf@tecgraf.puc-rio.br> wrote:
>> > All feedback welcome. Thanks.
>>
>> It's certainly a matter of taste, but... isn't calling the example
>> metatable event "__env" needlessly confusing, given that there is no
>> actual event called __env and _ENV means something else entirely?
>
> Sorry, but what "example" are you talking about?
>
> -- Roberto
>

You can query the metatable of any value using the getmetatable
function. Lua queries metamethods in metatables using a raw access
(see rawget). So, to retrieve the metamethod for event env in object
o, Lua does the equivalent to the following code:

     rawget(getmetatable(o) or {}, "__env")