Files
pfUI/env/functions.lua
T
2016-12-23 19:35:27 +01:00

55 lines
1.4 KiB
Lua

-- a real "round" instead of ceil or floor
function round(input, places)
if not places then places = 0 end
if type(input) == "number" and type(places) == "number" then
local pow = 1
for i = 1, places do pow = pow * 10 end
return floor(input * pow + 0.5) / pow
end
end
function strsplit(delimiter, subject)
local ret = {}
local sector = subject
while true do
local pos = strfind(sector, delimiter)
if pos then
table.insert(ret, strsub(sector,1,pos-1))
sector = strsub(sector,pos+1)
else
table.insert(ret, sector)
return unpack(ret)
end
end
end
function CreateGoldString(money)
local gold = floor(money/ 100 / 100)
local silver = floor(mod((money/100),100))
local copper = floor(mod(money,100))
local string = ""
if gold > 0 then string = string .. "|cffffffff" .. gold .. "|cffffd700g" end
if silver > 0 then string = string .. "|cffffffff " .. silver .. "|cffc7c7cfs" end
string = string .. "|cffffffff " .. copper .. "|cffeda55fc"
return string
end
function CopyTable(src)
local lookup_table = {}
local function _copy(src)
if type(src) ~= "table" then
return src
elseif lookup_table[src] then
return lookup_table[src]
end
local new_table = {}
lookup_table[src] = new_table
for index, value in pairs(src) do
new_table[_copy(index)] = _copy(value)
end
return setmetatable(new_table, getmetatable(src))
end
return _copy(src)
end