• Subject: Table functions in Lua 5.2 Reference Manual
• From: Jakob Voss <jakob.voss@...>
• Date: Tue, 26 Apr 2011 11:13:57 +0200

```Hi,

```
I think that mixed and sparse tables (tables with some numeric indices but not limited to a range 1 to n) are the most difficult issue of Lua and a source of constant confusion. Unfortunately the Reference Manual does only help if you very carefully read all of it. Could you please update section 6.5 (Table Manipulation) of the Lua 5.2 Reference Manual with some additional hints? The section reads:
```
```
```Most functions in the table library assume that the table represents
an array or a list. For these functions, when we talk about the
"length" of a table we mean the result of the length operator.
```
```
```
1. What are "most functions" out of six? You should better list them by name or say "all but ..."
```

```
3. It is still not clear how the table methods work if you override the length operator with a __len metamethod. As I read the definition, this:
```
t = {[1]="a",[3]="b",[5]="c"}
setmetatable(t,{ len = function() return 5 end })
print( table.concat(t,",") )

```
should print "a,nil,b,nil,c", but it prints only "a". I only propose to change this behaviour but it is not what is written in the reference manual. I have not checked the other table functions, but I know that the current 5.2 manual does not really help, if I happen to use the table functions with sparse tables.
```
```
4. Is There really need for table.pack? As far as I understand, this both are equivalent:
```
t = table.pack(...)
t = {...}; t.n = #t

To clarify, it would be helpful to give the equivalence in the manual.

Jakob

--
Jakob Voß <jakob.voss@gbv.de>, skype: nichtich
Verbundzentrale des GBV (VZG) / Common Library Network
Platz der Goettinger Sieben 1, 37073 Göttingen, Germany
+49 (0)551 39-10242, http://www.gbv.de

```