diff options
author | Matthew Wild <mwild1@gmail.com> | 2009-06-05 20:18:55 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2009-06-05 20:18:55 +0100 |
commit | df5c3bcaafdc7b428adb9d0d0b2929e654855bae (patch) | |
tree | 399a87771f52d094411366fc81518b6c87c1e4be | |
parent | b4318db1757e1080ca117918dee022c4ce209c71 (diff) | |
download | prosody-df5c3bcaafdc7b428adb9d0d0b2929e654855bae.tar.gz prosody-df5c3bcaafdc7b428adb9d0d0b2929e654855bae.zip |
mod_console: Allow running code in the global environment by prefixing with '>'
-rw-r--r-- | plugins/mod_console.lua | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/plugins/mod_console.lua b/plugins/mod_console.lua index bae106fd..c676c0eb 100644 --- a/plugins/mod_console.lua +++ b/plugins/mod_console.lua @@ -56,6 +56,8 @@ function console_listener.listener(conn, data) if data then -- Handle data (function(session, data) + local useglobalenv; + if data:match("[!.]$") then local command = data:lower(); command = data:match("^%w+") or data:match("%p"); @@ -64,6 +66,11 @@ function console_listener.listener(conn, data) return; end end + + if data:match("^>") then + data = data:gsub("^>", ""); + useglobalenv = true; + end session.env._ = data; @@ -79,7 +86,8 @@ function console_listener.listener(conn, data) end end - setfenv(chunk, session.env); + setfenv(chunk, (useglobalenv and _G) or session.env or nil); + local ranok, taskok, message = pcall(chunk); if not ranok then |