forked from jxai/lean-conky-config
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtform.lua
More file actions
32 lines (27 loc) · 855 Bytes
/
tform.lua
File metadata and controls
32 lines (27 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
-- defend Lua version incompatibility, just in case
local _load = load
if _VERSION <= "Lua 5.1" then
_load = loadstring
end
-- apply transform functions to rewrite values in a string
-- e.g. "$sc{42}" would be replaced by the value of T_sc(42)
function T_(s)
local function _repl(f, args)
return assert(_load("return T_" .. f .. "(" .. args .. ")"))()
end
return s:gsub("$([%w_]+){([^{}]*)}", _repl)
end
-- scale a number
function T_sc(num, scale)
scale = scale or lcc.config.scale
return num * scale
end
-- scale then round, for where only integers are allowed
function T_sr(num, scale)
return math.floor(T_sc(num, scale) + 0.5)
end
-- scale then round to a multiple of 0.5
-- might be useful for certain cases, e.g. font size
function T_sh(num, scale)
return math.floor(T_sc(num * 2, scale) + 0.5) / 2.0
end