- 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
Found 82 Articles for Lua
15K+ Views
Comments are a set of commands that are ignored by the compiler. They are used in a scenario where you want to attach a note to your code or a section of code so that when you visit it later, you can recall it easily. The comment statements are usually ignored during the execution of the program.There are two types of comments in Lua −Single-line commentsMulti-line commentsMulti-line comments are also known as block comments in Lua.Single-Line CommentA single-line comment in Lua starts with a double hyphen (--) and runs until the end of the line.Syntax-- this is a commentLet’s consider ... Read More
467 Views
The break statement is used when we want to break or terminate the execution of a loop. Once the break statement is reached, the control is transferred from the current loop to whatever is written after the loop. This statement breaks the inner loop (for, repeat, or while) that contains it; it cannot be used outside a loop. After the break, the program continues running from the point immediately after the broken loop.A break statement is mostly used in conditional statements and also in loops of all types. It is present in almost all popular programming languages.SyntaxbreakNow, let’s consider a ... Read More
4K+ Views
A function is a group of statements that together perform a task. You can divide up your code into separate functions.Functions help in reducing the code redundancy and at the same time they make the code much more readable and less error prone.In Lua, we declare functions with the help of the function keyword and then, we can invoke(call) the functions just by writing a pair of parentheses followed by the functions name.ExampleConsider the example shown below − Live Demofunction add(a, b) -- declaring the function return a + b end result = add(1, 2) -- calling the function print(result) ... Read More
1K+ Views
We can create standalone Lua executables with the help of the third party packages like srlua.srlua does a perfect job in converting a Lua script file into an executable, and we can do it on both the major platforms, whether that is the windows or the Unix based systems.Let’s first learn how to do it on a Windows system.Consider the steps mentioned below as a reference −First, visit the github link of the srlua project. Please click the following link. After that, you need to clone the repository on your local windows machine with this command −git clone https://github.com/LuaDist/srlua.gitIt should ... Read More
558 Views
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 More
3K+ Views
Lua does the implicit conversion or also known as coercion when it notices that you are trying to use a number but wrote a string, then it automatically converts the string into an int, and it is quite useful.Let’s consider a simple example where I will declare a string variable, and then I will try to do an arithmetic operation on it, then once the Lua compiler infers that we are trying to use the string as an int, it will automatically convert it into an int.ExampleConsider the example shown below − Live Demostr = "10" print(type(str)) num = 2 * ... Read More
397 Views
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 More
3K+ Views
When working with JSON we generally need to decode JSON into a string or maybe encode a string into JSON. Both of these processes of converting the string into a JSON or the opposite are seen frequently.While Lua doesn’t provide an official library to do the same, we can still make use of the third party libraries.There are many third party libraries that we can make use of, out of these the most common one is the json-lua library which can be located on this link.We can either clone the repository on our local machine and then install it or ... Read More
2K+ Views
We know that Lua does a great job when it comes to being a simple language and an embedded language. Lua works even better with C, because of the different libraries that provide a great amount of support for it.In order to compile embedded Lua in C, we need to first write a Lua program followed by a C program that will invoke the Lua program function, and then we will compile the C program.Consider the program shown below as the Lua program −print("--I am using Lua from within C--")It should be noted that the above Lua script should be ... Read More
513 Views
While there are different ways with which a person can compile a Lua executable, some of them require more time and resources.The most basic approach is to set the Lua Path environment variable and then simply run the lua command. While this might seem to be not much of a pain, setting the Lua Path definitely requires some work.Instead of setting the Lua path, we can simply make use of the env and lua combination which will allow us to convert a Lua file into an executable or run a Lua script.The command shown below does the same −#!/USR/BIN/ENV LUAIn ... Read More