+3 votes
1.1k views
How to install Lua on Linux or Windows 10

in Linux / Unix by (552k points)
reopened | 1.1k views

1 Answer

+4 votes
Best answer

1. How to install Lua on Linux
2. How to install LUA on Windows 10
3. LUA functions

The use of scripts is a current way of executing automated tasks which result in better administrative processes and better time control. But it is true that to execute various scripts it is necessary to have the best tools for this that provide functions and features such as:

  • Security
  • Easy to use
  • Compatibility between operating systems
  • File extensions
  • Multiple file support and more.
In this case one of the best alternatives to use is LUA and that is why today TechnoWikis will explain what it is and how to install LUA on Linux and Windows systems to have a great application for the execution and administration of scripts.
What is LUA?
Lua is a scripting language available for free because it is open source that has advantages thanks to its powerful, robust and easy integration with both systems and applications.

When using LUA we have a tool that supports procedural programming, object-oriented programming, functional programming, data-based programming and more with which the execution options are wide and we will not be limited by it..

When we implement Lua, it combines simple procedure syntax with versatile data description constructs which in turn are based on associative matrices and extensible semantics.

LUA is executed when interpreting bytecode with a virtual machine based on registration and has automatic memory management through which it will be possible to carry out configuration tasks, creating scripts and much more.

LUA features
If we choose to use LUA, we will have the following features:
  • Lua is a proven and robust language which has an emphasis on integrated systems and games as it is the leading scripting language in games.
  • Lua is one of the fastest applications today, and has been listed as one of the best applications, in terms of speed, of interpreted scripting languages.
  • It is portable, it is portable since Lua is distributed in a lightweight package and is built for all platforms that have a standard C compiler. Lua works on all Unix and Windows distributions, on mobile devices with Android, iOS, BREW, Symbian, Windows Phone and on integrated microprocessors such as ARM and Rabbit and many more.
  • It can be embeddable, this thanks to the fact that LUA has a simple API which allows a strong integration with code written in other languages ​​such as C #, Smalltalk, Fortran, Ada, Erlang and other scripting languages, such as Perl and Ruby.
  • Of great functionalities since it has a set of features directly in its own language, for example, it provides meta-mechanisms to implement classes and inheritance in object-oriented programming.
  • It is light, this implies that LUA has a size of 297 KB compressed and 1.2 MB uncompressed, its source contains about 24000 C lines and in 64-bit Linux environments, the Lua interpreter created with all the standard Lua libraries has a size of 247 KB and the Lua library of 421 KB.
  • It is free to be free code

1. How to install Lua on Linux


There are different mechanisms for installing LUA on Linux, the available options are:
Install LUA from the repositories on Linux

The Lua package is available in the official repositories of the main Linux distributions, so that we can install the latest version using the package manager according to the distribution used as follows:
Debian and Ubuntu
 sudo apt install lua5.3 
RHEL / CentOS
 yum install epel-release && yum install lua 
Fedora
 dnf install lua 
image
Install LUA from the source on Linux

The current version of the Lua package in the EPEL repository is 5.1.4, so to purchase this version, it must be compiled and installed from the source.

First, we will install the development tools using the following command:

Debian / Ubuntu
 sudo apt install build-essential libreadline-dev 
RHEL / CentOS
 yum groupinstall "Development Tools" readline 
Fedora
 dnf groupinstall "Development Tools" readline 

Enter the letter Y to confirm the download and installation of these tools..

image

Now, to compile and install the latest version which is version 5.3.4 of Lua, we will execute the following commands in order to download the tar ball package, extract it, compile it and install it:

 mkdir lua_build cd lua_build curl -R -O http://www.lua.org/ftp/lua-5.3.4.tar.gz tar -zxf lua-5.3.4.tar.gz cd lua-5.3.4 make linux test sudo make install 
image

Once installed, we will run the Lua interpreter with the following line:

 lua 
image

Once active, we will create a small program to check the use of LUA, for this we will use some text editor, in this case nano, and execute the following:

 sudo nano solvetic.lua 
In the created file we will paste the following:
 Print ("Hello TechnoWikis") Print ("TechnoWikis test document") 
image

We save the changes using the following key combination:

+ O Ctrl + O

We left the editor using the keys;

+ X Ctrl + X

.
Now, let's run the file created as follows:

 lua solvetic.lua 
image

There we see the content of our created file.


2. How to install LUA on Windows 10

Step 1

In the case of Windows 10, the first step is to download the binaries in the following link:
LUA

Now, we will create a root folder where all the LUA configuration will be hosted, in this case on the following path:

 C: \ Users \ TechnoWikis \ Documents \ LUA 
There, we will create another folder for the created projects:

image

Step 2

We open the downloaded tablet and its contents we select and extract it in the LUA folder we have created:

image

Step 3

They can be dragged directly or use the "Extract in" option:

image

Step 4

We access the subfolder "Projects" and there we will create a text file with the name of the project to be executed and it must contain the extension .lua, for this we go to the View menu of the file explorer and check the box "File name extensions ", when editing the extension we will see the following message. Click on the "Yes" button to confirm the action

image

Step 5

We will see the file created:

image

Step 6

Now we will open this file with some text editor, preferably Notepad ++, and there we enter the following:
 print ("TechnoWikis Internet") print ("LUA Windows 10 Validation") 
We save the changes created.

image

Step 7

To execute the code created, we access the command prompt and go to the root folder of LUA using the cd command, and once there we will enter the lua53 line which refers to the LUA executable and followed the path where the file is located. lua, in this case Projects / solvetic.lua, press "Enter" and we will see that the contents of the file are displayed: image

3. LUA functions


We have seen the basic use of LUA in both Linux and Windows 10, but LUA goes far beyond this exercise and some of its most useful functions are:
Call the error if the value of argument v is false (i.e. null or false)
 assert (v [, message]) 
This function is a standard interface for the garbage collector, it performs different functions according to the first argument, opt as collect, stop, restart, step, etc.
 collectgarbage ([opt [, arg]]) 
Open the selected file and run its contents as a fragment of Lua.
 dofile ([file]) 
The last protected function that was called ends and returns the message as the error object.
 error (message [, level]) 
It is a global variable, not a function, which contains the global environment.
 _G 
If the selected object does not have a metatable, it returns nil, otherwise, if the object's metatable has a __metatable field, it returns the associated value.
 getmetatable (object) 
Returns three values ​​(an iterator function, table t and 0)
 ipairs (t) 
Allows a program to access all fields in a table
 next (table [, index]) 
If t contains a __pairs metamethod, call it with t as an argument and return the first three results of the call
 pairs (t) 
Receive any number of arguments and print their values ​​in stdout
 print (···) 

To know in detail all the arguments available to LUA, we can visit the following official link:

LUA

Thus, LUA becomes a complete solution for all work related to scripts that can be used simply in both Linux and Windows 10.


by (3.5m points)
edited

Related questions

+4 votes
1 answer
+3 votes
1 answer
+5 votes
1 answer
+4 votes
1 answer
asked Jan 31, 2020 in Linux / Unix by backtothefuture (552k points) | 5.9k views
+5 votes
1 answer
Sponsored articles cost $40 per post. You can contact us via Feedback

Most popular questions within the last 30 days

10,659 questions
10,791 answers
510 comments
3 users