From 4534fb5269069ead0e4a3ccb4498580bc406f861 Mon Sep 17 00:00:00 2001 From: Cloud Wu Date: Mon, 25 Jan 2021 20:31:04 +0800 Subject: [PATCH] pcall execute_module, #1331 --- lualib/skynet/require.lua | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/lualib/skynet/require.lua b/lualib/skynet/require.lua index b4ec9dd8..b902af13 100644 --- a/lualib/skynet/require.lua +++ b/lualib/skynet/require.lua @@ -62,19 +62,24 @@ do context[co] = init_list -- We should call modfunc in lua, because modfunc may yield by calling M.require recursive. - local m = modfunc(name, filename) + local function execute_module() + local m = modfunc(name, filename) - for _, f in ipairs(init_list) do - f() + for _, f in ipairs(init_list) do + f() + end + + if m == nil then + m = true + end + + loaded[name] = m end + + local ok, err = xpcall(execute_module, debug.traceback) + context[co] = old_init_list - if m == nil then - m = true - end - - package.loaded[name] = m - local waiting = #loading_queue if waiting > 0 then local skynet = require "skynet" @@ -84,7 +89,11 @@ do end loading[name] = nil - return m + if ok then + return loaded[name] + else + error(err) + end end end