From 78081f067f057c5787b0a2884f06353bce68091c Mon Sep 17 00:00:00 2001 From: Tobias Ulmer Date: Wed, 26 Jun 2019 16:56:25 +0200 Subject: [PATCH] source: provide deregister_source_class() for unloading plugins Signed-off-by: Tobias Ulmer --- local/source.lua | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/local/source.lua b/local/source.lua index ad51c10..7e76764 100644 --- a/local/source.lua +++ b/local/source.lua @@ -338,7 +338,7 @@ function source.register_source_class(typ, source_class) assert(type(source_class) == "table") if source_types[typ] then - return false, err.new("source %q already registered", typ) + return false, err.new("source class %q already registered", typ) end source_types[typ] = source_class @@ -346,6 +346,24 @@ function source.register_source_class(typ, source_class) return true end +--- Deregister a source class. +-- @param typ Source type name. +-- @param source_class Class derived from basic_source. +-- @return True on success, false on error. +-- @return Error object on failure. +function source.deregister_source_class(typ, source_class) + assert(type(typ) == "string" and typ ~= "") + assert(type(source_class) == "table") + + if source_types[typ] == nil then + return false, err.new("source class %q not registered", typ) + end + + source_types[typ] = nil + + return true +end + --- Iterate over registered source classes. -- @return Iterator function that returns a sorted typ, source class pair. function source.iterate_source_classes() -- 2.39.5