lua-users home
lua-l archive

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





On Tue, Aug 5, 2014 at 8:58 AM, Coroutines <coroutines@gmail.com> wrote:
On Tue, Aug 5, 2014 at 3:53 AM, Luiz Henrique de Figueiredo
<lhf@tecgraf.puc-rio.br> wrote:

> A central point in Lua semantics is that metamethods correspond to
> events that Lua cannot handle. (Metamethods were originally called
> fallbacks, for this reason.) Addition of two numbers is not such an
> event and it is never performed via a metamethod, even if you define one:
>
>         Lua 5.2.3  Copyright (C) 1994-2013 Lua.org, PUC-Rio
>         > debug.setmetatable(0,{__add=print})
>         > a=1
>         > b=2
>         > =a+b
>         3
>         ... but this works:
>         > debug.setmetatable(0,{__call=print})
>         > a(10,20,30)
>         1       10      20      30

Well yes, I do understand this... I just wish the focus of metamethods
were changed.  It'd be inefficient but interesting to expose the base
mechanics through the primitive types having a metatable -- imo.  It'd
be really cool to disable adding numbers by unreferencing the C code
that handles __add, for example -- this has always been a dream of
mine :\..



That seems interesting.

As it is, Lua has one structure: the table. With it, there just isn't anything that you can't do. The basic types are not handled in the same way as tables are. The fact that strings are interned and passed by reference is opaque (until you try to export a Lua state).

If you view the table as your sole mechanism with which to accomplish all desired craziness, then what is left that is impossible? That is, what is a table object incapable of doing that would require messing with the internals in that way?

[this is ot. perhaps it should be forked?]

-Andrew