Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lua table library removed?

Tags:

lua

lua-table

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?

like image 692
Piotr Avatar asked Aug 09 '12 18:08

Piotr


People also ask

How to remove from table Lua?

An item can be removed from an array with Lua's table. remove() function. This will remove the item at the specified position and move any following items down one index position.

How to insert table Lua?

In Lua, the table library provides functions to insert elements into the table. The insert function usually takes two arguments, the first argument is usually the name of the table from which we want to insert the element to, and the second argument is the element that we want to insert.

How to remove in Lua?

remove () function removes a value from an array using the index position of the value to be removed. This function removes the element at the pos position from the table. This causes other elements to shift down to close the space, if necessary. This function returns the value that we remove from the table.

What is Lua table?

Tables are the only data structure available in Lua that helps us create different types like arrays and dictionaries. Lua uses associative arrays and which can be indexed with not only numbers but also with strings except nil. Tables have no fixed size and can grow based on our need.


2 Answers

Use the length operator # as in #foo.

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

like image 111
lhf Avatar answered Nov 02 '22 10:11

lhf


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.

like image 40
Craig Avatar answered Nov 02 '22 10:11

Craig