preface
In the previous chapter, we introduced the past and present lives of lua. Although we didn't see many small partners, we didn't recommend it, and there was no traffic; Most people think there is no nutrition. In fact, I personally don't think so: "if you like a language, do you need to understand the origin of the language; why did the author create the language? What pain diseases have been solved? Its own advantages and past experience?". At least it's not easy to understand the past of Lua language by translating foreign languages.
Popular languages such as Java, Go and Python are very popular. Of course, I like them very much. However, I will insist on using my spare time to record and practice articles about lua.
Lua language supports the following systems
- Windows
- Linux
- Mac OS
Download address of linux Installation Package: lua development package download address
Download address of windows installation package: windows development package download address
Lua officially recommends the following methods: http://luadist.org/
Lua development package installation
1. Install on Mac
➜ Desktop mkdir luadir -- Create one on the desktop lua Installation package folder ➜ Desktop cd luadir ➜ luadir curl -R -O http://www.lua.org/ftp/lua-5.4.3.tar.gz % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 349k 100 349k 0 0 35654 0 0:00:10 0:00:10 --:--:-- 48646 ➜ luadir tar zxf lua-5.4.3.tar.gz ➜ luadir cd lua-5.4.3 ➜ lua-5.4.3 make macosx test /Library/Developer/CommandLineTools/usr/bin/make all SYSCFLAGS="-DLUA_USE_MACOSX -DLUA_USE_READLINE" SYSLIBS="-lreadline" gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c -o lapi.o lapi.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c lcode.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c -o lctype.o lctype.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c -o ldebug.o ldebug.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c -o ldo.o ldo.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c -o ldump.o ldump.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c -o lfunc.o lfunc.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c -o lgc.o lgc.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c llex.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c -o lmem.o lmem.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c -o lobject.o lobject.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c -o lopcodes.o lopcodes.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c lparser.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c -o lstate.o lstate.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c -o lstring.o lstring.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c -o ltable.o ltable.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c -o ltm.o ltm.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c -o lundump.o lundump.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c -o lvm.o lvm.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c -o lzio.o lzio.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c -o lauxlib.o lauxlib.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c -o lbaselib.o lbaselib.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c -o lcorolib.o lcorolib.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c -o ldblib.o ldblib.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c -o liolib.o liolib.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c -o lmathlib.o lmathlib.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c -o loadlib.o loadlib.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c -o loslib.o loslib.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c -o lstrlib.o lstrlib.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c -o ltablib.o ltablib.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c -o lutf8lib.o lutf8lib.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c -o linit.o linit.c ar rcu liblua.a lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o lundump.o lvm.o lzio.o lauxlib.o lbaselib.o lcorolib.o ldblib.o liolib.o lmathlib.o loadlib.o loslib.o lstrlib.o ltablib.o lutf8lib.o linit.o ranlib liblua.a gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c -o lua.o lua.c gcc -std=gnu99 -o lua lua.o liblua.a -lm -lreadline gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_MACOSX -DLUA_USE_READLINE -c -o luac.o luac.c gcc -std=gnu99 -o luac luac.o liblua.a -lm -lreadline ./lua -v Lua 5.4.3 Copyright (C) 1994-2021 Lua.org, PUC-Rio ### Install ok ### You need sudo ➜ lua-5.4.3 sudo make install Password: cd src && mkdir -p /usr/local/bin /usr/local/include /usr/local/lib /usr/local/man/man1 /usr/local/share/lua/5.4 /usr/local/lib/lua/5.4 cd src && install -p -m 0755 lua luac /usr/local/bin cd src && install -p -m 0644 lua.h luaconf.h lualib.h lauxlib.h lua.hpp /usr/local/include cd src && install -p -m 0644 liblua.a /usr/local/lib cd doc && install -p -m 0644 lua.1 luac.1 /usr/local/man/man1 ### After the installation is successful, let's check our lua version number ➜ lua-5.4.3 lua -v Lua 5.4.3 Copyright (C) 1994-2021 Lua.org, PUC-Rio ### Version number before installation ➜ ~ lua -v Lua 5.3.5 Copyright (C) 1994-2018 Lua.org, PUC-Rio
mac terminal can also install lua through homebrew:
### The installation process is omitted here brew install lua
2. Installation on Linux Centos terminal
### View native lua version [root@localhost ~]# lua -v Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio ### Download the latest version of lua installation package [root@localhost ~]# curl -R -O http://www.lua.org/ftp/lua-5.4.3.tar.gz % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 349k 100 349k 0 0 18443 0 0:00:19 0:00:19 --:--:-- 10397 ### Unzip the installation package [root@localhost ~]# tar zxf lua-5.4.3.tar.gz ### Switch to the installation package directory [root@localhost ~]# cd lua-5.4.3 ### Testing the compilation results can detect the errors omitted in the previous make compilation steps and ensure the normal compilation of services [root@localhost lua-5.4.3]# make linux test make[1]: Entering directory `/root/lua-5.4.3/src' make all SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -ldl" make[2]: Entering directory `/root/lua-5.4.3/src' gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -c -o lapi.o lapi.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -c lcode.c gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -c -o lctype.o lctype.c ...........................Omit the compilation process................................................ gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -c -o lua.o lua.c gcc -std=gnu99 -o lua lua.o liblua.a -lm -Wl,-E -ldl gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -c -o luac.o luac.c gcc -std=gnu99 -o luac luac.o liblua.a -lm -Wl,-E -ldl make[2]: Leaving directory `/root/lua-5.4.3/src' make[1]: Leaving directory `/root/lua-5.4.3/src' make[1]: Entering directory `/root/lua-5.4.3/src' ./lua -v Lua 5.4.3 Copyright (C) 1994-2021 Lua.org, PUC-Rio ### Compile ok make[1]: Leaving directory `/root/lua-5.4.3/src' ### install [root@localhost lua-5.4.3]# make install cd src && mkdir -p /usr/local/bin /usr/local/include /usr/local/lib /usr/local/man/man1 /usr/local/share/lua/5.4 /usr/local/lib/lua/5.4 cd src && install -p -m 0755 lua luac /usr/local/bin cd src && install -p -m 0644 lua.h luaconf.h lualib.h lauxlib.h lua.hpp /usr/local/include cd src && install -p -m 0644 liblua.a /usr/local/lib cd doc && install -p -m 0644 lua.1 luac.1 /usr/local/man/man1
If the following problems occur:
cd src && mkdir -p /usr/local/bin /usr/local/include /usr/local/lib /usr/local/man/man1 /usr/local/share/lua/5.4 /usr/local/lib/lua/5.4 mkdir: cannot create directory '/usr/local/man/man1': File exists make: *** [install] Error 1 ## explain Obviously, the existing folder cannot be created during installation. We can delete the existing folder and continue make install
3. Installing Lua on Window system
① go github Upper: https://github.com/rjpcomputing/luaforwindows/releases download the corresponding version of lua installation package ② Unzip to D:\5.1 ③ Configure environment variables(Look at the picture below) ④ input Windows+R —–> cmd —-> lua ⑤ Verify that the installation was successful(Look at the picture below) C:\Users\amumu>lua Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio
Configure environment variables:
Verify successful installation:
Lua language development editor selection
1. IDEA editor tool (take mac computer as an example)
Recommend a very easy-to-use Baiquan MAC software download website: https://www.macwk.com/soft/intellij-idea
Official website (for charging partners): https://www.jetbrains.com/idea/
After the installation is successful, the opening is purple:
LUA code prompt plug-in address: https://github.com/EmmyLua/IntelliJ-EmmyLua
2. VSCode editor tool (Visual Studio Code)
Microsoft's product, a tool running on Mac OS, Windows and Linux, has powerful functions. There are countless Lua language plug-ins. It can also support intelligent prompt, compilation and operation and other functions.
Official download address: https://code.visualstudio.com/
After successful installation, you can choose to install plug-ins that you think are good:
Then quickly write a lua script to run:
local tonumber = tonumber -- Define a table array local _table = {'hello everyone!', 'I am amu children's shoes!', 'You can search WeChat official account:', 'I'm amu', ';Friends can pay attention to me!'} -- Cyclic iteration local text = '' for i,v in ipairs(_table) do text = text..v end print(text) ### hello everyone! I am amu children's shoes! You can search WeChat official account: I am Mu Mu. Friends can pay attention to me!
"Terminal" - > new terminal in VSCode, execute Lua hello The Lua command directly runs hello Lua script, the result is as follows:
3. Sublime Text editor tool
This sublime editor has been used in writing php and py languages before. It can be regarded as an artifact editor. All kinds of fancy style highlight plug-ins are just like it or can't put it down. The official can try it for free, but you can also find the cracked version on Baidu and Google.
Official download address (it seems that you need to go over the wall): https://www.sublimetext.com/
Official website of Chinese version:[ https://sublimetextcn.com/3/][https://sublimetextcn.com/3/]
After successful installation; Install Package Control plug-in tool center:
-
1. Press "command + shift + p" on the keyboard to call up the command input box
-
2. Enter install Package Control and press enter
-
3. After successful installation, the window will pop up and click OK
-
4. Use {command + shift + p again. Enter Install Package in the input box (wait for the link for the first time, a few seconds). After success, the input box will appear again, and then enter the plug-in you want to install. Select and enter to install the plug-in.
Write a lua script and execute it to see the result:
-- Cyclic iteration local text = 'I hope my friends will pay more attention to ah Mu: Thank you for writing the code so well and paying attention to me!' print(text) ### I hope my friends will pay more attention to ah Mu: Thank you for writing the code so well and paying attention to me! ### command + B runs as shown in the figure below
Now, the Lua language development environment is set up!
4. Write our first lua script program (from the full love of our guys) 💗 💗 💗)
--- From the Internet C Written in English --- lua The version is as follows function show_love() local i, j, k, l, m local text = '' -- Leave 5 lines at the beginning for i=1,5 do text = text .. "\n" end -- There is a gap in the middle of the first three lines to write separately for i = 1, 3, 1 do -- The space on the left of each next line is 2 8 less than that on the previous line*n-2*i for j = 1, 32-2*i do text = text.." " end -- Output small characters in the left half for k = 1, 4 * i + 1 do text = text.."*" end -- The space in the middle is 4 less than the space in the previous line for l=1, 13-4*i do text = text.." " end -- Output small characters in the right half for m=1,4*i+1 do text = text.."*" end -- Line wrap after output of each line text = text.."\n" end -- There is no space in the middle of the next three lines for i = 1, 3 do -- Left space 8*(n-1)+1 for j=1,24+1 do text = text.." " end -- Output character little love for k = 1, 29 do text = text.."*" end -- Line wrap after output of each line text = text.."\n" end -- Next 7 lines for i=7, 1, -1 do -- The space on the left of each next line is 2 8 less than that on the previous line*(n+1)-2*i for j=1,40-2*i do text = text.." " end -- Each line of love is smaller than the next 4 characters for k=1, 4*i-1 do text = text.."*" end -- Line wrap after output of each line text = text.."\n" end -- The space to the left of the last line for i=1,39 do text = text.." " end -- Last character little love text = text.."*\n" -- Finally, leave 5 lines blank for i=1,5 do text = text.."\n" end return text end print(show_love())
The effect is as follows
***** ***** ********* ********* ************* ************* ***************************** ***************************** ***************************** *************************** *********************** ******************* *************** *********** ******* *** *
summary
This chapter is very simple. Let's introduce the installation of lua under linux, mac and windows; As well as the installation of three commonly used editors and Lua plug-ins to help us develop quickly. If you have any questions, you can leave a message!
Finally, welcome to my official account, "I am ammu", and will update the knowledge and learning notes from time to time. Also welcome direct official account or personal mail or email to contact me. We can learn together and make progress together. The article is first launched on WeChat official account.
Well, I'm a mu. Thank you for writing the code so well and paying attention to me! ⛽ ️ ⛽ ️ ⛽ ️