
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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