Use tabs consistently.
This commit is contained in:
parent
170e397961
commit
b995b401e8
174
init.lua
174
init.lua
@ -11,105 +11,105 @@
|
|||||||
|
|
||||||
|
|
||||||
local function isArray(t)
|
local function isArray(t)
|
||||||
-- Check if a table only contains sequential values.
|
-- Check if a table only contains sequential values.
|
||||||
-- by kikito
|
-- by kikito
|
||||||
-- [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/)
|
-- [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/)
|
||||||
-- answered May 21, 2011 at 7:22
|
-- answered May 21, 2011 at 7:22
|
||||||
-- edited Mar 2, 2014 at 17:13
|
-- edited Mar 2, 2014 at 17:13
|
||||||
-- <https://stackoverflow.com/a/6080274/4541104>
|
-- <https://stackoverflow.com/a/6080274/4541104>
|
||||||
local i = 0
|
local i = 0
|
||||||
for _ in pairs(t) do
|
for _ in pairs(t) do
|
||||||
i = i + 1
|
i = i + 1
|
||||||
if t[i] == nil then return false end
|
if t[i] == nil then return false end
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function yamlSerializeTable(val, name, depth)
|
function yamlSerializeTable(val, name, depth)
|
||||||
-- Make a table into a string.
|
-- Make a table into a string.
|
||||||
-- (c) 2011 Henrik Ilgen, 2022 Poikilos
|
-- (c) 2011 Henrik Ilgen, 2022 Poikilos
|
||||||
-- [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/)
|
-- [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/)
|
||||||
-- answered May 21 '11 at 12:14 Henrik Ilgen
|
-- answered May 21 '11 at 12:14 Henrik Ilgen
|
||||||
-- edited May 13, 2019 at 9:10
|
-- edited May 13, 2019 at 9:10
|
||||||
-- on <https://stackoverflow.com/a/6081639>
|
-- on <https://stackoverflow.com/a/6081639>
|
||||||
-- Only the first argument is required.
|
-- Only the first argument is required.
|
||||||
-- Get the object back from the string via:
|
-- Get the object back from the string via:
|
||||||
-- a = loadstring(s)()
|
-- a = loadstring(s)()
|
||||||
depth = depth or 0
|
depth = depth or 0
|
||||||
|
|
||||||
local tmp = string.rep(" ", depth)
|
local tmp = string.rep(" ", depth)
|
||||||
|
|
||||||
if name then
|
if name then
|
||||||
if name == "METATOOLS_ARRAY_ELEMENT" then
|
if name == "METATOOLS_ARRAY_ELEMENT" then
|
||||||
tmp = tmp .. "- "
|
tmp = tmp .. "- "
|
||||||
else
|
else
|
||||||
tmp = tmp .. name .. ": "
|
tmp = tmp .. name .. ": "
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if type(val) == "table" then
|
if type(val) == "table" then
|
||||||
if isArray(val) then
|
if isArray(val) then
|
||||||
tmp = tmp .. "\n"
|
tmp = tmp .. "\n"
|
||||||
for k, v in pairs(val) do
|
for k, v in pairs(val) do
|
||||||
tmp = tmp .. yamlSerializeTable(v, "METATOOLS_ARRAY_ELEMENT", depth + 1) .. "\n"
|
tmp = tmp .. yamlSerializeTable(v, "METATOOLS_ARRAY_ELEMENT", depth + 1) .. "\n"
|
||||||
end
|
end
|
||||||
-- tmp = tmp .. string.rep(" ", depth)
|
-- tmp = tmp .. string.rep(" ", depth)
|
||||||
else
|
else
|
||||||
tmp = tmp .. "\n" -- Newline is after <name>: for tables.
|
tmp = tmp .. "\n" -- Newline is after <name>: for tables.
|
||||||
for k, v in pairs(val) do
|
for k, v in pairs(val) do
|
||||||
tmp = tmp .. yamlSerializeTable(v, k, depth + 1) .. "\n"
|
tmp = tmp .. yamlSerializeTable(v, k, depth + 1) .. "\n"
|
||||||
end
|
end
|
||||||
-- tmp = tmp .. string.rep(" ", depth)
|
-- tmp = tmp .. string.rep(" ", depth)
|
||||||
end
|
end
|
||||||
elseif type(val) == "number" then
|
elseif type(val) == "number" then
|
||||||
tmp = tmp .. tostring(val)
|
tmp = tmp .. tostring(val)
|
||||||
elseif type(val) == "string" then
|
elseif type(val) == "string" then
|
||||||
tmp = tmp .. string.format("%q", val)
|
tmp = tmp .. string.format("%q", val)
|
||||||
elseif type(val) == "boolean" then
|
elseif type(val) == "boolean" then
|
||||||
tmp = tmp .. (val and "true" or "false")
|
tmp = tmp .. (val and "true" or "false")
|
||||||
else
|
else
|
||||||
tmp = tmp .. "\"[inserializeable datatype:" .. type(val) .. "]\""
|
tmp = tmp .. "\"[inserializeable datatype:" .. type(val) .. "]\""
|
||||||
end
|
end
|
||||||
return tmp
|
return tmp
|
||||||
end
|
end
|
||||||
|
|
||||||
function serializeTable(val, name, skipnewlines, depth)
|
function serializeTable(val, name, skipnewlines, depth)
|
||||||
-- Make a table into a string.
|
-- Make a table into a string.
|
||||||
-- (c) 2011 Henrik Ilgen
|
-- (c) 2011 Henrik Ilgen
|
||||||
-- [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/)
|
-- [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/)
|
||||||
-- answered May 21 '11 at 12:14 Henrik Ilgen
|
-- answered May 21 '11 at 12:14 Henrik Ilgen
|
||||||
-- edited May 13, 2019 at 9:10
|
-- edited May 13, 2019 at 9:10
|
||||||
-- on <https://stackoverflow.com/a/6081639>
|
-- on <https://stackoverflow.com/a/6081639>
|
||||||
-- Only the first argument is required.
|
-- Only the first argument is required.
|
||||||
-- Get the object back from the string via:
|
-- Get the object back from the string via:
|
||||||
-- a = loadstring(s)()
|
-- a = loadstring(s)()
|
||||||
skipnewlines = skipnewlines or false
|
skipnewlines = skipnewlines or false
|
||||||
depth = depth or 0
|
depth = depth or 0
|
||||||
|
|
||||||
local tmp = string.rep(" ", depth)
|
local tmp = string.rep(" ", depth)
|
||||||
|
|
||||||
if name then tmp = tmp .. name .. " = " end
|
if name then tmp = tmp .. name .. " = " end
|
||||||
|
|
||||||
if type(val) == "table" then
|
if type(val) == "table" then
|
||||||
tmp = tmp .. "{" .. (not skipnewlines and "\n" or "")
|
tmp = tmp .. "{" .. (not skipnewlines and "\n" or "")
|
||||||
|
|
||||||
for k, v in pairs(val) do
|
for k, v in pairs(val) do
|
||||||
tmp = tmp .. serializeTable(v, k, skipnewlines, depth + 1) .. "," .. (not skipnewlines and "\n" or "")
|
tmp = tmp .. serializeTable(v, k, skipnewlines, depth + 1) .. "," .. (not skipnewlines and "\n" or "")
|
||||||
end
|
end
|
||||||
|
|
||||||
tmp = tmp .. string.rep(" ", depth) .. "}"
|
tmp = tmp .. string.rep(" ", depth) .. "}"
|
||||||
elseif type(val) == "number" then
|
elseif type(val) == "number" then
|
||||||
tmp = tmp .. tostring(val)
|
tmp = tmp .. tostring(val)
|
||||||
elseif type(val) == "string" then
|
elseif type(val) == "string" then
|
||||||
tmp = tmp .. string.format("%q", val)
|
tmp = tmp .. string.format("%q", val)
|
||||||
elseif type(val) == "boolean" then
|
elseif type(val) == "boolean" then
|
||||||
tmp = tmp .. (val and "true" or "false")
|
tmp = tmp .. (val and "true" or "false")
|
||||||
else
|
else
|
||||||
tmp = tmp .. "\"[inserializeable datatype:" .. type(val) .. "]\""
|
tmp = tmp .. "\"[inserializeable datatype:" .. type(val) .. "]\""
|
||||||
end
|
end
|
||||||
|
|
||||||
return tmp
|
return tmp
|
||||||
end
|
end
|
||||||
|
|
||||||
local function token_indices(haystack, needle)
|
local function token_indices(haystack, needle)
|
||||||
@ -327,10 +327,10 @@ minetest.register_craftitem("metatools:stick",{
|
|||||||
-- (same for other variables),
|
-- (same for other variables),
|
||||||
-- so API documentation is unclear:
|
-- so API documentation is unclear:
|
||||||
-- `get_animation()`: returns `range`, `frame_speed`, `frame_blend` and
|
-- `get_animation()`: returns `range`, `frame_speed`, `frame_blend` and
|
||||||
-- `frame_loop`.
|
-- `frame_loop`.
|
||||||
-- yamlSerializeTable(animation) only gets:
|
-- yamlSerializeTable(animation) only gets:
|
||||||
-- y: 65
|
-- y: 65
|
||||||
-- x: 35
|
-- x: 35
|
||||||
-- minetest.chat_send_player(
|
-- minetest.chat_send_player(
|
||||||
-- username,
|
-- username,
|
||||||
-- yamlSerializeTable(animation.range, " range")
|
-- yamlSerializeTable(animation.range, " range")
|
||||||
|
Loading…
Reference in New Issue
Block a user