# HG changeset patch # User Matthew Wild # Date 1244229535 -3600 # Node ID f6e56a555c37a67ee834c9b399d6670d94973391 # Parent 28ae044f1aafd6c5da7b54562a5ad95515ef423b mod_console: Allow running code in the global environment by prefixing with '>' diff -r 28ae044f1aaf -r f6e56a555c37 plugins/mod_console.lua --- 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