How to configure an elegant Lua Development Environment
Discussion topic
- What is an elegant development environment?
- How to deploy the Service (this article discusses the MacOSX platform, which is also applicable to other platforms)
Elegant Lua Development Environment
The elegant Lua development environment includes at least the following:
- Install the latest stable edition Lua
- Install the appropriate Lua Package Manager (Luarocks is recommended for installation)
- Source code installation (properly organize the installation directory and set environment variables to make the Lua environment easier to use and manage)
Version Selection
First, we should pay attention to the various popular Lua versions (5.1x, 5.2x, 5.3x). How can we choose the latest stable version that suits our needs.
My environment is used for Web Application Development Based on Openresty (Openresty is a derivative version of Nginx and its Http_lua Module). In Openresty, Lua code execution is through LuaJit parsing and acceleration, while LuaJit is developed based on Lua5.1x ABI, Openresty officially states that using LuaJit to run Lua code is the best solution, so there is no doubt that Lua5.1x is the most suitable for me, and the latest stable version is Lua5.1.5.
Installation and deployment
Compared with brew, apt-get, yum, and other installation methods, we recommend that you use the source code for installation. This helps us to have a better understanding and grasp of the details of the entire environment and organize the installation directory reasonably, it is easy to use and manage by setting environment variables.
Download and decompress the Lua source code:
wget http://www.lua.org/ftp/lua-5.1.5.tar.gztar zxvf lua-5.1.5.tar.gzcd lua-5.1.5
Open Makefile and you can see the following information:
PLAT = none # Installation Platform. The default platform is noneINSTALL_TOP =/usr/local # installation and directory. The default value is/usr/local # Convenience platforms targets. # Platform Supported by source code PLATS = aix ansi bsd freebsd generic linux macosx mingw posix solaris
Change INSTALL_TOP to your specified installation directory and save it.
INSTALL_TOP= /usr/local/lua-5.1.5
Follow these steps:
Make macosx # The compilation platform is set to macosx, and other platforms can directly replace macosx, such as make linuxmake macosx install # The Installation Platform is set to macosx
After successful installation:
~/Desktop/ ll /usr/local/lua-5.1.5total 0drwxr-xr-x 4 root wheel 136B 10 19 18:48 bindrwxr-xr-x 7 root wheel 238B 10 19 18:48 includedrwxr-xr-x 4 root wheel 136B 10 19 18:48 libdrwxr-xr-x 3 root wheel 102B 10 19 18:48 mandrwxr-xr-x 3 root wheel 102B 10 19 18:48 share
Runlua -v
View the installed Lua version
~/Desktop/ lua -vzsh: command not found: lua ~/Desktop/ ln -sf /usr/local/lua-5.1.5/bin/lua /usr/local/bin/lua ~/Desktop/ lua -vLua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio
The above installation project is to get a Lua executable file. The elegance lies in the use of source code installation, the organization of the installation directory makes it easier for us to manage the Lua environment, in the future, the ABI and Lua packages related to Lua5.1.5 will be installed inlib,share
Path, we can even defineLUA_PATH=/usr/local/lua-5.1.5
For more convenient referencelua.h
And so on.
Because the specified installation directory/usr/local/lua-5.1.5
It is not in the PATH environment variable, so it is executed directly.lua
Reportcommand not found: lua
Here, we use the method of adding a soft connection to link the executable file to the PATH to achieve the same effect, you can also directly/usr/local/lua-5.1.5/bin
Add to environment variable PATH.
Multi-version coexistence
Multi-version coexistence can be achieved by using the source code installation.
~/Desktop/luarocks-2.2.2/ ll /usr/local/lua*/usr/local/lua:/usr/local/lua-5.1.5:/usr/local/lua-5.2.3:/usr/local/lua-5.3.1: // ll /usr/local/bin/lua*lrwxr-xr-x 1 root admin 28B 10 19 23:16 /usr/local/bin/lua -> /usr/local/lua-5.1.5/bin/lualrwxr-xr-x 1 root admin 28B 10 20 10:08 /usr/local/bin/lua52 -> /usr/local/lua-5.2.3/bin/lualrwxr-xr-x 1 root admin 28B 10 20 10:12 /usr/local/bin/lua53 -> /usr/local/lua-5.3.1/bin/lualrwxr-xr-x 1 root admin 29B 10 20 10:12 /usr/local/bin/luac -> /usr/local/lua-5.1.5/bin/luaclrwxr-xr-x 1 root admin 29B 10 20 10:08 /usr/local/bin/luac52 -> /usr/local/lua-5.2.3/bin/luaclrwxr-xr-x 1 root admin 29B 10 20 10:11 /usr/local/bin/luac53 -> /usr/local/lua-5.3.1/bin/luac
Lua Language 15-minute Quick Start
Lua programming (version 2nd) Chinese PDF
Lua programming (version 2) Reading Notes
NetBSD will support the use of Lua scripts to develop Kernel Components
CentOS compilation and installation of Lua LuaSocket
Programming In Lua PDF
Lua details: click here
Lua's: click here
This article permanently updates the link address: