plugins/mod_console.lua

changeset 3407
15f633285755
parent 3404
33c81ee280e3
child 3452
2d1a5d8893c2
--- a/plugins/mod_console.lua	Mon Jul 26 01:12:52 2010 +0500
+++ b/plugins/mod_console.lua	Mon Jul 26 01:52:04 2010 +0500
@@ -27,7 +27,13 @@
 prosody.console = { commands = commands, env = def_env };
 
 local function redirect_output(_G, session)
-	return setmetatable({ print = session.print }, { __index = function (t, k) return rawget(_G, k); end, __newindex = function (t, k, v) rawset(_G, k, v); end });
+	local env = setmetatable({ print = session.print }, { __index = function (t, k) return rawget(_G, k); end, __newindex = function (t, k, v) rawset(_G, k, v); end });
+	env.dofile = function(name)
+		local f, err = loadfile(name);
+		if not f then return f, err; end
+		return setfenv(f, env)();
+	end;
+	return env;
 end
 
 console = {};

mercurial