From 4cc90797462549df16c802f42db8d9ee96e9412e Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Sun, 17 Sep 2017 13:29:14 -0400 Subject: util.throttle: Fix initial time setting (double accounting the first time) and fractional balance updates (0.1*10 was not the same as 1*1) --- util/throttle.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'util') diff --git a/util/throttle.lua b/util/throttle.lua index 18692a8a..a8191886 100644 --- a/util/throttle.lua +++ b/util/throttle.lua @@ -12,7 +12,7 @@ function throttle:update() local newt = gettime(); local elapsed = newt - self.t; self.t = newt; - local balance = floor(self.rate * elapsed) + self.balance; + local balance = (self.rate * elapsed) + self.balance; if balance > self.max then self.balance = self.max; else @@ -40,7 +40,7 @@ function throttle:poll(cost, split) end local function create(max, period) - return setmetatable({ rate = max / period, max = max, t = 0, balance = max }, throttle_mt); + return setmetatable({ rate = max / period, max = max, t = gettime(), balance = max }, throttle_mt); end return { -- cgit v1.2.3 From 03b4a9a938d1ec27f5a0119e2c799cfbba360ff3 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 23 Sep 2017 13:20:46 +0100 Subject: util.dataforms: Don't include list options in result forms (fixes #983) --- util/dataforms.lua | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) (limited to 'util') diff --git a/util/dataforms.lua b/util/dataforms.lua index 756f35a7..469ce976 100644 --- a/util/dataforms.lua +++ b/util/dataforms.lua @@ -68,33 +68,37 @@ function form_t.form(layout, data, formtype) form:tag("value"):text(line):up(); end elseif field_type == "list-single" then - local has_default = false; - for _, val in ipairs(field.options or value) do - if type(val) == "table" then - form:tag("option", { label = val.label }):tag("value"):text(val.value):up():up(); - if value == val.value or val.default and (not has_default) then - form:tag("value"):text(val.value):up(); - has_default = true; + if formtype ~= "result" then + local has_default = false; + for _, val in ipairs(field.options or value) do + if type(val) == "table" then + form:tag("option", { label = val.label }):tag("value"):text(val.value):up():up(); + if value == val.value or val.default and (not has_default) then + form:tag("value"):text(val.value):up(); + has_default = true; + end + else + form:tag("option", { label= val }):tag("value"):text(tostring(val)):up():up(); end - else - form:tag("option", { label= val }):tag("value"):text(tostring(val)):up():up(); end end - if field.options and value then + if (field.options or formtype == "result") and value then form:tag("value"):text(value):up(); end elseif field_type == "list-multi" then - for _, val in ipairs(field.options or value) do - if type(val) == "table" then - form:tag("option", { label = val.label }):tag("value"):text(val.value):up():up(); - if not field.options and val.default then - form:tag("value"):text(val.value):up(); + if formtype ~= "result" then + for _, val in ipairs(field.options or value) do + if type(val) == "table" then + form:tag("option", { label = val.label }):tag("value"):text(val.value):up():up(); + if not field.options and val.default then + form:tag("value"):text(val.value):up(); + end + else + form:tag("option", { label= val }):tag("value"):text(tostring(val)):up():up(); end - else - form:tag("option", { label= val }):tag("value"):text(tostring(val)):up():up(); end end - if field.options and value then + if (field.options or formtype == "result") and value then for _, val in ipairs(value) do form:tag("value"):text(val):up(); end -- cgit v1.2.3