From 7305c4cccc89374d3b8f66be5d095506037d80c4 Mon Sep 17 00:00:00 2001 From: Gordon Hecker Date: Thu, 18 Jun 2009 20:39:27 +0200 Subject: [PATCH] plugin support: allow plugins to extend the scm interface, allow plugins to extend the scm implementations Signed-off-by: Gordon Hecker --- local/e2scm.lua | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/local/e2scm.lua b/local/e2scm.lua index bacd6c0..d10d71f 100644 --- a/local/e2scm.lua +++ b/local/e2scm.lua @@ -65,7 +65,6 @@ function e2scm.register(scm, t) t = t or {} t.name = scm scms[ scm ] = t - setmetatable(t, scmmt) return t end @@ -383,3 +382,39 @@ function scm.has_working_copy(info, sourcename) end return true, nil end + +--- register a new scm interface +-- @param name string: interface name +-- @param func function: interface function +-- @return bool +-- @return an error object on failure +function scm.register_interface(name, func) + local e = new_error("registering scm interface failed") + if scm[name] then + return false, e:append( + "interface with that name exists: %s", name) + end + scm[name] = func + return true, nil +end + +--- register a new scm function (accessible through a scm interface) +-- @param type string: scm type +-- @param name string: interface name +-- @param func function: interface function +-- @return bool +-- @return an error object on failure +function scm.register_function(type, name, func) + local e = new_error("registering scm function failed") + if not e2scm[type] then + return false, e:append("no scm type by that name: %s", type) + end + if not scm[name] then + return false, e:append("no scm interface by that name: %s", name) + end + if e2scm[type][name] then + return false, e:append("scm function exists: %s.%s", type, name) + end + scms[type][name] = func + return true, nil +end -- 2.39.5