blockgame/mods/bg_api/util_string.lua
trans_soup 0c5d4891b7 add utility for extracting name parts.
add API function for splitting up an item identifier into its mod name
and item name parts.
2023-10-21 22:03:28 +02:00

41 lines
912 B
Lua

function blockgame.stringify (tab)
if type(tab) == "table" then
local result = "{ "
for key, value in pairs(tab) do
result = result .. key .. ": " .. blockgame.stringify(value) .. ", "
end
return result .. "}"
elseif type(tab) == "function" then
return "<function>"
elseif type(tab) == "boolean" then
if tab then return "true" else return "false" end
elseif type(tab) == "nil" then
return "nil"
else
return tab
end
end
function blockgame.starts_with (str, start)
return string.sub(str, 1, string.len(start)) == start
end
function blockgame.extract_id_parts (name)
local basename
local modname
local colon_pos = string.find(name, ":")
if colon_pos then
modname = string.sub(name, 1, colon_pos - 1)
basename = string.sub(name, colon_pos + 1)
else
modname = minetest.get_current_modname()
basename = name
end
return basename, modname, modname .. ":" .. basename
end