diff options
author | kwolekr <kwolekr@minetest.net> | 2015-08-11 22:27:54 -0400 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2015-08-12 23:56:12 -0400 |
commit | 2b04ab874d75711bc021a0cd8dc7fca68f4e6929 (patch) | |
tree | 04c1e9ad914c8c744cfd1055e2a8f6620d924c8b /builtin/game/register.lua | |
parent | 738fbc66d096575bb9a1694056ce2d627a70c03d (diff) | |
download | minetest-2b04ab874d75711bc021a0cd8dc7fca68f4e6929.tar.gz minetest-2b04ab874d75711bc021a0cd8dc7fca68f4e6929.tar.bz2 minetest-2b04ab874d75711bc021a0cd8dc7fca68f4e6929.zip |
SAPI: Track last executed mod and include in error messages
Diffstat (limited to 'builtin/game/register.lua')
-rw-r--r-- | builtin/game/register.lua | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/builtin/game/register.lua b/builtin/game/register.lua index 3a13abfb3..d0e04bfc3 100644 --- a/builtin/game/register.lua +++ b/builtin/game/register.lua @@ -72,6 +72,7 @@ end function core.register_abm(spec) -- Add to core.registered_abms core.registered_abms[#core.registered_abms+1] = spec + spec.mod_origin = core.get_current_modname() or "??" end function core.register_entity(name, prototype) @@ -86,6 +87,7 @@ function core.register_entity(name, prototype) -- Add to core.registered_entities core.registered_entities[name] = prototype + prototype.mod_origin = core.get_current_modname() or "??" end function core.register_item(name, itemdef) @@ -147,6 +149,8 @@ function core.register_item(name, itemdef) end -- END Legacy stuff + itemdef.mod_origin = core.get_current_modname() or "??" + -- Disable all further modifications getmetatable(itemdef).__newindex = {} @@ -326,6 +330,8 @@ function core.override_item(name, redefinition) end +core.callback_origins = {} + function core.run_callbacks(callbacks, mode, ...) assert(type(callbacks) == "table") local cb_len = #callbacks @@ -338,6 +344,14 @@ function core.run_callbacks(callbacks, mode, ...) end 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) + --print("Running " .. tostring(callbacks[i]) .. + -- " (a " .. origin.name .. " callback in " .. origin.mod .. ")") + else + --print("No data associated with callback") + end local cb_ret = callbacks[i](...) if mode == 0 and i == 1 then @@ -370,13 +384,29 @@ end local function make_registration() local t = {} - local registerfunc = function(func) table.insert(t, func) end + local registerfunc = function(func) + table.insert(t, func) + core.callback_origins[func] = { + mod = core.get_current_modname() or "??", + name = debug.getinfo(1, "n").name or "??" + } + --local origin = core.callback_origins[func] + --print(origin.name .. ": " .. origin.mod .. " registering cbk " .. tostring(func)) + end return t, registerfunc end local function make_registration_reverse() local t = {} - local registerfunc = function(func) table.insert(t, 1, func) end + local registerfunc = function(func) + table.insert(t, 1, func) + core.callback_origins[func] = { + mod = core.get_current_modname() or "??", + name = debug.getinfo(1, "n").name or "??" + } + --local origin = core.callback_origins[func] + --print(origin.name .. ": " .. origin.mod .. " registering cbk " .. tostring(func)) + end return t, registerfunc end @@ -408,6 +438,7 @@ local function make_registration_wrap(reg_fn_name, clear_fn_name) end core.registered_on_player_hpchanges = { modifiers = { }, loggers = { } } + function core.registered_on_player_hpchange(player, hp_change) local last = false for i = #core.registered_on_player_hpchanges.modifiers, 1, -1 do @@ -427,12 +458,17 @@ function core.registered_on_player_hpchange(player, hp_change) end return hp_change end + function core.register_on_player_hpchange(func, modifier) if modifier then table.insert(core.registered_on_player_hpchanges.modifiers, func) else table.insert(core.registered_on_player_hpchanges.loggers, func) end + core.callback_origins[func] = { + mod = core.get_current_modname() or "??", + name = debug.getinfo(1, "n").name or "??" + } end core.registered_biomes = make_registration_wrap("register_biome", "clear_registered_biomes") |