2021-03-20 02:48:56 +01:00
|
|
|
|
|
|
|
--- Parses a map of key-value pairs into a table.
|
2021-05-30 02:40:18 +02:00
|
|
|
-- For example, "count 25000 speed 0.8 rate_erosion 0.006 doawesome true" would be parsed into
|
|
|
|
-- the following table: { count = 25000, speed = 0.8, rate_erosion = 0.006, doawesome = true }.
|
2021-03-20 02:48:56 +01:00
|
|
|
-- @param params_text string The string to parse.
|
|
|
|
-- @returns table A table of key-value pairs parsed out from the given string.
|
|
|
|
function worldeditadditions.parse.map(params_text)
|
|
|
|
local result = {}
|
|
|
|
local parts = worldeditadditions.split(params_text, "%s+", false)
|
|
|
|
|
|
|
|
local last_key = nil
|
|
|
|
for i, part in ipairs(parts) do
|
|
|
|
if i % 2 == 0 then -- Lua starts at 1 :-/
|
|
|
|
-- Try converting to a number to see if it works
|
|
|
|
local part_converted = tonumber(part)
|
2021-07-03 23:53:16 +02:00
|
|
|
if part_converted == nil then part_converted = part end
|
2021-05-30 02:40:18 +02:00
|
|
|
-- Look for bools
|
|
|
|
if part_converted == "true" then part_converted = true end
|
|
|
|
if part_converted == "false" then part_converted = false end
|
2021-03-20 02:48:56 +01:00
|
|
|
result[last_key] = part
|
|
|
|
else
|
|
|
|
last_key = part
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return true, result
|
|
|
|
end
|