Skip to content

Commit d1f3f97

Browse files
committed
compact
1 parent 893e5be commit d1f3f97

File tree

8 files changed

+969
-888
lines changed

8 files changed

+969
-888
lines changed

resources/luajitCompact.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,28 @@ table.unpack = unpack
33
table.pack = function(...)
44
return { n = select('#', ...), ... }
55
end
6+
7+
function defer(toBeClosed, callback)
8+
local ctype = type(toBeClosed)
9+
if ctype == 'table' then
10+
local meta = getmetatable(toBeClosed)
11+
if meta and meta.__close then
12+
local ok, result = xpcall(callback, log.error)
13+
meta.__close(toBeClosed)
14+
if ok then
15+
return result
16+
end
17+
else
18+
local ok, result = xpcall(callback, log.error)
19+
if ok then
20+
return result
21+
end
22+
end
23+
elseif ctype == 'function' then
24+
local ok, result = xpcall(callback, log.error)
25+
toBeClosed()
26+
if ok then
27+
return result
28+
end
29+
end
30+
end

resources/override_script/await.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ function m.await(callback, ...)
7373
end
7474
return m.wait(function(resume, ...)
7575
m.call(function()
76-
resume(callback())
76+
local returnNil = resume
77+
defer(returnNil, function ()
78+
resume(callback())
79+
end)
7780
end, ...)
7881
end, ...)
7982
end

resources/override_script/files.lua

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -695,33 +695,34 @@ function m.compileState(uri)
695695
log.error('Client not ready!', uri)
696696
end
697697
local prog = progress.create(uri, lang.script.WINDOW_COMPILING, 0.5)
698-
prog:setMessage(ws.getRelativePath(uri))
699-
log.trace('Compile State:', uri)
700-
local clock = os.clock()
701-
local state, err = parser.compile(file.text
702-
, 'Lua'
703-
, config.get(uri, 'Lua.runtime.version')
704-
, options
705-
)
706-
local passed = os.clock() - clock
707-
if passed > 0.1 then
708-
log.warn(('Compile [%s] takes [%.3f] sec, size [%.3f] kb.'):format(uri, passed, #file.text / 1000))
709-
end
710-
711-
if not state then
712-
log.error('Compile failed:', uri, err)
713-
return nil
714-
end
698+
return defer(prog, function()
699+
prog:setMessage(ws.getRelativePath(uri))
700+
log.trace('Compile State:', uri)
701+
local clock = os.clock()
702+
local state, err = parser.compile(file.text
703+
, 'Lua'
704+
, config.get(uri, 'Lua.runtime.version')
705+
, options
706+
)
707+
local passed = os.clock() - clock
708+
if passed > 0.1 then
709+
log.warn(('Compile [%s] takes [%.3f] sec, size [%.3f] kb.'):format(uri, passed, #file.text / 1000))
710+
end
715711

716-
state = pluginOnTransformAst(uri, state)
717-
if not state then
718-
log.error('pluginOnTransformAst failed! discard the file state')
719-
return nil
720-
end
712+
if not state then
713+
log.error('Compile failed:', uri, err)
714+
return nil
715+
end
721716

722-
m.compileStateThen(state, file)
717+
state = pluginOnTransformAst(uri, state)
718+
if not state then
719+
log.error('pluginOnTransformAst failed! discard the file state')
720+
return nil
721+
end
723722

724-
return state
723+
m.compileStateThen(state, file)
724+
return state
725+
end)
725726
end
726727

727728
---@class parser.state

resources/override_script/proto/proto.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,11 @@ function m.applyMethod(proto)
199199
m.responseErr(proto.id, proto._closeReason or define.ErrorCodes.InternalError, proto._closeMessage or res)
200200
end
201201
end
202-
ok, res = xpcall(abil, log.error, proto.params, proto.id)
203-
await.delay()
202+
203+
defer(response, function()
204+
ok, res = xpcall(abil, log.error, proto.params, proto.id)
205+
await.delay()
206+
end)
204207
end)
205208
end
206209

0 commit comments

Comments
 (0)