changeset 13909:e6c6f58dfda1

moduleapi: :context(): ensure requested host exists (fixes #605)
author Matthew Wild <mwild1@gmail.com>
date Fri, 27 Jun 2025 11:11:08 +0100
parents 356c8ec22e9a
children 622790951285
files core/moduleapi.lua
diffstat 1 files changed, 5 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/core/moduleapi.lua	Thu Jun 26 15:17:57 2025 +0100
+++ b/core/moduleapi.lua	Fri Jun 27 11:11:08 2025 +0100
@@ -405,7 +405,11 @@
 end
 
 function api:context(host)
-	return setmetatable({ host = host or "*", global = "*" == host }, { __index = self, __newindex = self });
+	local is_global = host == "*";
+	if not is_global and not hosts[host] then
+		error("Cannot create context for unknown host: "..host);
+	end
+	return setmetatable({ host = host or "*", global = is_global }, { __index = self, __newindex = self });
 end
 
 function api:add_item(key, value)