unity搭建xlua和emmy_lua的debug环境

4 篇文章 0 订阅

配置步骤

1 环境

1.1 vscode 安装emmy_lua

1.2 安装对应的lua版本

1.3 安装java8并配置环境

1.4 emmy_lua的github上下载emmy_lua的64位版本,解压放到工程目录client\Tools\EmmyLua\

下载地址:https://github.com/EmmyLua/EmmyLuaDebugger/releasesicon-default.png?t=M85Bhttps://github.com/EmmyLua/EmmyLuaDebugger/releases

结构如下

client

——Assets

——Tools\EmmyLua

——EasyHook.dll

——emmy_core.dll

——emmy_hook.dll

2 程序启动时执行下面的代码

local function split(line, sep, maxsplit)
    if string.len(line) == 0 then
        return {}
    end
    sep = sep or " "
    maxsplit = maxsplit or 0
    local retval = {}
    local pos = 1
    local step = 0
    while true do
        local from, to = string.find(line, sep, pos, true)
        step = step + 1
        if (maxsplit ~= 0 and step > maxsplit) or not from then
            local item = string.sub(line, pos)
            table.insert(retval, item)
            break
        else
            local item = string.sub(line, pos, from - 1)
            table.insert(retval, item)
            pos = to + 1
        end
    end
    return retval
end

--连接EmmyLua
local function connectEmmyLua()
    local func = function()
        local assets = CS.UnityEngine.Application.dataPath
        local assetDict = split(assets, "/")
        local path = ''
        for i = 1, #assetDict-1 do
            path = path .. assetDict[i] .. '/'
        end
        package.cpath = package.cpath .. ';' .. path .. 'Tools/EmmyLua/emmy_core.dll'
        local dbg = require('emmy_core')
        dbg.tcpConnect('localhost', 9966)
    end
 
    local handle = function(error)
        print('IDE没有开启调试', error)
    end
 
    xpcall(func, handle)
end

3 配置debug使用的launch.json

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "emmylua_new",
            "request": "launch",
            "name": "EmmyLua New Debug",
            "host": "localhost",
            "port": 9966,
            "ext": [
                ".lua",
                ".lua.txt",
                ".lua.bytes",
                ".txt"
            ],
            "ideConnectDebugger": false
        },
    ]
}

4 如果是xlua,修改自定义的LuaLoader

这里有个坑,比如lua中require("game.xxx.XX")

在自定义loader中,public byte[] CustomLoader(ref string luaPath)

luaPath则为game.xxx.XX

如果不对这个luaPath做什么,emmylua的断点无法生效,也不会报错,就什么也不发生,简单查阅emmylua插件的源码,没找到关联到lua源码的代码

后来使用breakHere方法,强制进到一个lua断点,但是报错"无法加载源",看不到源码。

local dbg = require('emmy_core')
dbg.tcpConnect('localhost', 8866)
dbg.breakHere()

我猜是不是xlua那边传给emmylua的路径不对呢?

如果想让emmylua断点后可以找到文件需要重新赋值这个luaPath为真实的文件路径

luaPath = GetRealPath(luaPath)

解决问题

5 vscode启动debug

6 设置断点后运行游戏

参考资料

VSCode使用EmmyLua调试Lua代码_HKW_hankangwen的博客-CSDN博客_emmylua vscode

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值