local Utils = {} function Utils.percentCoordinates(x, y) x = (x/100)*Config.width y = (y/100)*Config.height return x, y end function Utils.tprint(tbl, indent) if not indent then indent = 0 end for k, v in pairs(tbl) do formatting = string.rep(" ", indent) .. k .. ": " if type(v) == "table" then print(formatting) Utils.tprint(v, indent+1) else print(formatting .. v) end end end function Utils.tuple2ToIndexHash(table) local tmp = {} for k,v in pairs(table) do tmp[v[1]] = k end return tmp end -- From http://lua-users.org/wiki/CopyTable function Utils.copyTable(orig) local orig_type = type(orig) local copy if orig_type == 'table' then copy = {} for orig_key, orig_value in next, orig, nil do copy[Utils.copyTable(orig_key)] = Utils.copyTable(orig_value) end setmetatable(copy, Utils.copyTable(getmetatable(orig))) else -- number, string, boolean, etc copy = orig end return copy end function Utils.sortByArtistAndTitle(a, b) if a.artist:lower() < b.artist:lower() then return true elseif a.artist:lower() == b.artist:lower() and a.title:lower() < b.title:lower() then return true else return false end end return Utils