diff tools/migration/prosody-migrator.lua @ 5021:85b2689dbcfe

Eliminate direct setfenv usage
author Florian Zeitz <florob@babelmonkeys.de>
date Fri, 08 Jun 2012 05:04:38 +0200
parents b3d9063aad4d
children bd0ff8ae98a8
line wrap: on
line diff
--- a/tools/migration/prosody-migrator.lua	Thu Jun 07 23:27:26 2012 +0200
+++ b/tools/migration/prosody-migrator.lua	Fri Jun 08 05:04:38 2012 +0200
@@ -30,16 +30,22 @@
 end
 table.remove(arg, handled_opts);
 
+if CFG_SOURCEDIR then
+	package.path = CFG_SOURCEDIR.."/?.lua;"..package.path;
+	package.cpath = CFG_SOURCEDIR.."/?.so;"..package.cpath;
+else
+	package.path = "../../?.lua;"..package.path
+	package.cpath = "../../?.so;"..package.cpath
+end
+
+local envloadfile = require "util.envload".envloadfile;
+
 -- Load config file
 local function loadfilein(file, env)
 	if loadin then
 		return loadin(env, io.open(file):read("*a"));
 	else
-		local chunk, err = loadfile(file);
-		if chunk then
-			setfenv(chunk, env);
-		end
-		return chunk, err;
+		return envloadfile(file, env);
 	end
 end
 
@@ -59,14 +65,6 @@
 
 config_chunk();
 
-if CFG_SOURCEDIR then
-	package.path = CFG_SOURCEDIR.."/?.lua;"..package.path;
-	package.cpath = CFG_SOURCEDIR.."/?.so;"..package.cpath;
-elseif not package.loaded["util.json"] then
-	package.path = "../../?.lua;"..package.path
-	package.cpath = "../../?.so;"..package.cpath
-end
-
 local have_err;
 if #arg > 0 and #arg ~= 2 then
 	have_err = true;