//many: fix running commands that take no arguments

This commit is contained in:
Starbeamrainbowlabs 2021-02-07 02:59:19 +00:00
parent a360f06138
commit 151afadf6c
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
2 changed files with 12 additions and 7 deletions

View file

@ -301,3 +301,8 @@ function worldeditadditions.makeseed(str)
end end
return result return result
end end
-- From http://lua-users.org/wiki/StringTrim
function worldeditadditions.trim(s)
return (s:gsub("^%s*(.-)%s*$", "%1"))
end

View file

@ -26,11 +26,6 @@ local function explode(delim, str)
end end
end end
-- From http://lua-users.org/wiki/StringTrim
local function trim(s)
return (s:gsub("^%s*(.-)%s*$", "%1"))
end
local function step(params) local function step(params)
local start_time = worldeditadditions.get_ms_time() local start_time = worldeditadditions.get_ms_time()
@ -96,11 +91,16 @@ minetest.register_chatcommand("/many", {
local times = {} local times = {}
local count, cmd_name, args = params_text:match("^(%d+)%s([^%s]+)%s(.+)$") local count, cmd_name, args = params_text:match("^(%d+)%s([^%s]+)%s(.+)$")
if not count then
count, cmd_name = params_text:match("^(%d+)%s([^%s]+)$")
if not count then return false, "Error: Invalid syntax" end if not count then return false, "Error: Invalid syntax" end
end
if not args then args = "" end
args = worldeditadditions.trim(args)
-- print("[many] count", count, "cmd_name", cmd_name, "args", args) -- print("[many] count", count, "cmd_name", cmd_name, "args", args)
count = tonumber(count) count = tonumber(count)
cmd_name = trim(cmd_name):sub(2) -- Things start at 1, not 0 in Lua :-( cmd_name = worldeditadditions.trim(cmd_name):sub(2) -- Things start at 1, not 0 in Lua :-(
-- Check the command we're going to execute -- Check the command we're going to execute
local cmd = minetest.chatcommands[cmd_name] local cmd = minetest.chatcommands[cmd_name]