lua-users home
lua-l archive

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


Philippe,

I will split my reply in two because your email is quite rich. Here the reply about metatables:

Why not "t[!]" or "t[~]" to refer to the metatable with the index notation (except that the index is not valid _expression_ here, it's a syntaxic construct)
The alternative would be to give a meaning to t[nil]: trying to read index nil normally generates an exception (with the default getindex accessor) but could as well allow reading/writing the metatable 
:  
- t[['m']] would access to the member 'm' of the metatable of t as a shortcut to getmetatable(t)['m']
- t[[[m']]] would access to the member 'm' of the metatable of the metatable of t as a shortcut to getmetatable(getmetatable(t))['m']

Lua syntax is clean and beautiful. Maybe there is a way to respect the spirit of the language, We can adopt a solution similar to _ENV that has replaced getfenv/setfenv, The metatable is a property of tables (and types in some case) you can then choose to have a property table:

_META[t] = mt   -- same as setmetatable(t,mt)

mt = _META[t]   -- same as mt = getmetatable(t)

This is similar to the solution adopted by _ENV so looks clean (at least to me). It would not be an actual look up in the META properties table, instead it would be map to the functions that are in place today.

   Andrea


--
Andrea Vitali