crash in case of invalid api usage
This commit is contained in:
parent
e237bf0e22
commit
e6a950c30a
8
api.lua
8
api.lua
|
@ -5,8 +5,16 @@ areas.registered_on_adds = {}
|
||||||
areas.registered_on_removes = {}
|
areas.registered_on_removes = {}
|
||||||
areas.registered_on_moves = {}
|
areas.registered_on_moves = {}
|
||||||
|
|
||||||
|
areas.callback_origins = {}
|
||||||
|
|
||||||
function areas:registerProtectionCondition(func)
|
function areas:registerProtectionCondition(func)
|
||||||
table.insert(areas.registered_protection_conditions, 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
|
end
|
||||||
|
|
||||||
function areas:registerOnAdd(func)
|
function areas:registerOnAdd(func)
|
||||||
|
|
|
@ -222,6 +222,11 @@ function areas:canPlayerAddArea(pos1, pos2, name)
|
||||||
allowed = false
|
allowed = false
|
||||||
-- save the first error that occurred
|
-- save the first error that occurred
|
||||||
errMsg = errMsg or msg
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue