blockgame/mods/bg_api/util_string.lua
trans_soup 7df5d33d02 refactor: extract repeated code into api function.
move function `starts_with`, which was declared twice in separate files,
to the api, and make those files use that function instead.
2023-10-17 14:58:15 +02:00

23 lines
550 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