|
2014-02-23 2:38 GMT+02:00 Anders Petersson <andpet@gmail.com>:
PiL 3 is available online, though not gratis.
> I didn't receive the Programming in Lua book yet so this is all from online
> sources.
> I'm surprised there's no built-in function to print the contents of a table.Because tables can be printed in so many ways, there is no
> I looked at lua-stdlib [2] but it doesn't define such a function either.
one-size-fits-all.
> In particular I haven't found a good description of syntax and semantics ofThose in the official reference manual are good, though terse. See
> __pairs/__ipairs metamethods.
under global functions `pairs` and `ipairs`. But the really decent
explanation is in PiL.
"If t has a metamethod __pairs, calls it with t as argument and returns the first three results from the call.Otherwise, returns three values: the next function, the table t, and nil, so that the constructionfor k,v in pairs(t) do body endwill iterate over all key–value pairs of table t."
> The wiki [4] talks of 'pairs' as an experimental feature and also mentionsA wiki is written by users. There is the occasional contributor that
> 'next' which wasn't even included in 5.2? I think the page isn't updated for 5.2?
has a sense of ownership and occasionally revises his pages, but
by and large, when you put something on a Wiki, it is there for
everybody to modify and correct. Even newbies with two weeks
of experience.
> These metamethods are not listed in the 5.2 manual:They don't have their own entries, but search and you shall find.
> __mode, __pairs, __ipairs, __gc, __metatable, __tostring
> And 6.2 'Coroutine Manipulation' states that coroutine operations "compriseWhy is it not true? There is a "coroutine" sublibrary.
> a sub-library of the basic library", which is no longer true.
What version of the manual do you have? The one that comes
> Also, 6.4.1 'Patterns' doesn't explain the now official %f pattern.
with Lua 5.2.3 does explain the frontier pattern.