]> git.lizzy.rs Git - minetest.git/commitdiff
Improve ABM and LBM registration error handling (#12969)
authorJude Melton-Houghton <jwmhjwmh@gmail.com>
Sun, 20 Nov 2022 20:26:54 +0000 (15:26 -0500)
committerGitHub <noreply@github.com>
Sun, 20 Nov 2022 20:26:54 +0000 (21:26 +0100)
builtin/game/register.lua

index d4c8768981f63b848678a8d76362056e5b947a8c..f0a6cb49a267c05cb503714e701710a0cde6243c 100644 (file)
@@ -79,8 +79,22 @@ local function check_modname_prefix(name)
        end
 end
 
+local function check_node_list(list, field)
+       local t = type(list)
+       if t == "table" then
+               for _, entry in pairs(list) do
+                       assert(type(entry) == "string",
+                               "Field '" .. field .. "' contains non-string entry")
+               end
+       elseif t ~= "string" and t ~= "nil" then
+               error("Field '" .. field .. "' has invalid type " .. t)
+       end
+end
+
 function core.register_abm(spec)
        -- Add to core.registered_abms
+       check_node_list(spec.nodenames, "nodenames")
+       check_node_list(spec.neighbors, "neighbors")
        assert(type(spec.action) == "function", "Required field 'action' of type function")
        core.registered_abms[#core.registered_abms + 1] = spec
        spec.mod_origin = core.get_current_modname() or "??"
@@ -89,6 +103,7 @@ end
 function core.register_lbm(spec)
        -- Add to core.registered_lbms
        check_modname_prefix(spec.name)
+       check_node_list(spec.nodenames, "nodenames")
        assert(type(spec.action) == "function", "Required field 'action' of type function")
        core.registered_lbms[#core.registered_lbms + 1] = spec
        spec.mod_origin = core.get_current_modname() or "??"