summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorANAND <ClobberXD@gmail.com>2019-04-28 15:12:20 +0530
committersfan5 <sfan5@live.de>2019-05-04 12:56:19 +0200
commit72feab081c336d2d71d300131d30e71694b485f3 (patch)
treee3c202863ab57011831de81fec82d14b65c85acb /builtin
parent96f250ed8f5b019904bb67c427fe5c1babf0f4df (diff)
downloadminetest-72feab081c336d2d71d300131d30e71694b485f3.tar.gz
minetest-72feab081c336d2d71d300131d30e71694b485f3.tar.bz2
minetest-72feab081c336d2d71d300131d30e71694b485f3.zip
builtin/../register.lua: Abort make_wrap_deregistration if param is invalid
Diffstat (limited to 'builtin')
-rw-r--r--builtin/game/register.lua13
1 files changed, 10 insertions, 3 deletions
diff --git a/builtin/game/register.lua b/builtin/game/register.lua
index 3edab0471..d111e5c27 100644
--- a/builtin/game/register.lua
+++ b/builtin/game/register.lua
@@ -514,11 +514,17 @@ local function make_registration_wrap(reg_fn_name, clear_fn_name)
end
local function make_wrap_deregistration(reg_fn, clear_fn, list)
- local unregister = function (unregistered_key)
+ local unregister = function (key)
+ if type(key) ~= "string" then
+ error("key is not a string", 2)
+ end
+ if not list[key] then
+ error("Attempt to unregister non-existent element - '" .. key .. "'", 2)
+ end
local temporary_list = table.copy(list)
clear_fn()
for k,v in pairs(temporary_list) do
- if unregistered_key ~= k then
+ if key ~= k then
reg_fn(v)
end
end
@@ -564,7 +570,8 @@ core.registered_biomes = make_registration_wrap("register_biome", "cle
core.registered_ores = make_registration_wrap("register_ore", "clear_registered_ores")
core.registered_decorations = make_registration_wrap("register_decoration", "clear_registered_decorations")
-core.unregister_biome = make_wrap_deregistration(core.register_biome, core.clear_registered_biomes, core.registered_biomes)
+core.unregister_biome = make_wrap_deregistration(core.register_biome,
+ core.clear_registered_biomes, core.registered_biomes)
core.registered_on_chat_messages, core.register_on_chat_message = make_registration()
core.registered_globalsteps, core.register_globalstep = make_registration()