19
votes

I'm trying to learn the ropes on Lua, and I was going through the online tutorials. One problem I tried to solve was to examine a table local foo = {} to see how many elements it had. The tutorial gave the suggestion to use local length = table.getn(foo). When i try this using Lua52, I get an error stating attempt to call field 'getn' (a nil value). I looked around further and noticed that any of the functions given with table produce the same type of error. Was the table library removed from Lua? Is it a third-party library, or what gives?

2

2 Answers

40
votes

Use the length operator # as in #foo.

table.getn was deprecated in 5.1 and removed in 5.2.

5
votes

The table library wasn't removed, as it's an essential part of the language and the module system. The getn function was removed but if none of the table functions work, it's almost certainly because you've overwritten table.