[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: number of result value for __len metamethod
- From: Rici Lake <lua@...>
- Date: Tue, 9 Jan 2007 14:46:09 -0500
On 9-Jan-07, at 11:21 AM, Thomas Lavergne wrote:
Is there any reason for the __len metamethod to reduce only allow
returning a single value ?
Currently, all Lua operators return single values; only function calls
and the ... syntax can return multiple values. Of course, the
metamethod can return as many values as it likes, but it will get
corrected to a single value inside the VM opcode.
I'm sure that it would be possible to change that, but it would require
a redesign of the VM, and would undoubtedly slow down VM execution.
It's probably better, in the particular case of __len, to define an
object method, or a primitive function, possibly something along these
lines:
function len(x) return getmetatable(x).__len(x) end