Table.pack adds count of indices to the end of the data

STR:

  1. Run the following command:
for i, v in pairs(table.pack("1", "2", "3")) do print(i, v) end
  1. Observe the output.

Expectations:
The output should read

1 1
2 2
3 3

Reality:
The output reads

1 1
2 2
3 3
n 3

table.pack produces a malformed table, it is neither a dictionary nor array. Gross :sick:

Edit: Looks like this is intended looking at the documentation

2 Likes

Confirming that this is intentional, we’re following what Lua 5.2 does here: Lua 5.2 Reference Manual

2 Likes

To clarify, the intended usecase is unpack(tab, 1, tab.n)