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
Lua Articles
Page 3 of 6
How 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 MoreHow to use the require function in Lua programming?
Lua offers a high-level function which we can use when we want to load and run libraries. This high-level function is named require function.The require function mainly targets the high level functions and keywords.The require function is a bit similar to the dofile function, but it has two key differences, the first one being that it searches for the file in a specified path and the second one is that it mainly focuses on to control whether the file is already running on the script or not.Syntaxrequire “module-name” // some codeHow Does the require Function Work in Lua?It is mainly ...
Read MoreHow to use the Time package in Lua programming?
Lua library provides us with a time package that can be used to calculate the current time and that current time can be converted into hours, days and minutes and we can also take the later values and turn them into a Lua representation of time.In order to make use of the library time package, we don’t necessarily need to require anything, we just need to write the following command in a Lua script and we are done.Lua code for printing the current time in Lua format −Exampleprint(os.time())Output1624642168The output of the above time command definitely isn’t something that we normally ...
Read MoreInline conditions in Lua (a == b ? “yes” : “no”)
You might have noticed ternary operators in different programming languages, but since there’s no ternary operator in Lua, as per the official documentation, we can create one for ourselves with the help of the Lua operators.Let’s first understand what a ternary operator is and why we need one.ExampleConsider the example shown below, which depicts a simple if else condition in lua.a = 3 b = 4 if a == b then print("blah") else print("nah nah") endOutputnah nahIn the above if else condition, we wrote multiple lines of code and also used many statements that the lua language provides, but what ...
Read More__tostring element in Lua Programming
The _tostring element in Lua receives an argument of any type and converts it to a string in a reasonable format.If the metatable of e has a "__tostring" field, then tostring calls the corresponding value with e as argument, and uses the result of the call as its result.The __tostring element method is a part of the metatables that Lua library provides us and is used to modify the behaviour of the table that we get as an output.The __tostring element method is used to modify the behavior of the output table.Examplecurrtable = setmetatable({ 10, 20, 30 }, { ...
Read MoreDifference between . and : in Lua programming
The .(dot) operator in Lua is used to invoke the method of an object, and it is a widely used operator in Lua.The :(colon) operator in Lua is used when you want to pass an invisible parameter to the method of an object that you are calling.Let’s consider an example where we will have an object in which two functions are present and we will try to access these functions, first by making use of the dot operator and secondly by making use of the colon operator.ExampleConsider the example shown below −returnX = {foo = function(x, y) return x end, ...
Read MoreHow to Convert Perl Compatible Regular Expressions (PCRE) into Lua
A regular expression is a special text string that is used to describe a search pattern.PCRE (Perl Compatible Regular Expressions) is a C library implementing regex. It was written in 1997 when Perl was the de-facto choice for complex text processing tasks. The syntax for patterns used in PCRE closely resembles Perl. If you want to learn about PERL and its use cases, you should visit this link.Now, let's take an example to see how to convert a PCRE into Lua and then print it.ExampleConsider the code shown below −"\002\003\004\005\006\007\008\009\010\011\012\”The above string acts as a PCRE and we will convert ...
Read MoreHow to create a Sandbox in Lua?
In order to create a sandbox and to be able to use it we must first understand what a sandbox is and why we need it. A sandbox is term that is used in different fields of computer science, like in case we are talking about the software testing domain, then a sandbox is a testing environment that isolates untested code changes and outright experimentation from the production environment and if we talk about cybersecurity, then a sandbox is an environment that is an isolated virtual machine in which potentially unsafe software code can execute.Sandboxing is basically all about isolating ...
Read Morestring.sub() function in Lua
Another important function of the Lua’s string library is the string.sub() function. The string.sub() function is used to extract a piece of the string.The string.sub() function takes three arguments in general, the first argument being the name of the string from which we want to extract a piece, the second argument is the i-th index or say, the starting index of the string piece that we want, and the third and the last argument is the j-th index of the last index of the string piece we want.It should be noted that both the starting index and the ending index, ...
Read MoreDifference between Python and Lua
There are many different kinds of application-specific scripting languages, some of which are Emacs LISP, MEL (Maya Embedded Language), AutoLISP, and MaxScript. There are also others that are more flexible and are ideal for the development of high-level applications such as Java, OCaml, C#, and so on. Then there is a category of programming languages known as embedded scripting languages, which were developed in order to provide an easy integration with bigger programmes. They provide programmes with new functionality and link together applications that have a complex relationship. These kinds of scripting languages typically provide substantial support for utility packages ...
Read More