Skip to content

Commit 7ac81bc

Browse files
committed
去掉重复代码
1 parent 6545e99 commit 7ac81bc

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

extension/script/debugger.lua

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ if not selfsource then
88
end
99
end
1010

11+
local IsWindows = package.config:sub(1, 1) == "\\"
1112
local root = selfsource
12-
:match "(.+)[/][^/]+$"
13-
:match "(.+)[/][^/]+$"
13+
:match "(.+)[/][^/]+$"
14+
:match "(.+)[/][^/]+$"
1415

1516
if debug.getregistry()["lua-debug"] then
1617
local dbg = debug.getregistry()["lua-debug"]
@@ -47,9 +48,6 @@ end
4748

4849
local function detectLuaDebugPath(cfg)
4950
local PLATFORM
50-
local function isWindows()
51-
return package.config:sub(1, 1) == "\\"
52-
end
5351
do
5452
local function shell(command)
5553
--NOTICE: io.popen可能会多线程不安全
@@ -93,7 +91,7 @@ local function detectLuaDebugPath(cfg)
9391
error "unknown ARCH"
9492
end
9593
end
96-
if isWindows() then
94+
if IsWindows then
9795
detect_windows()
9896
else
9997
local name = shell 'uname -s'
@@ -133,7 +131,7 @@ local function detectLuaDebugPath(cfg)
133131
error(_VERSION.." is not supported.")
134132
end
135133

136-
local ext = isWindows() and "dll" or "so"
134+
local ext = IsWindows and "dll" or "so"
137135
return root..rt..'/luadebug.'..ext
138136
end
139137

@@ -148,8 +146,7 @@ local function initDebugger(dbg, cfg)
148146
luadebug = detectLuaDebugPath(cfg)
149147
updateenv = true
150148
end
151-
local isWindows = package.config:sub(1, 1) == "\\"
152-
if isWindows then
149+
if IsWindows then
153150
assert(package.loadlib(luadebug, 'init'))(cfg.luaapi)
154151
end
155152

@@ -163,7 +160,7 @@ local function initDebugger(dbg, cfg)
163160
end
164161

165162
local function utf8(s)
166-
if cfg.ansi and isWindows then
163+
if cfg.ansi and IsWindows then
167164
return dbg.rdebug.a2u(s)
168165
end
169166
return s
@@ -208,7 +205,7 @@ function dbg:event(...)
208205
end
209206

210207
function dbg:set_wait(name, f)
211-
_G[name] = function(...)
208+
_G[name] = function (...)
212209
_G[name] = nil
213210
f(...)
214211
self:event 'wait'
@@ -221,7 +218,7 @@ function dbg:setup_patch()
221218
local rawxpcall = xpcall
222219
function pcall(f, ...)
223220
return rawxpcall(f,
224-
function(msg)
221+
function (msg)
225222
self:event("exception", msg, ERREVENT_ERRRUN, 3)
226223
return msg
227224
end,
@@ -230,7 +227,7 @@ function dbg:setup_patch()
230227

231228
function xpcall(f, msgh, ...)
232229
return rawxpcall(f,
233-
function(msg)
230+
function (msg)
234231
self:event("exception", msg, ERREVENT_ERRRUN, 3)
235232
return msgh and msgh(msg) or msg
236233
end
@@ -251,7 +248,7 @@ function dbg:setup_patch()
251248
function coroutine.wrap(f)
252249
local wf = rawcoroutinewrap(f)
253250
local _, co = debug.getupvalue(wf, 1)
254-
return function(...)
251+
return function (...)
255252
self:event("thread", co, 0)
256253
return coreturn(co, wf(...))
257254
end

0 commit comments

Comments
 (0)