From b181803ac4ef6aae6c94e78568d16f865103f184 Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Sun, 5 Apr 2020 21:32:27 +0200 Subject: [PATCH] scripts: check_site: add need_number_range check --- .luacheckrc | 1 + scripts/check_site.lua | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/.luacheckrc b/.luacheckrc index 06bda7bc..62d839a3 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -32,6 +32,7 @@ files["package/**/check_site.lua"] = { "need_chanlist", "need_domain_name", "need_number", + "need_number_range", "need_one_of", "need_string", "need_string_array", diff --git a/scripts/check_site.lua b/scripts/check_site.lua index 4e78437a..dd33bf52 100644 --- a/scripts/check_site.lua +++ b/scripts/check_site.lua @@ -289,6 +289,19 @@ function M.need_number(path, required) return need_type(path, 'number', required, 'be a number') end +function M.need_number_range(path, min, max, required) + local val = need_type(path, 'number', required) + if not val then + return nil + end + + if val < min or val > max then + var_error(path, val, "be in range [" .. min .. ", " .. max .. "]") + end + + return val +end + function M.need_boolean(path, required) return need_type(path, 'boolean', required, 'be a boolean') end