Skip to content

Commit c98e63d

Browse files
committed
add debugger
1 parent 9362db1 commit c98e63d

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

resources/debugger.lua

+66-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,66 @@
1-
-- empty file
1+
if not DEVELOP then
2+
return
3+
end
4+
5+
local fs = require 'bee.filesystem'
6+
local luaDebugs = {}
7+
8+
local home = os.getenv 'USERPROFILE' or os.getenv 'HOME'
9+
if not home then
10+
log.error('Cannot find home directory')
11+
return
12+
end
13+
for _, vscodePath in ipairs { '.vscode', '.vscode-insiders', '.vscode-server-insiders' } do
14+
local extensionPath = fs.path(home) / vscodePath / 'extensions'
15+
log.debug('Search extensions at:', extensionPath:string())
16+
17+
if fs.exists(extensionPath) then
18+
for path in fs.pairs(extensionPath) do
19+
if fs.is_directory(path) then
20+
local name = path:filename():string()
21+
if name:find('actboy168.lua-debug-', 1, true) then
22+
luaDebugs[#luaDebugs+1] = path:string()
23+
end
24+
end
25+
end
26+
end
27+
end
28+
29+
if #luaDebugs == 0 then
30+
log.debug('Cant find "actboy168.lua-debug"')
31+
return
32+
end
33+
34+
local function getVer(filename)
35+
local a, b, c = filename:match('actboy168%.lua%-debug%-(%d+)%.(%d+)%.(%d+)')
36+
if not a then
37+
return 0
38+
end
39+
return a * 1000000 + b * 1000 + c
40+
end
41+
42+
table.sort(luaDebugs, function (a, b)
43+
return getVer(a) > getVer(b)
44+
end)
45+
46+
local debugPath = luaDebugs[1]
47+
local cpath = "/runtime/win64/lua54/?.dll;/runtime/win64/lua54/?.so"
48+
local path = "/script/?.lua"
49+
50+
local function tryDebugger()
51+
local entry = assert(package.searchpath('debugger', debugPath .. path))
52+
local root = debugPath
53+
local addr = ("127.0.0.1:%d"):format(DBGPORT)
54+
local dbg = loadfile(entry)(entry)
55+
dbg:start {
56+
address = addr,
57+
}
58+
log.debug('Debugger startup, listen port:', DBGPORT)
59+
log.debug('Debugger args:', addr, root, path, cpath)
60+
if DBGWAIT then
61+
dbg:event('wait')
62+
end
63+
return dbg
64+
end
65+
66+
xpcall(tryDebugger, log.debug)

0 commit comments

Comments
 (0)