comparison core/moduleapi.lua @ 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 4309c934e813
children 622790951285
comparison
equal deleted inserted replaced
13908:356c8ec22e9a 13909:e6c6f58dfda1
403 end 403 end
404 return value; 404 return value;
405 end 405 end
406 406
407 function api:context(host) 407 function api:context(host)
408 return setmetatable({ host = host or "*", global = "*" == host }, { __index = self, __newindex = self }); 408 local is_global = host == "*";
409 if not is_global and not hosts[host] then
410 error("Cannot create context for unknown host: "..host);
411 end
412 return setmetatable({ host = host or "*", global = is_global }, { __index = self, __newindex = self });
409 end 413 end
410 414
411 function api:add_item(key, value) 415 function api:add_item(key, value)
412 self.items = self.items or {}; 416 self.items = self.items or {};
413 self.items[key] = self.items[key] or {}; 417 self.items[key] = self.items[key] or {};