/ util.lua
util.lua
 1  local S = minetest.get_translator("player_settings")
 2  local _ps = player_settings
 3  _ps.util = {}
 4  
 5  _ps.util.idx_in_table = function(tb,v)
 6      for i,tv in ipairs(tb) do
 7          if tv == v then return i end
 8      end
 9      return nil
10  end
11  
12  _ps.util.errmsgs = {
13      PLAYER_NOT_EXIST = S("Player does not exist"),
14      KEY_NOT_EXIST = S("Key does not exist"),
15      TYPE_CONVERT_FAILED = S("Value not matching the data type"),
16      SETTING_ENUM_TYPE_INVALID = S("Invalid enum data type"),
17      SETTING_VALUE_NOT_IN_ENUM = S("Value not in list of choices"),
18      SETTING_TYPE_INVALID = S("Invalid setting data type"),
19      VALIDATION_FAILED = S("Validation failed"),
20      NUMBER_TOO_SMALL = S("Number too small"),
21      NUMBER_TOO_LARGE = S("Number too large"),
22  }
23  
24  -- type = "int" / "string" / "bool" / "float" / "enum"
25  _ps.util.types = {
26      int = S("Integer"),
27      string = S("String"),
28      bool = S("Boolean"),
29      float = S("Float"),
30      enum = S("Multiple-choice")
31  }