2021-11-07 13:35:40 +00:00
function worldeditadditions_core . register_command ( name , def )
-- TODO: Implement our own deep copy function here
-- Depending on a Minetest-specific addition here makes be very uneasy
-- ...especially since it's not obvious at first glance that this isn't a
-- core feature provided by Lua itself
2021-06-30 01:53:14 +00:00
local def = table.copy ( def )
2021-11-07 13:35:40 +00:00
assert (
def.privs ,
" Error: No privileges specified in definition of command ' " .. name .. " '. "
)
2021-06-30 01:53:14 +00:00
def.require_pos = def.require_pos or 0
2021-11-07 13:35:40 +00:00
2021-06-30 01:53:14 +00:00
assert ( def.require_pos >= 0 and def.require_pos < 3 )
2021-11-07 13:35:40 +00:00
2021-06-30 01:53:14 +00:00
if def.params == " " and not def.parse then
2021-07-15 21:04:43 +00:00
def.parse = function ( params_text ) return true end
2021-06-30 01:53:14 +00:00
else
2021-11-07 13:35:40 +00:00
assert (
def.parse ,
" Error: No parameter parsing function specified, even though parameters were specified in definition of command ' " .. name .. " '. "
)
2021-06-30 01:53:14 +00:00
end
2021-11-07 13:35:40 +00:00
assert (
def.nodes_needed == nil or type ( def.nodes_needed ) == " function " ,
" Error: nodes_needed must be either not specified or be a function that returns the number of nodes that could potentially be changed for a given set fo parsed parameters in definition of command ' " .. name .. " ' "
)
assert (
def.func ,
" Error: 'func' is not defined. It must be defined to the function to call to run the command in definition of command ' " .. name .. " '. "
)
return def
2021-06-30 01:53:14 +00:00
end