lua-users home
lua-l archive

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


2018-01-20 6:23 GMT+02:00 Sean Conner <sean@conman.org>:

>   Also, Lua 5.2 introduced two new metamethods, __pair and __ipairs.  Lua
> 5.3 dropped __ipairs because PUC felt it wasn't needed.

I hate that last part.

'ipairs' looks so simple, but it depends on __index, which can have
unpleasant side effects. E.g. I would like to print the contents of a list
using table.concat (which respects __len). It balks at 'nil', so I innocently
put in an __index metamethod which returns a nice-looking string
(such as '⎕'). table.,concat now works as desired. Unfortunately,
'ipairs' then loops infinitely.

There was a proposal on this list long ago, probably when 5.3 was in
alpha, that __len should be allowed to be an integer rather than
a function, in which case it is a hard limit past which ipairs should not go.

Am I hijacking the thread? Not really. This anecdote demonstrates the
enormous ripples that even a tiny change to the current behaviour of
a table can cause.

But "It's more of a fun exercise than anything." Ipse dicit.