From df5c3bcaafdc7b428adb9d0d0b2929e654855bae Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 5 Jun 2009 20:18:55 +0100 Subject: mod_console: Allow running code in the global environment by prefixing with '>' --- plugins/mod_console.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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 -- cgit v1.2.3