This is the 13th day of my participation in the August More Text Challenge.More challenges in August

0 portal

Lua programming series will be explained in the near future, from the most basic entry, to master, actual combat, nanny level tutorials. This is Lua’s first post, here are the portals that will continue to output…

  • 01 Lua Data Type to be a Script Master
  • 01 Lua operator 01 Lua operator
  • Stay tuned for

1 the Lua profile

Lua is a small scripting language developed in 1993 by a research team at the Catholic University of Rio de Janeiro, Brazil.

Written in standard C and open source, Lua can be compiled and run on almost any operating system and platform. Lua scripts can call C/C++ functions and can be called by C/C++ code, so Lua is widely used in applications.

Lua does not provide a powerful library because of its positioning. So Lua is not a good language for developing standalone applications. It is designed to provide flexible extension and customization capabilities for applications through flexible embedding.

Lua is small and fast to start up. A complete Lua interpreter is only 200K, making Lua the fastest of all scripting engines. So Lua is the best choice for embedded scripts. That’s why we need to learn Lua.

So what does Lua do? In fact, it is mainly used as a scripting language to develop scripts, such as writing auxiliary scripts for games, using Lua scripts in Redis, etc.

Lua official website: www.lua.org/

2 the Lua features

  • Lightweight: Lua is written in the standard C language. The official version of Lua consists of a compact core and basic libraries. It is small and fast to start up.

  • Extensible: Lua provides very easy-to-use extension interfaces and mechanisms that are provided by the host language (usually C or C++) and can be used by Lua as if they were already built in.

  • Other features:

    • Support for procedure-oriented programming and functional programming;
    • Automatic memory management;
    • Provides only a general type of table (table), but can be used to implement arrays, hash tables, collections, objects;
    • Closures. Closures and tables make it easy to support some of the key mechanisms needed for object-oriented programming, such as data abstraction, virtual functions, inheritance, and overloading. ;
    • Multithreading (collaborative processes, not threads supported by the operating system) support;

3 Application Scenarios

  • Game development, such as game auxiliary scripts.
  • Application scripts, such as Redis using Lua scripts.
  • Database plug-ins such as MySQL Proxy and MySQL WorkBench.
  • Security systems, such as intrusion detection systems.

4 Environment Installation

The latest version of Lua is Lua 5.4.3. It can be downloaded on the official website: www.lua.org/download.ht…

The Windows installation package can be downloaded at Github: github.com/rjpcomputin…

4.1 Installation on Linux

To install Lua on Linux, download the package, decompress it, and compile it.

# download package curl -r -o http://www.lua.org/ftp/lua-5.4.3.tar.gz # extract tar ZXVF lua - 5.4.3. Tar. Gz # # into extract catalog CD lua - 5.4.3 compilation Make Linux test # installCopy the code

Then we can open the Lua interactive program, use Lua’s print statements, and verify and experience the first program.

[root@chenpi 5.4]# lua-I Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, Puc-rio > print("Hello JavaLib")Copy the code

You can also create a new Lua script file, such as chenpi. Lua, and open the file to write the following code.

Print ("Hello JavaLib")Copy the code

Run the following command to execute the Lua script.

[root@chenpi 5.4]# Lua chenpi. Lua Hello Orange peel JavaLib [root@chenpi 5.4]#Copy the code

It is also possible to execute a Lua script as an executable file. The first line explains which interpreter is used to execute the Lua script:

#! /usr/local/bin/lua print "Hello JavaLib"Copy the code

Then grant executable permissions to the file, and execute.

[root@chenpi 5.4]# chmod +x chenpi.lua [root@chenpi 5.4]#./chenpi.lua Hello JavaLib [root@chenpi 5.4]#Copy the code

4.2 Windows Installation

Download the zip package and unzip it to the directory we want to install.

After decompression, double-click lua5.1.exe in the files directory to open the interactive window as follows:

And in the SciTE directory, the SciTE. Exe program is an editor that can edit Lua code.

I am Chen PI, an ITer in Internet Coding. Search “Chen PI’s JavaLib” in wechat to read the latest articles in the first time oh!

This is the end of sharing ~~

If you find the article helpful, like, favorites, follow, comment on yours