Lua Articles

Found 52 articles

table.pack() function in Lua programming

Mukul Latiyan
Mukul Latiyan
Updated on 11-Mar-2026 6K+ 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 −a = 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 value ...

Read More

What does # mean in Lua programming?

Mukul Latiyan
Mukul Latiyan
Updated on 11-Mar-2026 950 Views

The unary operator # is known as the Length operator in Lua. It is used almost everywhere in Lua. By everywhere, I meant that anywhere we would require to calculate the length of the any string or can also be used in tables also, but when it comes to table, it is generally not preferred to use the # operator as it doesn’t calculate the number of elements present inside the table.Let’s explore different examples of the length operator to understand how we can make use of it.ExampleConsider the example shown below −print(#"abcdefg") print(#{"a", "b", "c", 77})Output7 4In the above ...

Read More

What does operator ~= mean in Lua?

Mukul Latiyan
Mukul Latiyan
Updated on 11-Mar-2026 2K+ Views

The ~= symbol or operator in Lua is known as the not-equal to operator. In many programming languages you might have seen the symbol != which is also known as the not equals operator.Let’s consider a few examples where we can make use of the not equals operator.ExampleConsider the examples shown below −a = 2 b = 3 print(a ~= b)OutputtrueExamplet1 = {4,2,3} t2 = {2,3,4} print(t1 ~= t2)Outputtrue

Read More

What is the difference between pairs() vs. ipairs() in Lua?

Mukul Latiyan
Mukul Latiyan
Updated on 11-Mar-2026 11K+ Views

In Lua, we make use of both the pairs() and ipairs() function when we want to iterate over a given table with the for loop. Both these functions return key-value pairs where the key is the index of the element and the value is the element stored at that index table.While both of them have some similarities, it is also good to know that they have some very notable differences that we should be aware of.The first difference between the pairs() and ipairs() function is that the pairs() function doesn’t maintain the key order whereas the ipairs() function surely does.ExampleConsider ...

Read More

Why do Lua arrays (tables) start at 1 instead of 0?

Mukul Latiyan
Mukul Latiyan
Updated on 11-Mar-2026 2K+ Views

Yes, the arrays in Lua start with index 1 as the first index and not index 0 as you might have seen in most of the programming languages.ExampleConsider the example shown below −arr = {10, 11, 12, 13, 14} print(arr[0]) print(arr[1])In the above example, we are printing the values at indices 0 and 1, and by default, the value at the 0 index will be nil, as in Lua, the arrays start indexing from 1, not 0.Outputnil 10So, now we know that the arrays are 1-index based not 0-index based. But, wait, why 1-index and 0-index?Actually, there have been several ...

Read More

Why does Lua have no "continue" statement?

Mukul Latiyan
Mukul Latiyan
Updated on 11-Mar-2026 5K+ Views

There’s no continue statement in Lua, and it’s not because the developers of the Lua programming language felt that it is of no use, in fact, in the official documentation they mentioned “continue was only one of a number of possible new control flow mechanisms”. This clearly shows that the developers of the Lua programming language aren’t a huge fan of the “continue” statement.If we need to break it down the fact that why Lua developers doesn’t wanted a “continue” statement, then it comes down to two possible answers, these are −They think that the “continue” statement is just another ...

Read More

Lexical Conventions in Lua Programming

Mukul Latiyan
Mukul Latiyan
Updated on 11-Mar-2026 485 Views

In this article, we will learn how to declare and write different lexical conventions in Lua programming.In Lua, we call NAMES as IDENTIFIERS and they can be any string of letters, digits, and underscored, and they should not begin with a digit.Let’s consider an example of different Identifiers in Lua and see which ones are valid and which aren’t.ExampleConsider the example shown below −i = 10 print(i) j1 = 11 print(j1) _ij = 99 print(_ij) aVeryLongName = "Tutorials point" print(aVeryLongName)In the above example, all the variables (Identifiers) are valid, as they either start with letters, digits, or ...

Read More

math.ceil() function in Lua programming

Mukul Latiyan
Mukul Latiyan
Updated on 11-Mar-2026 7K+ Views

There are several occurrences when we want to get the ceil value of an integer to round it off and then use that value later on.The Ceiling value of a number is the value that is rounded to the closest integer greater than or equal to that integer.Lua provides us with a math.ceil() function that we can use to find the ceil value of a number.ExampleLet’s consider a simple example where we will make use of the math.ceil() function in Lua −a = math.ceil(3.3) b = math.ceil(7.1) print(a) print(b)Output4 8ExampleIt should be noted that if we try to find ceil ...

Read More

math.max() function in Lua programming

Mukul Latiyan
Mukul Latiyan
Updated on 11-Mar-2026 10K+ Views

There are several occurrences when we want to get the max value from a given series of numbers and then use that value later on.The Maximum value from the series of different numbers is the value that is the maximum of all the numbers that are present in that series.Lua provides us with a math.max() function that we can use to find the max value out of different numbers that we pass to it as arguments.ExampleLet’s consider a simple example where we will make use of the math.max() function in Lua −a = 10 b = 11 c = 12 ...

Read More

math.min() function in Lua

Mukul Latiyan
Mukul Latiyan
Updated on 11-Mar-2026 8K+ Views

There are several occurrences when we want to get the min value from a given series of numbers and then use that value later on.The Minimum value from the series of different numbers is the value that is the minimum of all the numbers that are present in that series.Lua provides us with a math.min() function that we can use to find the min value out of different numbers that we pass to it as an argument.ExampleLet’s consider a simple example where we will make use of the math.min() function in Lua −a = 10 b = 11 c = ...

Read More
Showing 1–10 of 52 articles
« Prev 1 2 3 4 5 6 Next »
Advertisements