-
-
Save est31/e84180467a76f8badb42 to your computer and use it in GitHub Desktop.
Lua error reporting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/builtin/game/register.lua b/builtin/game/register.lua | |
index d0e04bf..002c8b2 100644 | |
--- a/builtin/game/register.lua | |
+++ b/builtin/game/register.lua | |
@@ -10,6 +10,21 @@ core.register_item_raw = nil | |
local register_alias_raw = core.register_alias_raw | |
core.register_alias_raw = nil | |
+local function make_func_safe(func) | |
+ return function(...) | |
+ local arg = {...} | |
+ local worked, result = xpcall(function () return func(unpack(arg)) end, | |
+ function(err) | |
+ return debug.traceback(err, 1) | |
+ end) | |
+ if worked then | |
+ return result | |
+ else | |
+ print(result) | |
+ assert(false) -- still error, so that we can be sure we fail | |
+ end | |
+ end | |
+end | |
+ | |
-- | |
-- Item / entity / ABM registration functions | |
-- | |
@@ -154,6 +169,11 @@ function core.register_item(name, itemdef) | |
-- Disable all further modifications | |
getmetatable(itemdef).__newindex = {} | |
+ for idx, obj in pairs(itemdef) do | |
+ if type(obj) == "function" then | |
+ itemdef[idx] = make_func_safe(obj) | |
+ end | |
+ end | |
--core.log("Registering item: " .. itemdef.name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment