Software /
code /
prosody
Diff
plugins/mod_console.lua @ 3407:15f633285755
mod_console: Override dofile() in the console environment (this lets print() print to the console session for example).
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Mon, 26 Jul 2010 01:52:04 +0500 |
parent | 3404:33c81ee280e3 |
child | 3452:2d1a5d8893c2 |
line wrap: on
line diff
--- 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 = {};