From 0c5d4891b78087f9bfff70087a8dd40e4d9f8ad2 Mon Sep 17 00:00:00 2001 From: trans_soup <> Date: Sat, 21 Oct 2023 22:03:28 +0200 Subject: [PATCH] add utility for extracting name parts. add API function for splitting up an item identifier into its mod name and item name parts. --- mods/bg_api/util_string.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/mods/bg_api/util_string.lua b/mods/bg_api/util_string.lua index fe897a6..6650ecd 100644 --- a/mods/bg_api/util_string.lua +++ b/mods/bg_api/util_string.lua @@ -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