C++调用Lua如何调试lua代码呢,可以使用 mobdebug.lua + ZeroBrane Studio 进行调试
0x00:工具下载
mobdebug.lua 项目地址:https://github.com/pkulchenko/MobDebug
ZeroBrane Studio 项目地址:https://github.com/pkulchenko/ZeroBraneStudio
ZeroBrane Studio 官网地址:https://studio.zerobrane.com/
在官网上找到对应的操作系统版本下载
0x01:实例操作
C++代码
#include "lua.hpp" int main() { lua_State *L = luaL_newstate(); luaL_openlibs(L); luaopen_debug(L); luaL_dofile(L,"a.lua"); lua_pcall(L,0,0,0); lua_close(L); return 0; }
通过C++代码调用a.lua,输出“hello world”
a.lua
require('mobdebug').start() function hello(l) print("hello world") end hello(1);
代码很简单,只要在需要调试的lua文件上加上require(‘mobdebug’).start()这行代码。并且将 mobdebug.lua 文件,放到lua代码目录下,如下图:
打开ZeroBrane Studio,将lua代码目录设置成project,在需要调试的地方打上断点。
在Project菜单,选择 Start Debugger Server即可。
然后直接执行C++代码;触发断点会在ZeroBrane中显示,就是这么简单
主要窗口就是 Stack和Watch窗口,一个显示调用栈,一个用来查看当前变量的值信息。
通过调整 require(‘mobdebug’).start(‘192.168.1.110’) 的IP参数OR端口,可实现调试嵌入移动端的Lua
如何使用 ZeroBrane Studio 调试嵌入式 Lua