安装lua和luarocks

# 通过brew安装lua5.3
brew install lua@5.3

brew link lua@5.3
Linking /opt/homebrew/Cellar/lua@5.3/5.3.6... 17 symlinks created.

# 手动添加环境变量,我这里使用的是zsh,请根据自己情况进行修改
echo 'export PATH="/opt/homebrew/opt/lua@5.3/bin:$PATH"' >> ~/.zshrc

# 安装luarocks
wget https://luarocks.org/releases/luarocks-3.11.0.tar.gz
tar zxpf luarocks-3.11.0.tar.gz
cd luarocks-3.11.0
./configure && make && sudo make install

# 启用默认为本地用户
luarocks config local_by_default true

修改luarocks配置文件

在/Users/yourName/.luarocks/ 建立配置文件 config-5.3.lua
或者直接从系统配置中进行复制 cp /usr/local/etc/luarocks/config-5.3.lua /Users/yourName/.luarocks/
将其文件内容修改如下

此处目的为主要为修改luarocks库的安装位置,将其直接安装到lua的搜索库路径中去
local_by_default = true
rocks_trees = {
   {
      name = "user",
      root = "/opt/homebrew"
   },
   {
      name = "system",
      root = "/opt/homebrew"
   }
}
variables = {
   LUA = "/opt/homebrew/opt/lua@5.3/bin/lua5.3",
   LUA_BINDIR = "/opt/homebrew/opt/lua@5.3/bin",
   LUA_DIR = "/opt/homebrew/opt/lua@5.3",
   LUA_VERSION = "5.3"
}

如何查看当前lua的库搜索路径

写入环境变量后需要重新开启一个终端后才可正常输入lua

image

安装luasocket

luarocks install luasocket

# 当出现下列字样则安装成功
# luasocket 3.1.0-1 is now installed in /opt/homebrew (license: MIT)

验证

image

再次输入 lua -e "require('socket')" 没有报错即为安装成功

本文由mdnice多平台发布


好奇怪o
1 声望1 粉丝