



Here we discuss the Introduction, syntax, How to Work of table structure in Lua programming and example with code implementation respectively. The Lua table is a built-in data structure is in Lua programming, which is used to create an array and dictionary in Lua. And farther also we can see that the element is added and the element is removed from an array. Farther the table length is printing by using “#” operator. A wonderful data structure used to add elements, remove elements and iterate through the elements efficiently in Lua is called Linked lists, which are of two kinds, namely singly-linked lists and doubly linked list where we have a reference pointing to the first node in a singly linked list, and there is a reference from each node to the next node in the singly linked. Print("The length of the city array is : ", #city )Īs in the above Lua program code, a non-empty table is created that is a city without any keys as an array, it takes index number for the key by default, so 1 2, 3,4 are keys and “Bangalore”, “Delhi”, “Mumbai”, “Hyderabad” are the associative values, which are printing farther by using the keys, as we can see in the output. the length of an array get by using the # operator In Lua the table is created by įor key, value in pairs(city) do print( key, value ) end The table data structure used in programming to create an array and dictionary. How Table Structure works in Lua Programming?

value – This parameter specifies the value to be stored for the specific key.It can be number or string type but key does not support nil. table.insert (fruits,'watermelon') print ('index 2 fruit is ',fruits 2) table.insert (fruits,4,'banana') print ('index 4 fruit is ',fruits 4) print ('Max number of elements in the table are',table.maxn (fruits)) print ('Final element is',fruits 6) table. key – This is not an optional type parameter, that specifies the key or index for which the associated value stores.Web development, programming languages, Software testing & others Syntax table.Start Your Free Software Development Course It takes a list and returns multiple values. When we want to return multiple values from a table, we make use of the table.unpack() function.
