- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
table.unpack() function in Lua programming
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.
Syntax
table.unpack{x,y,z,....}
Example
The 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 −
a, 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 will be discarded.
Output
1 2
Example
It should be noted that if we don’t pass any value then all the values that are present in the list will be returned from the table.unpack() function. Consider the example shown below −
print(table.unpack{1,2,3})
Output
1 2 3
Example
We can also ignore elements and select a specific index or positioned element from the list, consider the example shown below −
_, b = table.unpack{-1,-2} print(b)
Output
-2
- Related Articles
- Table Type in Lua Programming
- table.pack() function in Lua programming
- math.ceil() function in Lua programming
- math.floor() function in Lua programming
- math.max() function in Lua programming
- math.modf() function in Lua programming
- select() function in Lua programming
- Sort function in Lua programming
- string.byte() function in Lua programming
- string.char() function in Lua programming
- string.format() function in Lua programming
- string.gsub() function in Lua programming
- string.lower() function in Lua programming
- string.upper() function in Lua programming
- io.popen() function in Lua Programming
