add utility for extracting name parts.

add API function for splitting up an item identifier into its mod name
and item name parts.
This commit is contained in:
trans_soup 2023-10-21 22:03:28 +02:00
parent 8dfccdd315
commit 0c5d4891b7
1 changed files with 18 additions and 0 deletions

View File

@ -21,3 +21,21 @@ 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