mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-22 15:33:00 +00:00
//many: fix running commands that take no arguments
This commit is contained in:
parent
a360f06138
commit
151afadf6c
2 changed files with 12 additions and 7 deletions
|
@ -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
|
||||||
|
|
|
@ -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 return false, "Error: Invalid syntax" end
|
if not count then
|
||||||
|
count, cmd_name = params_text:match("^(%d+)%s([^%s]+)$")
|
||||||
|
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]
|
||||||
|
|
Loading…
Reference in a new issue