1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
local fs = require 'bee.filesystem'
local extensionPath = fs.path(os.getenv 'USERPROFILE') / '.vscode' / 'extensions'
log.debug('Search extensions at:', extensionPath:string())
if not fs.is_directory(extensionPath) then
log.debug('Extension path is not a directory.')
return
end
local luaDebugs = {}
for path in extensionPath:list_directory() do
if fs.is_directory(path) then
local name = path:filename():string()
if name:find('actboy168.lua-debug-', 1, true) then
luaDebugs[#luaDebugs+1] = name
end
end
end
if #luaDebugs == 0 then
log.debug('Cant find "actboy168.lua-debug"')
return
end
local function getVer(filename)
local a, b, c = filename:match('(%d+)%.(%d+)%.(%d+)$')
if not a then
return 0
end
return a * 1000000 + b * 1000 + c
end
table.sort(luaDebugs, function (a, b)
return getVer(a) > getVer(b)
end)
local debugPath = extensionPath / luaDebugs[1]
local cpath = "/runtime/win64/lua54/?.dll"
local path = "/script/?.lua"
package.cpath = package.cpath .. ';' .. debugPath:string() .. cpath
local function tryDebugger()
local rdebug = require "remotedebug"
local entry = package.searchpath('start_debug', debugPath:string() .. path)
local root = debugPath:string()
local pid = "11411"
local addr = ("@%s/runtime/tmp/pid_%s.tmp"):format(root, pid)
local dbg = loadfile(entry)(rdebug, root, path, cpath)
debug.getregistry()["lua-debug"] = dbg
dbg:start(addr, true)
log.debug('Debugger startup, listen port:', pid)
log.debug('Args:', addr, rdebug, root, path, cpath)
end
xpcall(tryDebugger, log.debug)
|