diff options
author | Matthew Wild <mwild1@gmail.com> | 2009-06-12 15:43:24 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2009-06-12 15:43:24 +0100 |
commit | 5d8c612e5c71f4deb1b9e8c13f412a0868dfebd9 (patch) | |
tree | 2bcaea72719e30f1ee26e1bb853d34243532bbf8 /plugins/mod_console.lua | |
parent | 3462f03de8b3346c28aa55d8b86cfa55ccfe8004 (diff) | |
download | prosody-5d8c612e5c71f4deb1b9e8c13f412a0868dfebd9.tar.gz prosody-5d8c612e5c71f4deb1b9e8c13f412a0868dfebd9.zip |
mod_console: Redirect print() to console session when executing commands in global environment
Diffstat (limited to 'plugins/mod_console.lua')
-rw-r--r-- | plugins/mod_console.lua | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/plugins/mod_console.lua b/plugins/mod_console.lua index a975ca70..9be37db4 100644 --- a/plugins/mod_console.lua +++ b/plugins/mod_console.lua @@ -8,6 +8,8 @@ module.host = "*"; +local _G = _G; + local prosody = _G.prosody; local hosts = prosody.hosts; local connlisteners_register = require "net.connlisteners".register; @@ -21,6 +23,10 @@ local commands = {}; local def_env = {}; local default_env_mt = { __index = 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 }); +end + console = {}; function console:new_session(conn) @@ -86,7 +92,7 @@ function console_listener.listener(conn, data) end end - setfenv(chunk, (useglobalenv and _G) or session.env or nil); + setfenv(chunk, (useglobalenv and redirect_output(_G, session)) or session.env or nil); local ranok, taskok, message = pcall(chunk); |