scripting language, you probably need Lua more.
Different scripting languages have different characteristics, and the first-contact scripting language may affect your understanding of the entire scripting language. The scripting language I used to touch most was JavaScript. The result: I once thought that scripting languages must be run in different processes from the host language; The syntax of the script itself is greatly influenced by the environment, and it is difficult to unify; If you want to unify your writing, you need to make a very large compromise on the application volume (embedding a generic JS interpreter will increase the application volume by more than 10 M).
I'm trying to make some effort to improve some of the specific technical issues that arise from the extensive use of JavaScript. But there was a chance to think of Lua again. At first, I heard about Lua from the roommate who played WOW. Because he said to write Wow plugin very lucrative, so once carefully searched for Lua, now there are some remnants of the brain fragments.
I suddenly realized that most of the limitations of JavaScript might not exist in Lua or other scripting languages. To solve all the problems caused by using JavaScript, you may need to change the scripting language.
Of course, this does not take into account the usual sense of the use of difficulty, learning difficulty, the promotion of the cost of a class of factors; After all, I am pure self-hi. But if Lua is really good at solving the problem that the scripting language I am encountering is not flexible enough to communicate with the host language, it will bring a new ascension to the whole knowledge system, and it will create many new possibilities in our daily practice.
The versions of the various tools involved
Programming Language: Lua 5.3.4
Lua Module Management tool: Luarocks 2.3.0
Editor: IntelliJ Idea CE (Community edition)
Build #IC -172.4343.14, built on September 26, 2017
JRE:1.8.0_152-RELEASE-915-B12 x86_64
JVM:OPENJDK 64-bit Server VM by JetBrains S.R.O
Mac OS X 10.13.1
Debug Plugin: Emmylua 1.2.0
Operating system: MacOS 10.13.1
MacOS Dedicated Module management tool: Homebrew 1.3.6
The following discussions are based on MacOS, and other system platforms are for informational purposes only.
Installing Lua
Open the MacOS terminal and enter the following command:
install lua53
There are several ways to install Lua, which is a simpler and more efficient one. It is important to note that, in this way, the invoke command of Lua becomes lua5.3
Installing the Lua Module management tool: Luarocks
Open the MacOS terminal and enter the following command:
install luarocks53
There are several ways to install Luarocks, which is a simpler and more efficient one. It is important to note that the Luarocks command, which is installed in this manner, becomes luarocks-5.3
Choose a suitable Lua editor: IntelliJ idea CE
Lua daily coding, recommended use IntelliJ idea CE (Community Free Edition),: https://www.jetbrains.com/idea/download/
Mainly from the configuration difficulty, syntax highlighting, code hints, code debugging and other aspects of trade-offs.
Configuring the Debug environment with the Emmylua plug-in installation Emmylua
The debugging and highlighting of Lua is mainly due to the Emmylua. In the IntelliJ idea CE Plugins, the direct search installation can be. Remember to install this plugin before you create a new project. After installing this plugin, the project template will have one more Lua template option. Creating a new project from the LUA template simplifies many of the LUA-related configurations.
Installing Luasocket
After installing the Emmylua plug-in, you will also need to install a Lua library luasocketfor debugging.
Open the terminal and enter the following command:
sudo luarocks-5.3 install luasocket
Modifying the LUA path configuration
Lua's configuration path is changed from the default Lua to the true path of lua5.3, typically /usr/local/bin/lua5.3
Start debugging
Create a new LUA project in IntelliJ idea CE, then create a new Lua file Hello.lua and enter the code:
--Defines a factorial functionfunction fact (nif n == 0 then return 1 else return n * fact (n -1) end enda = 42print (fact (a /span>
On the left side of the edit area, hit a few breakpoints, then right-click on the file Edit section and select Debug ' Hello.lua ':
A simple look at the Debug breakpoint debugging Effect:
Precautions
It is important to create a new project based on the new Lua template directly after configuring the Emmylua plugin, otherwise it may take a lot of time to modify the project configuration.
UTF-8 is only supported in later versions of Lua, and children's shoes with a large number of Chinese processing requirements may require this information.
Debug times wrong module ' socket ' not found , is because there is no installation of luasocket.
Lua is based on MIT open source, and if one day you want to define a new language to implement specific product features, consider a LUA-based customization.
With the help of Luajit,lua, the execution efficiency can be increased by up to dozens of times times.
Lua supports a variety of low-level hardware embedded development, portability is very good, the era of the Internet of things may have new possibilities and growth potential.
If you feel that lua5.3 is not handy for Lua, try configuring alias command aliases in . profile, as described in: https://stackoverflow.com/a/8967864
alias lua="/usr/local/bin/lua5.3"alias luarocks="/usr/local/bin/luarocks-5.3"
- Command aliases, which cannot be executed by sudo, such as when installing Luasocket, still require sudo raw command:
sudo luarocks-5.3 install Luasocket
Summary
The above describes the MacOS platform, Lua from installation to configuration debugging environment complete process. Next, you can enjoy the beauty of Lua according to your own rhythm and needs.
Reference Documentation:
- How do I set an alias for a command?
- Installing different versions of Lua and luarocks using Hombrew
- Emmylua Plugin Homepage
- Lua website
- Luarocks official website
- IntelliJ Idea website
- Luajit Project homepage
- Homebrew official website
Configuring Lua on MacOS