Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles by Mukul Latiyan
Page 2 of 37
select() function in Lua programming
The select function in Lua is used to return the number of arguments that are passed into it as an argument. It can be used in two forms, the first one includes passing an index and then it will return the numbers that are passed after that number into the function as an argument in a list format, the other pattern is if we pass the length operator as a first argument, in that case it simply returns a count of the multiple arguments that are provided.ExampleLet’s explore both the cases in the examples shown below.Case 1print(select(1, "a", "b", "c")) ...
Read MoreSemicolon Conventions in Lua Programming
There are very few sections we will explore the possibility of making use of a semicolon in Lua. Majority of the code doesn’t require it, while there are some cases where we might need them.ExampleLet’s consider a case where the use of semicolon seems necessary. Consider the example shown below −local a, b=10, 20 print(a+b)The above statement in Lua is perfectly valid and it works like a charm.Output30ExampleWhat if we change the code above and put it in the same line? Would it still be a valid Lua code? Let’s try it out. Consider the code shown below −local a, ...
Read Morestring.byte() function in Lua programming
The string.byte() function is one of the most widely used Lua string library functions that takes a character or a string as an argument and then converts that character into its internal numeric representations.The character to internal numeric representations can be easily interpreted from the ASCII table.Syntaxstring.byte(ch) or string.byte(ch, idx)In the above representation of the string.byte() function, the ch identifier represents the character that we want to convert into a decimal value. Also, the idx identifier represents a character at that index of the string passed as an argument.Let’s consider a few examples where we will make use of the ...
Read Morestring.char() function in Lua programming
There are so many scenarios where you might want to convert a decimal value into a character representation. The character representation of a decimal or integer value is nothing but the character value, which one can interpret using the ASCII table.In Lua, to convert a decimal value to its internal character value we make use of the string.char() function.Syntaxstring.char(I)In the above syntax, the identifier I represents the decimal value which we want to convert into a character.ExampleLet’s consider a very simple example, where you are given different decimal values, and you want to convert them to a character value.Consider the ...
Read Morestring.format() function in Lua programming
There are cases when we want to format strings which will help us to print the output in a particular format.When we use the string.format() function it returns a formatted version of its variable number of arguments following the description given by its first argument, the so-called format string.The format string that we get the output, is similar to those of the printf function of standard C: It is composed of regular text and directives, which control where and how each argument must be placed in the formatted string.Syntaxstring.format(“s = %a”)The string.format() syntax above contains an identifier s which is ...
Read Morestring.lower() function in Lua programming
There are certain scenarios in our code that when we are working with the strings, we might want some string to be in lowercase, like consider a very basic case of an API which is using an authentication service, and the password for that authentication service should in lowercase, and in that case, we need to convert whatever the password the user enters into lowercase.Converting a string to its lowercase in Lua is done by the string.lower() function.Syntaxstring.lower(s)In the above syntax, the identifier s denotes the string which we are trying to convert into its lowercase.ExampleLet’s consider a very simple ...
Read Morestring.upper() function in Lua programming
There are certain scenarios in our code that when we are working with the strings, we might want some string to be in uppercase, like consider a very basic and yet famous example of such scenario, the PAN number.Imagine that you are making a web form in which there’s a field for the PAN number of the user, and since you know that PAN number can’t be in lowercases, we need to take the user input of that field and convert the string into its uppercase.Converting a string to its uppercase in Lua is done by the string.upper() function.Syntaxstring.upper(s)In the ...
Read MoreHow to remove Lua table entry by its key?
Let’s consider an example where we would like to remove a Lua table entry. The table itself behaves like a hashmap, where it has several key value pairs, and we would like to remove an entry from that table on the basis of the key.Lua library does provide a function that we can use for our specific case. The function is table.remove() and it takes two arguments, the first argument is the name of the table and the second argument is the key that we want to remove.ExampleConsider the example shown below −local mapone = { [1] = 10, [2] ...
Read MoreHow to use the Insert function in Lua Programming?
There are cases when we want to insert elements into a table. In Lua, the table library provides functions to insert elements into the table.The insert function usually takes two arguments, the first argument is usually the name of the table from which we want to insert the element to, and the second argument is the element that we want to insert.If there are three arguments passed to the insert function then the second argument denotes the position in the table where we want to insert the element at.Let’s explore different examples of the insert function.Syntaxinsert(x, element) or insert(x, pos, ...
Read MoreHow to Use the Remove function in Lua programming?
There are cases when we want to remove an element from a table. In Lua, the table library provides functions to remove elements from the table.The remove function usually takes two arguments, the first argument is usually the name of the table from which we want to remove the element from, and the second argument is the position from which we want to remove the element from.Let’s explore different examples of the remove function.Syntaxtable.remove(x, pos)The x in the above example denotes the name of the table from which we want to remove the element from, and the pos identifier in ...
Read More