mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-22 07:23:00 +00:00
various commands: Upgrade to use wea.split_shell
This commit is contained in:
parent
e16fa0f5c8
commit
45def53294
11 changed files with 18 additions and 12 deletions
|
@ -1,3 +1,4 @@
|
|||
-- worldeditadditions = { modpath="/home/sbrl/.minetest/worlds/Mod-Sandbox/worldmods/WorldEditAdditions/worldeditadditions/" }
|
||||
local table_map = dofile(worldeditadditions.modpath.."/utils/tables/table_map.lua")
|
||||
|
||||
local function is_whitespace(char)
|
||||
|
@ -21,6 +22,8 @@ local function split_shell(text)
|
|||
if i < text_length then nextchar = text:sub(i+1, i+1) end
|
||||
if i+1 < text_length then nextnextchar = text:sub(i+2, i+2) end
|
||||
|
||||
print("mode", mode, "prevchar", "curchar", curchar, "nextchar", nextchar)
|
||||
|
||||
if mode == "NORMAL" then
|
||||
if is_whitespace(curchar) and #acc > 0 then
|
||||
table.insert(result, table.concat(acc, ""))
|
||||
|
@ -35,9 +38,10 @@ local function split_shell(text)
|
|||
table.insert(acc, curchar)
|
||||
end
|
||||
elseif mode == "INSIDE_QUOTES_DOUBLE" then
|
||||
if curchar == "\"" and prevchar ~= "\\" and is_whitespace(nextchar) then
|
||||
if curchar == "\"" and prevchar ~= "\\" and (is_whitespace(nextchar) or #nextchar == 0) then
|
||||
-- It's the end of a quote!
|
||||
mode = "NORMAL"
|
||||
|
||||
elseif (curchar == "\\" and (
|
||||
nextchar ~= "\""
|
||||
or (nextchar == "\"" and not is_whitespace(nextnextchar))
|
||||
|
@ -71,7 +75,7 @@ end
|
|||
|
||||
return split_shell
|
||||
|
||||
-- function test(text)
|
||||
-- local function test(text)
|
||||
-- print("Source", text)
|
||||
-- for i,value in ipairs(split_shell(text)) do
|
||||
-- print("i", i, "→", value)
|
||||
|
@ -80,6 +84,7 @@ return split_shell
|
|||
-- end
|
||||
--
|
||||
-- test("yay yay yay")
|
||||
-- test("dirt \"snow block\"")
|
||||
-- test("yay \"yay yay\" yay")
|
||||
-- test("yay \"yay\\\" yay\" yay")
|
||||
-- test("yay \"yay 'inside quotes' yay\\\"\" yay")
|
||||
|
|
|
@ -15,7 +15,7 @@ worldedit.register_command("bonemeal", {
|
|||
params_text = "1"
|
||||
end
|
||||
|
||||
local parts = worldeditadditions.split(params_text, "%s+", false)
|
||||
local parts = worldeditadditions.split_shell(params_text, "%s+", false)
|
||||
|
||||
local strength = 1
|
||||
local chance = 1
|
||||
|
|
|
@ -11,7 +11,8 @@ worldedit.register_command("convolve", {
|
|||
parse = function(params_text)
|
||||
if not params_text then params_text = "" end
|
||||
|
||||
local parts = worldeditadditions.split(params_text, "%s+", false)
|
||||
-- local parts = worldeditadditions.split(params_text, "%s+", false)
|
||||
local parts = worldeditadditions.split_shell(params_text)
|
||||
|
||||
local kernel_name = "gaussian"
|
||||
local width = 5
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
-- ███████ ███████ ███████ ██ ██ ███████ ██████ ██ ██████
|
||||
local wea = worldeditadditions
|
||||
local function parse_params_ellipsoid(params_text)
|
||||
local parts = wea.split(params_text, "%s+", false)
|
||||
local parts = wea.split_shell(params_text)
|
||||
|
||||
if #parts < 4 then
|
||||
return false, "Error: Not enough arguments. Expected \"<rx> <ry> <rz> <replace_node> [h[ollow]]\"."
|
||||
|
|
|
@ -18,7 +18,7 @@ worldedit.register_command("forest", {
|
|||
end
|
||||
|
||||
local success, sapling_list = worldeditadditions.parse.weighted_nodes(
|
||||
worldeditadditions.split(params_text, "%s+", false),
|
||||
worldeditadditions.split_shell(params_text),
|
||||
false,
|
||||
function(name)
|
||||
return worldedit.normalize_nodename(
|
||||
|
|
|
@ -14,7 +14,7 @@ worldedit.register_command("layers", {
|
|||
end
|
||||
|
||||
local success, node_list = worldeditadditions.parse.weighted_nodes(
|
||||
worldeditadditions.split(params_text, "%s+", false),
|
||||
worldeditadditions.split_shell(params_text),
|
||||
true
|
||||
)
|
||||
return success, node_list
|
||||
|
|
|
@ -5,7 +5,7 @@ local function parse_params_maze(params_text, is_3d)
|
|||
return false, "No arguments specified"
|
||||
end
|
||||
|
||||
local parts = worldeditadditions.split(params_text, "%s+", false)
|
||||
local parts = worldeditadditions.split_shell(params_text)
|
||||
|
||||
local replace_node = parts[1]
|
||||
local seed = os.time()
|
||||
|
|
|
@ -10,7 +10,7 @@ worldedit.register_command("overlay", {
|
|||
require_pos = 2,
|
||||
parse = function(params_text)
|
||||
local success, node_list = worldeditadditions.parse.weighted_nodes(
|
||||
worldeditadditions.split(params_text, "%s+", false)
|
||||
worldeditadditions.split_shell(params_text)
|
||||
)
|
||||
return success, node_list
|
||||
end,
|
||||
|
|
|
@ -15,7 +15,7 @@ worldedit.register_command("replacemix", {
|
|||
return false, "Error: No arguments specified"
|
||||
end
|
||||
|
||||
local parts = wea.split(params_text, "%s+", false)
|
||||
local parts = wea.split_shell(params_text)
|
||||
|
||||
local target_node = nil
|
||||
local target_node_chance = 1
|
||||
|
|
|
@ -30,7 +30,7 @@ worldedit.register_command("scale", {
|
|||
parse = function(params_text)
|
||||
if not params_text then params_text = "" end
|
||||
|
||||
local parts = worldeditadditions.split(params_text, "%s+", false)
|
||||
local parts = worldeditadditions.split_shell(params_text)
|
||||
|
||||
local scale = vector.new(1, 1, 1)
|
||||
local anchor = vector.new(1, 1, 1)
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
-- ██ ██ ██ ██ ██ ██ ██ ██
|
||||
-- ██ ██████ ██ ██ ██████ ███████
|
||||
local function parse_params_torus(params_text)
|
||||
local parts = worldeditadditions.split(params_text, "%s+", false)
|
||||
local parts = worldeditadditions.split_shell(params_text)
|
||||
|
||||
if #parts < 1 then
|
||||
return false, "Error: No replace_node specified."
|
||||
|
|
Loading…
Reference in a new issue