Fri, 05 Jun 2009 20:18:55 +0100
mod_console: Allow running code in the global environment by prefixing with '>'
plugins/mod_console.lua | file | annotate | diff | comparison | revisions |
--- 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