[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: User-definable table length
- From: pocomane <pocomane_7a@...>
- Date: Mon, 19 Mar 2018 09:08:33 +0100
On Sat, Mar 17, 2018 at 1:16 PM, Egor Skriptunoff
<egor.skriptunoff@gmail.com> wrote:
> Hi!
>
> The following idea already occurred several times on this mailing list.
> We are solving not the problem we have.
> We actually need neither nils in tables nor array data type.
> All we need is USER-DEFINABLE TABLE LENGTH.r
>
Pratically, are you proposing a new {...#} contructor that is just
syntactic sugar for:
```
local function TableWithUserDefinedLength(...)
local result = {...}
setmetatable(result, {
len = select('#',...),
__len = function(a)
return getmetatable(a).len
end
})
return result
end
```
?
Just two notes:
1) The [...] constructor can be used instead
2) It can be strongly simplified, If the __len metamethod will be
changed to accept also a number to be plainly returned.