actboy168 / lua-debug

Lua Debug Adapter for Visual Studio Code
MIT License
435 stars 94 forks source link

coroutine 调试需要怎么改才行的呀? #146

Closed car520120 closed 2 years ago

car520120 commented 2 years ago

下面是兼容 zbstudio 的,如果想使用 lua-debug 需要怎么改这个地方的呀?

local oldLuaLoader = package.searchers[2]
local function luaLoader(mod)
    local func, path = oldLuaLoader(mod)
    if not path then
        return func
    end
    local func2 = function()
        if mobdebug then
            mobdebug.on()
        end
        local func3 = func()
        if mobdebug then
            mobdebug.off()
        end
        return func3
    end
    if string.sub(path, 1, 1) == "@" then
        path = string.sub(path, 2)
    end
    local ft = filelist[mod]
    local oldCo = ft and ft.load
    local oldLT = localTable
    if oldCo then
        localTable = {}
        for i = 1, 999 do
            local k, v = debug.getlocal(oldCo, 1, i)
            if not k then
                break
            end
            localTable[k] = v
        end
    else
        localTable = nil
    end
    local co = coroutine.create(func2)
    local ok1, ok2, ret = pcall(coroutine.resume, co, mod, path)
    localTable = oldLT
    if not ok1 then
        error(traceback(co, ok2), 0)
    end
    if not ok2 then
        error(traceback(co, ret), 0)
    end
    if coroutine.status(co)=="dead" then
        co = nil
    end
    filelist[mod] = {
        path = path,
        time = lfs.attributes(path, "modification"),
        load = co,
    }
    return function() return ret end, path
end

package.searchers[2] = luaLoader
actboy168 commented 2 years ago

https://github.com/actboy168/lua-debug/blob/master/docs/ported.md