lua-users home
lua-l archive

Re: High-level vs low-level overrides / Multi-level overrides

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


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".

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