Skip to content

Commit 72feab0

Browse files
ClobberXDsfan5
authored andcommittedMay 4, 2019
builtin/../register.lua: Abort make_wrap_deregistration if param is invalid
1 parent 96f250e commit 72feab0

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed
 

‎builtin/game/register.lua

+10-3
Original file line numberDiff line numberDiff line change
@@ -514,11 +514,17 @@ local function make_registration_wrap(reg_fn_name, clear_fn_name)
514514
end
515515

516516
local function make_wrap_deregistration(reg_fn, clear_fn, list)
517-
local unregister = function (unregistered_key)
517+
local unregister = function (key)
518+
if type(key) ~= "string" then
519+
error("key is not a string", 2)
520+
end
521+
if not list[key] then
522+
error("Attempt to unregister non-existent element - '" .. key .. "'", 2)
523+
end
518524
local temporary_list = table.copy(list)
519525
clear_fn()
520526
for k,v in pairs(temporary_list) do
521-
if unregistered_key ~= k then
527+
if key ~= k then
522528
reg_fn(v)
523529
end
524530
end
@@ -564,7 +570,8 @@ core.registered_biomes = make_registration_wrap("register_biome", "cle
564570
core.registered_ores = make_registration_wrap("register_ore", "clear_registered_ores")
565571
core.registered_decorations = make_registration_wrap("register_decoration", "clear_registered_decorations")
566572

567-
core.unregister_biome = make_wrap_deregistration(core.register_biome, core.clear_registered_biomes, core.registered_biomes)
573+
core.unregister_biome = make_wrap_deregistration(core.register_biome,
574+
core.clear_registered_biomes, core.registered_biomes)
568575

569576
core.registered_on_chat_messages, core.register_on_chat_message = make_registration()
570577
core.registered_globalsteps, core.register_globalstep = make_registration()

0 commit comments

Comments
 (0)
Please sign in to comment.