Software /
code /
prosody
Comparison
util/human/units.lua @ 10888:42a0d9089de9
util.human.units: Handle location of unpack() in Lua 5.1
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 03 Jun 2020 19:46:17 +0200 |
parent | 10886:994c4a333199 |
child | 10889:25e0ec11b4e4 |
comparison
equal
deleted
inserted
replaced
10887:3debe04a6162 | 10888:42a0d9089de9 |
---|---|
1 local unpack = table.unpack or unpack; --luacheck: ignore 113 | |
2 | |
1 local large = { | 3 local large = { |
2 "k", 1000, | 4 "k", 1000, |
3 "M", 1000000, | 5 "M", 1000000, |
4 "G", 1000000000, | 6 "G", 1000000000, |
5 "T", 1000000000000, | 7 "T", 1000000000000, |
47 elseif n < 1 then | 49 elseif n < 1 then |
48 prefixes = small; | 50 prefixes = small; |
49 round = math.ceil; | 51 round = math.ceil; |
50 end | 52 end |
51 local m = math.max(0, math.min(8, round(math.abs(math.log(math.abs(n), logbase))))); | 53 local m = math.max(0, math.min(8, round(math.abs(math.log(math.abs(n), logbase))))); |
52 local prefix, multiplier = table.unpack(prefixes, m * 2-1, m*2); | 54 local prefix, multiplier = unpack(prefixes, m * 2-1, m*2); |
53 return fmt:format(n / (multiplier or 1), prefix or "", unit); | 55 return fmt:format(n / (multiplier or 1), prefix or "", unit); |
54 end | 56 end |
55 | 57 |
56 return { | 58 return { |
57 format = format; | 59 format = format; |