Skip to content

Commit

Permalink
builtin/../register.lua: Abort make_wrap_deregistration if param is i…
Browse files Browse the repository at this point in the history
…nvalid
  • Loading branch information
ClobberXD authored and sfan5 committed May 4, 2019
1 parent 96f250e commit 72feab0
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions builtin/game/register.lua
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 72feab0

Please sign in to comment.