Comparison

util/pubsub.lua @ 9117:a19fdc6e4f09

util.pubsub: Apply defaults metatable before config check (thanks pep.) Makes it so that the callback sees the default if it’s not in the form, which makes it easier to validate.
author Kim Alvefur <zash@zash.se>
date Sun, 05 Aug 2018 15:17:00 +0200
parent 9107:6e42ef9c805c
child 9129:7721794e9e93
comparison
equal deleted inserted replaced
9116:9f36f5c14545 9117:a19fdc6e4f09
563 local node_obj = self.nodes[node]; 563 local node_obj = self.nodes[node];
564 if not node_obj then 564 if not node_obj then
565 return false, "item-not-found"; 565 return false, "item-not-found";
566 end 566 end
567 567
568 setmetatable(new_config, {__index=self.node_defaults})
569
568 if self.config.check_node_config then 570 if self.config.check_node_config then
569 local ok = self.config.check_node_config(node, actor, new_config); 571 local ok = self.config.check_node_config(node, actor, new_config);
570 if not ok then 572 if not ok then
571 return false, "not-acceptable"; 573 return false, "not-acceptable";
572 end 574 end
573 end 575 end
574 576
575 local old_config = node_obj.config; 577 local old_config = node_obj.config;
576 node_obj.config = setmetatable(new_config, {__index=self.node_defaults}); 578 node_obj.config = new_config;
577 579
578 if self.config.nodestore then 580 if self.config.nodestore then
579 local ok, err = save_node_to_store(self, node_obj); 581 local ok, err = save_node_to_store(self, node_obj);
580 if not ok then 582 if not ok then
581 node_obj.config = old_config; 583 node_obj.config = old_config;