From e6a950c30a3fed3d72213836cddb65dac0491ac0 Mon Sep 17 00:00:00 2001 From: tour Date: Sun, 17 Mar 2024 14:01:05 +0100 Subject: [PATCH] crash in case of invalid api usage --- api.lua | 8 ++++++++ internal.lua | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/api.lua b/api.lua index 1ad2bde..8d6313f 100644 --- a/api.lua +++ b/api.lua @@ -5,8 +5,16 @@ areas.registered_on_adds = {} areas.registered_on_removes = {} areas.registered_on_moves = {} +areas.callback_origins = {} + function areas:registerProtectionCondition(func) table.insert(areas.registered_protection_conditions, func) + local debug_info = debug.getinfo(func, "S") + areas.callback_origins[func] = { + mod = core.get_current_modname() or "??", + source = debug_info.short_src or "??", + line = debug_info.linedefined or "??" + } end function areas:registerOnAdd(func) diff --git a/internal.lua b/internal.lua index c4e8db8..a9e16fa 100644 --- a/internal.lua +++ b/internal.lua @@ -222,6 +222,11 @@ function areas:canPlayerAddArea(pos1, pos2, name) allowed = false -- save the first error that occurred errMsg = errMsg or msg + elseif res ~= nil then + local origin = areas.callback_origins[areas.registered_protection_conditions[i]] + error("\n[Mod] areas: Invalid api usage from mod '" .. + origin.mod .. "' in callback registerProtectionCondition() at " .. + origin.source .. ":" .. origin.line) end end