macOS lua debug 环境搭建避坑指南

安装 lua5.3

坑1:lua5.4 与 mobdebug 存在兼容性问题

不能使用 lua5.4,lua5.4现在对 mobdebug 兼容有问题。

# 如果使用 brew install lua ,会自动安装最新版本
brew install lua@5.3
brew link lua@5.3

# 此时会自动link,进行下一步之前,先检查一下lua环境是不是ok了

安装 luarocks

参考:https://ttys3.dev/post/lua/luarocks-install-and-setup/

坑2:brew install luarocks 安装版本不对

不能使用 brew install luarocks ,他会自己安装基于 lua5.4 的 luarocks。

官方安装文档:https://github.com/luarocks/luarocks/wiki/Installation-instructions-for-Unix

# 下载
wget https://luarocks.org/releases/luarocks-3.7.0.tar.gz
tar zxpf luarocks-3.7.0.tar.gz

坑3:官方文档指令不能直接使用

官方文档说应该用 ./configure --with-lua-include=/usr/local/include ,但实际不能加 --with-lua-include=/usr/local/include ,这会导致 lua 依赖的路径错误。
可能会产生类似 Failed finding Lua header files. You may need to install them or configure LUA_INCDIR 的错误。

出现这种错误的原因还是 --with-lua-include=/usr/local/include 后边跟的这个路径不对,在我的环境中,应该为 --with-lua-include=/usr/local/opt/lua@5.3/include/lua5.3

在不指定这个参数的时候,会自动检测路径,未来避免出错,最好还是不要指定,除非系统里装了多版本的 lua 。

cd luarocks-3.7.0
./configure

此时会提示:

* Type make and make install:
  to install to /usr/local as usual.
* Type make bootstrap:
  to install LuaRocks into /usr/local as a rock.

让我们在 make && make installmake bootstrap 之间选择,此处推荐 make bootstrap

make bootstrap

安装 luacheck、luasocket

坑4:rock tree 与安装 scope

在上一步安装完之后,会有类似以下输出:

Configuration:
   Lua:
      Version    : 5.3
      Interpreter: /usr/local/bin/lua5.3 (ok)
      LUA_DIR    : /usr/local (ok)
      LUA_BINDIR : /usr/local/bin (ok)
      LUA_INCDIR : /usr/local/opt/lua@5.3/include/lua5.3 (ok)
      LUA_LIBDIR : /usr/local/opt/lua@5.3/lib (ok)

   Configuration files:
      System  : /usr/local/etc/luarocks/config-5.3.lua (ok)
      User    : /Users/eric/.luarocks/config-5.3.lua (ok)
      Project : /tmp/luarocks-3.7.0/./.luarocks/config-5.3.lua (ok)

   Rocks trees in use:
      /tmp/luarocks-3.7.0/./lua_modules ("project")
      /Users/eric/.luarocks ("user")
      /usr/local ("system")

其中:

  • Lua 指出 lua 依赖相关路径
  • Configuration files 指出了配置文件路径
  • Rocks trees in use 指出了安装 lua_modules 时的目标根路径,后边括号里的 "project""user""system" ,是指不同的 scope,使用 luarocks install xxx 时应该格外注意安装的 scope 是否正确。

像上边这个输出显示,project scope 是在 /tmp 下的一个路径,所以如果安装到这里的话,项目目录可能就找不到包。

这里应该格外注意的是:Rocks trees 是一个树状结构,这里边显示的是根路径,真实的安装目录应该是 Rocks treeslib_modules_path 拼起来。

system scope 为例,
运行指令 luarocks ,获得以下输出:

➜  luarocks
……
……
……
Rocks trees in use:
      /Users/eric/.luarocks ("user")
      /usr/local ("system")

可知,luarockssystem scope 中的 Rocks tree 路径为 /usr/local

运行 luarocks config --scope user lib_modules_path ,获得以下输出:

➜ luarocks config --scope user lib_modules_path
/lib/lua/5.3/

可知,luarockssystem scope 中的lib_modules_path/lib/lua/5.3/

此时如果要安装到 system scope ,这会安装到 /usr/local/lib/lua/5.3/

运行 lua -e 'require "abc"' ,获得以下输出:

lua: (command line):1: module 'abc' not found:
	no field package.preload['abc']
	no file '/usr/local/share/lua/5.3/abc.lua'
	no file '/usr/local/share/lua/5.3/abc/init.lua'
	no file '/usr/local/lib/lua/5.3/abc.lua'
	no file '/usr/local/lib/lua/5.3/abc/init.lua'
	no file './abc.lua'
	no file './abc/init.lua'
	no file '/usr/local/lib/lua/5.3/abc.so'
	no file '/usr/local/lib/lua/5.3/loadall.so'
	no file './abc.so'

上面输出的这些路径就是 lua 查找 package 时会检索的目录,应该保证 Rocks treelib_modules_path 拼接后的路径可以被 lua 检索到。

如果 lib_modules_path 路径不对,可以通过下面的指令进行配置:

luarocks config --scope user lib_modules_path /lib/lua/5.3/

一切就绪,安装 luacheckluasocket

luarocks install luacheck
luarocks install luasocket

运行 lua -e 'require "socket"' ,如果没有报错,说明安装成功。

使用 EmmyLua MobDebug 进行 debug

基本所有的 Lua debug 工具都基于 MobDebug ,像 EmmyLuaLuaPanda

IDEA 系列 IDE 推荐使用 EmmyLua ,vscode 编辑器推荐使用 LuaPanda

IDEA 中的 EmmyLua 插件已经集成了 MobDebug 。

使用 EmmyLua 中的 MobDebug 的方式,EmmyLua的文档里有很简略说明,
详见: https://emmylua.github.io/run.html#get-ready

step.1. 目录结构

➜ tree
.
└── src
    ├── dev1.lua
    └── mobdebug.lua

需要将 src 标为 Sources(源 根),显示为蓝色。

https://github.com/pkulchenko/MobDebug 下载 MobDebug 项目,
MobDebug/src/mobdebug.lua 放到项目 src 目录面。

在这里插入图片描述

step.2. 创建运行配置

在这里插入图片描述

step.3. 创建 debug 配置

在这里插入图片描述

step.4. 进行debug

先点击 debug按钮 运行 Lua Remote(MobDebug)效果如下图

在这里插入图片描述

再点击运行按钮运行 dev1.lua,成功进入 debug 模式
在这里插入图片描述

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
为了在 macOS 上搭建 PHP 开发环境,你可以按照以下步骤进行操作: 1. 安装 Homebrew:Homebrew 是 macOS 上一个常用的包管理器。打开终端并输入以下命令安装 Homebrew: ``` /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` 2. 安装 PHP:使用 Homebrew 安装 PHP。在终端中输入以下命令: ``` brew install php ``` 3. 配置 PHP:默认情况下,Homebrew 会将 PHP 安装在 `/usr/local/etc/php` 目录下。你可以根据需要进行配置更改。 4. 安装一个 Web 服务器:你可以选择安装 Apache 或 Nginx 作为 Web 服务器。下面是安装 Apache 的步骤: - 安装 Apache: ``` brew install httpd ``` - 配置 Apache:编辑 `/usr/local/etc/httpd/httpd.conf` 文件进行必要的配置更改,如修改网站根目录等。 - 启动 Apache: ``` sudo apachectl start ``` - 在浏览器中输入 `http://localhost`,如果看到 "It works!" 的页面,则说明 Apache 已经成功安装并运行。 5. 安装数据库:如果你需要使用数据库,可以选择安装 MySQL 或 PostgreSQL。使用以下命令安装 MySQL: ``` brew install mysql ``` - 启动 MySQL: ``` brew services start mysql ``` - 设置 MySQL 根密码: ``` mysql_secure_installation ``` 6. 安装开发工具:你可以选择安装一个集成开发环境(IDE)或文本编辑器,如 Visual Studio Code、PhpStorm、Sublime Text 等。 这样,你的 macOS PHP 开发环境就搭建完成了。你可以在配置文件中进行进一步的定制和调整,以适应你的开发需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值