[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] Lua 5.2.0 (work1) now available
- From: Tom N Harris <telliamed@...>
- Date: Sun, 10 Jan 2010 22:01:37 -0500
Nevin Flanagan wrote:
>
> On Jan 9, 2010, at 3:26 PM, Tom N Harris wrote:
>> __index can be a table instead of a function. Can __len be a number?
>
> It seems to me that it could be, if it can't be now. That seems to fit well into the Lua idiom.
The manual is misleading about __len. The pseudo-code says...
function len_event (op)
--[[ snip ]]--
local h = metatable(op).__len
if h then
return (h(op)) -- call handler with the operand
elseif type(op) == "table" then
return #op -- primitive table length
--[[ snip ]]--
If that were the case, then this would be possible...
T=setmetatable({},{
__len=setmetatable({gth=0},{
__len=function(o) return o.gth end
})
})
getmetatable(T).__len.gth = 3
print(#T)
An unrelated minor bug in 5.2 (actually 5.1 has it too):
S=[[]]
T={}
C=coroutine.create(function() end)
print(type(S),type(T),type(C))
print(S<T)
print(T<T)
print(S<C) -- error message is wrong
--
- tom
telliamed@whoopdedo.org
- References:
- [ANN] Lua 5.2.0 (work1) now available, Luiz Henrique de Figueiredo
- Re: [ANN] Lua 5.2.0 (work1) now available, Alexander Gladysh
- Re: [ANN] Lua 5.2.0 (work1) now available, Alexander Gladysh
- Re: [ANN] Lua 5.2.0 (work1) now available, Alexander Gladysh
- Re: [ANN] Lua 5.2.0 (work1) now available, Ignacio Burgueño
- Re: [ANN] Lua 5.2.0 (work1) now available, steve donovan
- Re: [ANN] Lua 5.2.0 (work1) now available, Alexander Gladysh
- Re: [ANN] Lua 5.2.0 (work1) now available, steve donovan
- Re: [ANN] Lua 5.2.0 (work1) now available, Tom N Harris
- Re: [ANN] Lua 5.2.0 (work1) now available, Nevin Flanagan