From d24ae56378dc9e503cb4ef9ecab779fa23205d1b Mon Sep 17 00:00:00 2001
From: Matthias Schiffer <mschiffer@universe-factory.net>
Date: Sun, 15 May 2022 15:29:30 +0200
Subject: [PATCH] gluon-core: check-site: support checking "custom" values

The new "value" helper can be used to turn a Lua value into a path that
can be passed to need_*() etc.
---
 .luacheckrc                                   |  1 +
 .../luasrc/lib/gluon/check-site.lua           | 20 +++++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/.luacheckrc b/.luacheckrc
index b308748c5..e0a64b544 100644
--- a/.luacheckrc
+++ b/.luacheckrc
@@ -25,6 +25,7 @@ files["package/**/check_site.lua"] = {
 		"extend",
 		"in_domain",
 		"in_site",
+		"value",
 		"need",
 		"need_alphanumeric_key",
 		"need_array",
diff --git a/package/gluon-core/luasrc/lib/gluon/check-site.lua b/package/gluon-core/luasrc/lib/gluon/check-site.lua
index 6861d8cb4..148f4968f 100644
--- a/package/gluon-core/luasrc/lib/gluon/check-site.lua
+++ b/package/gluon-core/luasrc/lib/gluon/check-site.lua
@@ -57,6 +57,10 @@ end
 
 
 local function path_to_string(path)
+	if path.is_value then
+		return path.label
+	end
+
 	return table.concat(path, '.')
 end
 
@@ -96,6 +100,10 @@ local function domain_src()
 end
 
 local function conf_src(path)
+	if path.is_value then
+		return 'Configuration'
+	end
+
 	local src
 
 	if has_domains then
@@ -138,6 +146,14 @@ function M.in_domain(path)
 	return path
 end
 
+function M.value(label, value)
+	return {
+		is_value = true,
+		label = label,
+		value = value,
+	}
+end
+
 function M.this_domain()
 	return domain_code
 end
@@ -171,6 +187,10 @@ function loadpath(path, base, c, ...)
 end
 
 local function loadvar(path)
+	if path.is_value then
+		return path.value
+	end
+
 	return loadpath({}, conf, unpack(path))
 end
 
-- 
GitLab