lua-users home
lua-l archive

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


Hi,

David Jones wrote:
> Now, I don't really have an excuse for poking around in this dark  
> corner, but...
> is this intended?

Probably not. But it's not really a bug either. It could be
called a leak in the implementation.

It's a side-effect of common code for unary and binary operators
in lvm.c and an assumption that nil never has metamethods:

  case OP_LEN:
    ...
    if (!call_binTM(L, rb, luaO_nilobject, ra, TM_LEN)) ...

If the 1st operand (a function in your case) has no metamethod
then call_binTM goes on to try the 2nd operand ... which is nil.
By default nil does not have any metamethods, so you get the
expected error, even for unary operators.

So you have to remember to set metamethods for all other types in
case you really want to use metamethods for nil. I'm not sure
this is a good idea, anyway. :-)

Bye,
     Mike