lua-users home
lua-l archive

Re: nil's metatable

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


On 4 Jul 2006, at 17:17, Mike Pall wrote:
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)) ...
This "bug" can be "fixed" be passing in rb twice.
drj
--- ../src/lvm.c 2006年01月23日 19:51:43.000000000 +0000
+++ lvm.c 2006年07月05日 08:15:35.000000000 +0000
@@ -519,7 +519,7 @@
 }
 default: { /* try metamethod */
 Protect(
- if (!call_binTM(L, rb, luaO_nilobject, ra, TM_LEN))
+ if (!call_binTM(L, rb, rb, ra, TM_LEN))
 luaG_typeerror(L, rb, "get length of");
 )
 }

AltStyle によって変換されたページ (->オリジナル) /