From ffdef1776115a6adbfd2ac814acd28770202a9bd Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Sat, 29 May 2021 01:17:24 +0100 Subject: [PATCH] //multi: add { curly brace } syntax support for grouping blocks of commands --- CHANGELOG.md | 3 ++- Chat-Command-Reference.md | 14 ++++++++++++++ .../commands/meta/multi.lua | 19 +++++++++++++------ 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3c8af3..f5ed9f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ Note to self: See the bottom of this file for the release template text. - Caveat: Percentages are converted to a 1-in-N chance, but additionally that number is rounded down in some places - `//torus`, `//hollowtorus`: Add optional new axes - `//torus`: Add optional hollow keyword + - `//multi`: Add curly brace syntax for nesting command calls ### Bugfixes - `//overlay`: Don't place nodes above water @@ -92,7 +93,7 @@ Updating depends on how you installed WorldEditAdditions. - UI in Minetest: There should be an update button for you to click in the mod menu - ContentDB: Download the latest update from [here](https://content.minetest.net/packages/Starbeamrainbowlabs/worldeditadditions/) - - Git: `cd` to the WorldEditAdditions directory and run `git pull` + - Git: `cd` to the WorldEditAdditions directory and run `git pull` (**Important:** Recently, WorldEditAdditions changed the default branch from `master` to `main`. If you're updating from before then, you'll need to re-clone the mod or else do some git-fu) After installing the update, don't forget to restart your client and / or server. diff --git a/Chat-Command-Reference.md b/Chat-Command-Reference.md index 90682e9..f98d296 100644 --- a/Chat-Command-Reference.md +++ b/Chat-Command-Reference.md @@ -475,6 +475,20 @@ While other server commands can be executed while a `//subdivide` is running, `/ ## `//multi .....` Executes multi chat commands in sequence. Intended for _WorldEdit_ commands, but does work with others too. Don't forget a space between commands! +``` +//multi //set dirt //shift x 10 //set glass +``` + +Since WorldEditAdditions v1.12, curly brace syntax has also been introduced to allow nesting of commands: + +``` +//multi //fixlight {//many 5 //bonemeal 3 100} +``` + +This syntax can also be nested arbitrarily in arbitrarily complex combinations, and can also be used multiple separate times in a single `//multi` invocation (if you find a bug, please [open an issue](https://github.com/sbrl/Minetest-WorldEditAdditions/issues/new)), though do remember that only `//multi` supports parsing out this syntax (e.g. if you want to nest multiple commands in a `//many` that's inside a `//multi`, you'll need a sub `//multi` there). + +In addition, this also allows for including a double forward slash in the argument list for a command, should you need to do so (e.g. `//multi //example {//bar //baz} //example` will be executed as 3 commands: `/example`, then `/bar` with an argument of `//baz`, then finally `/example`). + ``` //multi //1 //2 //shift z -10 //sphere 5 sand //shift z 20 //ellipsoid 5 3 5 ice //multi //1 //hollowtorus 30 5 stone //hollowtorus 20 3 dirt //torus 10 2 dirt_with_grass diff --git a/worldeditadditions_commands/commands/meta/multi.lua b/worldeditadditions_commands/commands/meta/multi.lua index fe177bc..81fec34 100644 --- a/worldeditadditions_commands/commands/meta/multi.lua +++ b/worldeditadditions_commands/commands/meta/multi.lua @@ -40,29 +40,36 @@ minetest.register_chatcommand("/multi", { local master_start_time = worldeditadditions.get_ms_time() local times = {} - -- Things start at 1, not 0 in Lua :-( - for command in explode(" /", string.sub(params_text, 2)) do + -- Tokenise the input into a list of commands + local success, commands = worldeditadditions.parse.tokenise_commands(params_text) + if not success then return success, commands end + + for i, command in ipairs(commands) do + print("[DEBUG] i", i, "command: '"..command.."'") local start_time = worldeditadditions.get_ms_time() + local found, _, command_name, args = command:find("^([^%s]+)%s(.+)$") if not found then command_name = command end - command_name = worldeditadditions.trim(command_name) + -- Things start at 1, not 0 in Lua :-( + command_name = worldeditadditions.trim(command_name):sub(2) -- Strip the leading / if not args then args = "" end + print("command_name", command_name) - worldedit.player_notify(name, "#"..i..": /"..command) + worldedit.player_notify(name, "#"..i..": "..command) local cmd = minetest.chatcommands[command_name] if not cmd then return false, "Error: "..command_name.." isn't a valid command." end if not minetest.check_player_privs(name, cmd.privs) then - return false, "Your privileges are insufficient to execute /"..command_name..". Abort." + return false, "Your privileges are insufficient to execute "..command_name..". Abort." end -- print("[DEBUG] command_name", command_name, "cmd", dump2(cmd)) minetest.log("action", name.." runs "..command) cmd.func(name, args) times[#times + 1] = (worldeditadditions.get_ms_time() - start_time) - i = i + 1 + -- i = i + 1 end local total_time = (worldeditadditions.get_ms_time() - master_start_time)