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
下面是兼容 zbstudio 的,如果想使用 lua-debug 需要怎么改这个地方的呀?