Software /
code /
prosody
Changeset
1317:f6e56a555c37
mod_console: Allow running code in the global environment by prefixing with '>'
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 05 Jun 2009 20:18:55 +0100 |
parents | 1316:28ae044f1aaf |
children | 1318:66f76c332a75 1323:e1bfe7816761 |
files | plugins/mod_console.lua |
diffstat | 1 files changed, 9 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/mod_console.lua Fri Jun 05 20:18:19 2009 +0100 +++ b/plugins/mod_console.lua Fri Jun 05 20:18:55 2009 +0100 @@ -56,6 +56,8 @@ 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 @@ return; end end + + if data:match("^>") then + data = data:gsub("^>", ""); + useglobalenv = true; + end session.env._ = data; @@ -79,7 +86,8 @@ 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