lua-users home
lua-l archive

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


2014-04-12 11:07 GMT+02:00 duz <duz@sol-3.de>:
> On 12.04.2014 10:10, Dirk Laurie wrote:
>>
>> 2014-04-12 5:02 GMT+02:00 Peng Zhicheng <pengzhicheng1986@gmail.com>:
>>
>>> the `metamethod' mechanism in Lua is FALLBACK, not OVERRIDE.
>>> the __index metamethod is fallback for non-existance keys.
>
>
> This does not apply to userdata, which is what I use.

It does apply to userdata — but since there are no predefined actions,
there is no discernible difference.

> This sounds like you've been carried away and hit your head
> trying all sorts of strange things that would never occur to me.

That statement, apart from the last six words which I cannot check,
is correct.

Among the things I hit my head on were:

1. The notation z[x,y] does not translate to __index(z,x,y).
2. The notation a,b = z[x] always assigns nil to b.

I used the following methods.

1. The notations z{x,y} and z"1,2". Not so nice. They solve only
one of the problems.
2. The notation z(x,y). Fully satisfactory. One can always use
z:init() or whatever for the purpose that the __call metamethod
would otherwise have been in use.
3. eval"z[x,y]", where 'eval' uses a parser written in LPeg to
translate all my language extensions to function calls and then
executes them. Difficult to implement when upvalues are needed.