//multi: add { curly brace } syntax support for grouping blocks of commands

This commit is contained in:
Starbeamrainbowlabs 2021-05-29 01:17:24 +01:00
parent 98a04b12db
commit ffdef17761
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
3 changed files with 29 additions and 7 deletions

View File

@ -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.

View File

@ -475,6 +475,20 @@ While other server commands can be executed while a `//subdivide` is running, `/
## `//multi <command_a> <command_b> <command_c> .....`
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

View File

@ -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)