From d7e38d63930d34fe325282dc81c9517c166374db Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Tue, 10 May 2022 11:41:49 -0400 Subject: [PATCH] supression of warnings, added lua diagnostics global list --- .vscode/settings.json | 9 +++++++++ scada-common/util.lua | 16 ++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7978039 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,9 @@ +{ + "Lua.diagnostics.globals": [ + "term", + "fs", + "peripheral", + "rs", + "bit" + ] +} \ No newline at end of file diff --git a/scada-common/util.lua b/scada-common/util.lua index 4ee8567..78ab422 100644 --- a/scada-common/util.lua +++ b/scada-common/util.lua @@ -25,10 +25,12 @@ end -- TIME -- util.time_ms = function () +---@diagnostic disable-next-line: undefined-field return os.epoch('local') end util.time_s = function () +---@diagnostic disable-next-line: undefined-field return os.epoch('local') / 1000 end @@ -41,6 +43,7 @@ end -- protected sleep call so we still are in charge of catching termination -- EVENT_CONSUMER: this function consumes events util.psleep = function (t) +---@diagnostic disable-next-line: undefined-field pcall(os.sleep, t) end @@ -66,9 +69,14 @@ end -- ComputerCraft OS Timer based Watchdog -- triggers a timer event if not fed within 'timeout' seconds util.new_watchdog = function (timeout) + ---@diagnostic disable-next-line: undefined-field + local start_timer = os.startTimer + ---@diagnostic disable-next-line: undefined-field + local cancel_timer = os.cancelTimer + local self = { _timeout = timeout, - _wd_timer = os.startTimer(timeout) + _wd_timer = start_timer(timeout) } local get_timer = function () @@ -77,14 +85,14 @@ util.new_watchdog = function (timeout) local feed = function () if self._wd_timer ~= nil then - os.cancelTimer(self._wd_timer) + cancel_timer(self._wd_timer) end - self._wd_timer = os.startTimer(self._timeout) + self._wd_timer = start_timer(self._timeout) end local cancel = function () if self._wd_timer ~= nil then - os.cancelTimer(self._wd_timer) + cancel_timer(self._wd_timer) end end