How to dump a table to console?

Feel free to browse the Lua Wiki on table serialization. It lists several ways on how to dump a table to the console. You just have to choose which one suits you best. There are many ways to do it, but I usually end up using the one from Penlight:

How to get number of entries in a Lua table?

You already have the solution in the question — the only way is to iterate the whole table with pairs(..). Also, notice that the “#” operator’s definition is a bit more complicated than that. Let me illustrate that by taking this table: According to the manual, any of 3, 5 and 9 are valid results for #t. The only … Read more

What is the difference of pairs() vs. ipairs() in Lua?

pairs() and ipairs() are slightly different. pairs() returns key-value pairs and is mostly used for associative tables. key order is unspecified. ipairs() returns index-value pairs and is mostly used for numeric tables. Non numeric keys in an array are ignored, while the index order is deterministic (in numeric order). This is illustrated by the following … Read more