]> git.e2factory.org Git - e2factory.git/commitdiff
Use strict module, but allow plugins
authorTobias Ulmer <tu@emlix.com>
Tue, 4 Sep 2012 12:07:58 +0000 (14:07 +0200)
committerTobias Ulmer <tu@emlix.com>
Tue, 26 Feb 2013 18:07:09 +0000 (19:07 +0100)
Plugins needs permission to create a plugin_descriptor table in the
global environment. Permit this until we have extracted the necessary
information.

Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/plugin.lua

index 566573a2e5c347dcaba214e4bb1364ab5c3f8f4b..111952a8a91838ada7f6dca1c7096c38f574bd13 100644 (file)
@@ -29,6 +29,7 @@
 local plugin = {}
 local err = require("err")
 local e2lib = require("e2lib")
+local strict = require("strict")
 
 --- plugin descriptor
 -- @class table
@@ -82,6 +83,9 @@ local plugins = {}
 local function load_plugin(dir, p, ctx)
     local e = err.new("loading plugin failed: %s", p)
     local plugin_file = string.format("%s/%s", dir, p)
+
+    strict.declare(_G, {plugin_descriptor = {}})
+
     local chunk, msg = loadfile(plugin_file)
     if not chunk then
         return false, e:append("%s", msg)
@@ -92,6 +96,9 @@ local function load_plugin(dir, p, ctx)
         plugin_file)
     end
     local pd = plugin_descriptor
+
+    strict.undeclare(_G, {plugin_descriptor = {}})
+
     if type(pd.description) ~= "string" then
         e:append("description missing in plugin descriptor")
     end
@@ -241,6 +248,6 @@ function plugin.print_descriptions()
     end
 end
 
-return plugin
+return strict.lock(plugin)
 
 -- vim:sw=4:sts=4:et: