mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-27 09:33:52 +01:00
we_core: fix bugs, add more useful error messages
This commit is contained in:
parent
3f1f3b5628
commit
12371a472d
@ -6,6 +6,7 @@ exclude_files = {
|
||||
"worldeditadditions/utils/bit.lua"
|
||||
}
|
||||
|
||||
files["worldeditadditions_core/register/check.lua"] = { read_globals = { "table" } }
|
||||
|
||||
ignore = {
|
||||
"631", "61[124]",
|
||||
|
@ -1,14 +1,37 @@
|
||||
function worldeditadditions_core.register_command(def)
|
||||
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
|
||||
local def = table.copy(def)
|
||||
assert(name and #name > 0)
|
||||
assert(def.privs)
|
||||
|
||||
assert(
|
||||
def.privs,
|
||||
"Error: No privileges specified in definition of command '"..name.."'."
|
||||
)
|
||||
|
||||
def.require_pos = def.require_pos or 0
|
||||
|
||||
assert(def.require_pos >= 0 and def.require_pos < 3)
|
||||
|
||||
if def.params == "" and not def.parse then
|
||||
def.parse = function(params_text) return true end
|
||||
else
|
||||
assert(def.parse)
|
||||
assert(
|
||||
def.parse,
|
||||
"Error: No parameter parsing function specified, even though parameters were specified in definition of command '"..name.."'."
|
||||
)
|
||||
end
|
||||
assert(def.nodes_needed == nil or type(def.nodes_needed) == "function")
|
||||
assert(def.func)
|
||||
|
||||
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
|
||||
end
|
||||
|
@ -1,5 +1,5 @@
|
||||
function worldeditadditions_core.chatcommand_handler(cmd_name, name, param)
|
||||
local def = assert(worldedit.registered_commands[cmd_name])
|
||||
local def = assert(worldedit.registered_commands[cmd_name], "Error: Failed to locate worldedit command definition for command '"..name.."' (this is probably a bug).")
|
||||
|
||||
if def.require_pos == 2 then
|
||||
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
||||
|
@ -1,6 +1,6 @@
|
||||
local we_c = worldeditadditions_core
|
||||
function we_c.override_command(name, def)
|
||||
local success, def = we_c.check(def)
|
||||
local success, def = we_c.check(name, def)
|
||||
|
||||
if not success then
|
||||
return false, def
|
||||
|
@ -1,6 +1,6 @@
|
||||
local we_c = worldeditadditions_core
|
||||
function we_c.register_command(name, def)
|
||||
local success, def = we_c.check(def)
|
||||
local success, def = we_c.check(name, def)
|
||||
|
||||
if not success then
|
||||
return false, def
|
||||
|
@ -1,5 +1,5 @@
|
||||
--- WorldEdit dependencies for WorldEditAdditions
|
||||
--- WorldEdit shim just in case WorldEdit doesn't exist
|
||||
|
||||
worldedit = {
|
||||
registered_commands = {}
|
||||
registered_commands = { }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user