Skip to content

Commit

Permalink
Fix Minetest blaming the wrong mod for errors (minetest#12241)
Browse files Browse the repository at this point in the history
Covers the case where mods insert their callbacks manually into "minetest.registered_<callbacks>" (often to achieve a particular order of execution).
  • Loading branch information
appgurueu committed May 9, 2022
1 parent 53c70b5 commit 089797d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
1 change: 0 additions & 1 deletion builtin/client/register.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

core.callback_origins = {}

local getinfo = debug.getinfo
Expand Down
4 changes: 1 addition & 3 deletions builtin/game/item.lua
Original file line number Diff line number Diff line change
Expand Up @@ -529,9 +529,7 @@ function core.node_dig(pos, node, digger)
-- Run script hook
for _, callback in ipairs(core.registered_on_dignodes) do
local origin = core.callback_origins[callback]
if origin then
core.set_last_run_mod(origin.mod)
end
core.set_last_run_mod(origin.mod)

-- Copy pos and node because callback can modify them
local pos_copy = vector.new(pos)
Expand Down
14 changes: 9 additions & 5 deletions builtin/game/register.lua
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,14 @@ function core.override_item(name, redefinition)
register_item_raw(item)
end


core.callback_origins = {}
do
local default = {mod = "??", name = "??"}
core.callback_origins = setmetatable({}, {
__index = function()
return default
end
})
end

function core.run_callbacks(callbacks, mode, ...)
assert(type(callbacks) == "table")
Expand All @@ -419,9 +425,7 @@ function core.run_callbacks(callbacks, mode, ...)
local ret = nil
for i = 1, cb_len do
local origin = core.callback_origins[callbacks[i]]
if origin then
core.set_last_run_mod(origin.mod)
end
core.set_last_run_mod(origin.mod)
local cb_ret = callbacks[i](...)

if mode == 0 and i == 1 then
Expand Down

0 comments on commit 089797d

Please sign in to comment.