Software /
code /
prosody
Changeset
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 |
parents | 3406:748246005893 |
children | 3408:e03fd9a16e19 |
files | plugins/mod_console.lua |
diffstat | 1 files changed, 7 insertions(+), 1 deletions(-) [+] |
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 = {};