[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: High-level vs low-level overrides / Multi-level overrides
- From: Dirk Laurie <dirk.laurie@...>
- Date: Tue, 2 Aug 2016 07:33:34 +0200
2016-08-02 4:37 GMT+02:00 Duane Leslie <parakleta@darkreality.org>:
> `pairs` is actually building me a custom iterator closure which
> it returns as its first result.
It may feel like that but in fact `pairs` simply returns `next,tbl,nil.`
That is why you don't really need __next. You can simply say
for k,v in mynext,tbl do ... end
`io.lines` and `string.gmatch` do make custom closures. You can do
things like
> f = ("The quick brown fox jumps over the lazy dog"):gmatch"%S*"
> repeat word = f() until word=='over'
> for word in f do print(word) end
the
lazy
dog
You can't do that with "pairs".