Refactored funcs.lua
- Renamed st and sp to strTrueValues and frameTime respectively - Modified files calling these to use the new names - Tidying like formatTime now using a single string.format
This commit is contained in:
27
funcs.lua
27
funcs.lua
@@ -1,4 +1,5 @@
|
||||
function copy(t)
|
||||
-- returns deep copy of t (as opposed to the shallow copy you get from var = t)
|
||||
if type(t) ~= "table" then return t end
|
||||
local meta = getmetatable(t)
|
||||
local target = {}
|
||||
@@ -7,7 +8,8 @@ function copy(t)
|
||||
return target
|
||||
end
|
||||
|
||||
function st(tbl)
|
||||
function strTrueValues(tbl)
|
||||
-- returns a concatenation of all the keys in tbl with value true, separated with spaces
|
||||
str = ""
|
||||
for k, v in pairs(tbl) do
|
||||
if v == true then
|
||||
@@ -17,14 +19,16 @@ function st(tbl)
|
||||
return str
|
||||
end
|
||||
|
||||
function sp(m, s, f)
|
||||
if m == nil then m = 0 end
|
||||
if s == nil then s = 0 end
|
||||
if f == nil then f = 0 end
|
||||
return m*3600 + s*60 + math.ceil(f * 0.6)
|
||||
function frameTime(min, sec, hth)
|
||||
-- returns a time in frames from a time in minutes-seconds-hundredths format
|
||||
if min == nil then min = 0 end
|
||||
if sec == nil then sec = 0 end
|
||||
if hth == nil then hth = 0 end
|
||||
return min*3600 + sec*60 + math.ceil(hth * 0.6)
|
||||
end
|
||||
|
||||
function vAdd(v1, v2)
|
||||
-- returns the sum of vectors v1 and v2
|
||||
return {
|
||||
x = v1.x + v2.x,
|
||||
y = v1.y + v2.y
|
||||
@@ -32,6 +36,7 @@ function vAdd(v1, v2)
|
||||
end
|
||||
|
||||
function vNeg(v)
|
||||
-- returns the opposite of vector v
|
||||
return {
|
||||
x = -v.x,
|
||||
y = -v.y
|
||||
@@ -39,14 +44,18 @@ function vNeg(v)
|
||||
end
|
||||
|
||||
function formatTime(frames)
|
||||
-- returns a mm:ss:hh (h=hundredths) representation of the time in frames given
|
||||
if frames < 0 then return formatTime(0) end
|
||||
str = string.format("%02d", math.floor(frames / 3600)) .. ":"
|
||||
.. string.format("%02d", math.floor(frames / 60) % 60) .. "."
|
||||
.. string.format("%02d", math.floor(frames / 0.6) % 100)
|
||||
local min, sec, hund
|
||||
min = math.floor(frames/3600)
|
||||
sec = math.floor(frames/60) % 60
|
||||
hund = math.floor(frames/.6) % 100
|
||||
str = string.format("%02d:%02d.%02d", min, sec, hund)
|
||||
return str
|
||||
end
|
||||
|
||||
function formatBigNum(number)
|
||||
-- returns a string representing a number with commas as thousands separator (e.g. 12,345,678)
|
||||
local s = string.format("%d", number)
|
||||
local pos = string.len(s) % 3
|
||||
if pos == 0 then pos = 3 end
|
||||
|
||||
Reference in New Issue
Block a user