
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
Found 33676 Articles for Programming

494 Views
There are cases where we would like to implement PHP Lua extension in PHP.ini so that we can make use of Lua as an embedding language for our PHP code.It can be done with some series of steps that need to be run in a specific manner and the most important of them is running the --with-lua-version command.The steps for installing Lua in Linux are −pecl download lua cd lua-2.0.7In the steps above we made use of the pecl which stands for PHP extension community library to download lua and then we are relocating to the lua directory. Now, it’s ... Read More

2K+ Views
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. Live Demoa = 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 ... Read More

2K+ Views
Lua provides different libraries that once can be used to work with MySQL. The most popular framework that enables us to work with MySQL in Lua is LuaSQL.LuaSQL is a simple interface from Lua to a DBMS. It enables a Lua program to −Connect to ODBC, ADO, Oracle, MySQL, SQLite, Firebird and PostgreSQL databases;Execute arbitrary SQL statements;Retrieve results in a row-by-row cursor fashion.You can download MySQL with the help of this command −luarocks install luasql-mysqlMySQL DB SetupIn order to use the following examples to work as expected, we need the initial db setup. The assumptions are listed below.You have installed ... Read More

2K+ Views
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 −Example Live Demoprint(os.time())Output1624642168The output of the above time command definitely isn’t something that we ... Read More

13K+ Views
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 More

2K+ Views
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

5K+ Views
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 More

1K+ Views
Lua provides different libraries that can be used to work with MongoDB. The most popular framework that enables us to work with MongoDB in Lua is lua-mongo.Lua-mongo is a binding to MongoDB C Driver for Lua −It provides a Unified API for MongoDB commands, CRUD operations and GridFS in MongoDB C Driver.Transparent conversion from Lua/JSON to BSON for convenience.Automatic conversion of Lua numbers to/from BSON Int32, Int64 and Double types depending on their capacity without precision loss (when Lua allows it). Manual conversion is also available.You can download MongoDB with the help of this command −luarocks install lua-mongoMongoDB SetupIn order ... Read More

3K+ Views
Lua provides us with different functions and methods that we can use when we want to work with files. These methods or functions do different operations, like from opening a file, to closing a file, to opening a file with a specific mode also.While many of these functions that Lua provides to work with files, two of them are more subtle to use and work with.In this article we will explore these two approaches, where in the first approach we will simply open a file by passing the name of the file and the mode in which we want to ... Read More

26K+ Views
Splitting a string is the process in which we pass a regular expression or pattern with which one can split a given string into different parts.In Lua, there is no split function that is present inside the standard library but we can make use of other functions to do the work that normally a split function would do.A very simple example of a split function in Lua is to make use of the gmatch() function and then pass a pattern which we want to separate the string upon.ExampleConsider the example shown below − Live Demolocal example = "lua is great" for ... Read More