Changeset

8500:9bf00d0734c8

util.pubsub: For clarity, split config tables from their metatables
author Matthew Wild <mwild1@gmail.com>
date Thu, 01 Feb 2018 15:09:04 +0000
parents 8499:549361c68f5a
children 8501:8d9e2c2095dd
files util/pubsub.lua
diffstat 1 files changed, 9 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/util/pubsub.lua	Sat Dec 30 22:57:55 2017 +0100
+++ b/util/pubsub.lua	Thu Feb 01 15:09:04 2018 +0000
@@ -4,22 +4,25 @@
 local service = {};
 local service_mt = { __index = service };
 
-local default_config = { __index = {
+local default_config = {
 	itemstore = function (config, _) return cache.new(config["max_items"]) end;
 	broadcaster = function () end;
 	get_affiliation = function () end;
 	capabilities = {};
-} };
-local default_node_config = { __index = {
+};
+local default_config_mt = { __index = default_config };
+
+local default_node_config = {
 	["persist_items"] = false;
 	["max_items"] = 20;
-} };
+};
+local default_node_config_mt = { __index = default_node_config };
 
 local function new(config)
 	config = config or {};
 	return setmetatable({
-		config = setmetatable(config, default_config);
-		node_defaults = setmetatable(config.node_defaults or {}, default_node_config);
+		config = setmetatable(config, default_config_mt);
+		node_defaults = setmetatable(config.node_defaults or {}, default_node_config_mt);
 		affiliations = {};
 		subscriptions = {};
 		nodes = {};