summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
Diffstat (limited to 'server/src')
-rw-r--r--server/src/vm/vm.lua21
1 files changed, 11 insertions, 10 deletions
diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua
index 26fcc84a..ac642056 100644
--- a/server/src/vm/vm.lua
+++ b/server/src/vm/vm.lua
@@ -1150,15 +1150,7 @@ function mt:remove()
self.sources = nil
end
-local function compile(ast, lsp, uri)
- local vm = setmetatable({
- funcs = {},
- sources = {},
- main = nil,
- env = nil,
- lsp = lsp,
- uri = uri or '',
- }, mt)
+local function compile(vm, ast, lsp, uri)
-- 创建初始环境
ast.uri = vm.uri
@@ -1175,8 +1167,17 @@ return function (ast, lsp, uri)
if not ast then
return nil
end
- local suc, res = xpcall(compile, log.error, ast, lsp, uri)
+ local vm = setmetatable({
+ funcs = {},
+ sources = {},
+ main = nil,
+ env = nil,
+ lsp = lsp,
+ uri = uri or '',
+ }, mt)
+ local suc, res = xpcall(compile, log.error, vm, ast, lsp, uri)
if not suc then
+ vm:remove()
return nil, res
end
return res