diff options
Diffstat (limited to 'plugins')
-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); |