[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: nil's metatable
- From: Mike Pall <mikelu-0607@...>
- Date: Tue, 4 Jul 2006 18:17:17 +0200
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:
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. :-)