comparison core/moduleapi.lua @ 13912:a0faff6ba853

moduleapi: Fix traceback when no host passed to :context() (thanks Menel, riau) I don't particularly like this, but it seems to be depended on and I don't plan to break the API at this time.
author Matthew Wild <mwild1@gmail.com>
date Thu, 03 Jul 2025 10:59:17 +0100
parents 622790951285
children cf21d285385b
comparison
equal deleted inserted replaced
13911:79ae4821c05e 13912:a0faff6ba853
410 end 410 end
411 return value; 411 return value;
412 end 412 end
413 413
414 function api:context(host) 414 function api:context(host)
415 local is_global = host == "*"; 415 local is_global;
416 if not host or host == "*" then
417 host, is_global = "*", true;
418 end
416 if not is_global and not hosts[host] then 419 if not is_global and not hosts[host] then
417 error("Cannot create context for unknown host: "..host); 420 error("Cannot create context for unknown host: "..host);
418 end 421 end
419 return setmetatable({ host = host or "*", global = is_global }, { __index = self, __newindex = self }); 422 return setmetatable({ host = host, global = is_global }, { __index = self, __newindex = self });
420 end 423 end
421 424
422 function api:add_item(key, value) 425 function api:add_item(key, value)
423 self.items = self.items or {}; 426 self.items = self.items or {};
424 self.items[key] = self.items[key] or {}; 427 self.items[key] = self.items[key] or {};