Found 82 Articles for Lua

table.unpack() function in Lua programming

Mukul Latiyan
Updated on 19-Jul-2021 11:17:40

13K+ Views

When we want to return multiple values from a table, we make use of the table.unpack() function. It takes a list and returns multiple values.Syntaxtable.unpack{x, y, z, ....}ExampleThe table.unpack() function provides us with all the values that are passed to it as an argument, but we can also specify which value we want by following the example shown below − Live Demoa, b = table.unpack{1, 2, 3} print(a, b)In the above example, even though the table.unpack() function contains different values, namely 1, 2 and 3, we only are storing the first two values, i.e., a and b and the value 3 ... Read More

table.pack() function in Lua programming

Mukul Latiyan
Updated on 19-Jul-2021 11:16:16

4K+ Views

When we want to return a table as a result from multiple values passed into a function, then we make use of the table.pack() function. The table.pack() function is a variadic function.Syntaxtable.pack(x, y, z, ....)ExampleThe table.pack() function provides a table formed with all the values that are passed to it as an argument, consider the example shown below − Live Demoa = table.pack(1, 2, 3) print(a) print(a.n)In the above example, we passed three numbers to the table.pack() function as an argument and then we are printing the returned value, i.e., which will hold the address of the table that contains the ... Read More

Previous 1 ... 5 6 7 8 9
Advertisements