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
|
local fmts = {
["zł"] = "%.2f %s",
l = "%.2f %s",
km = "%.1f %s",
}
local function fmt (value, unit)
return (fmts[unit] or "%.1f"):format(value, unit)
end
local last_milage = 0
local function relative (kilometres)
return last_milage + kilometres
end
local function fill (id, date, time, milage, fuel, cost, volume)
if last_milage > milage then
error "new milage may not be less than the previous"
end
last_milage = milage
print(id, date, time, fmt(last_milage, "km"), fuel, fmt(cost, "zł"), fmt(volume, "l"))
end
return {fill=fill, relative=relative}
|