diff --git a/lib/lua/tableHelper.lua b/lib/lua/tableHelper.lua index 20dbae8f..aaf0cd99 100644 --- a/lib/lua/tableHelper.lua +++ b/lib/lua/tableHelper.lua @@ -400,6 +400,18 @@ function tableHelper.isEmpty(inputTable) return false end +-- Function to get a table entry by its associated value +-- Note: This function is designed to handle cases where the loaded value may not be in the expected format due to "cjson" behavior. +-- Specifically, "cjson" may load a saved string containing only numbers as a number instead of a string. +function tableHelper.getEntryInTableByValue(inputTable, searchValue) + for key, value in pairs(inputTable) do + if key == searchValue or tostring(key) == tostring(searchValue) then + return value -- Return the table entry with all associated data + end + end + return nil +end + -- Check whether the table is an array with only consecutive numerical keys, -- i.e. without any gaps between keys -- Based on http://stackoverflow.com/a/6080274