Diff

plugins/mod_console.lua @ 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
parent 1316:28ae044f1aaf
child 1322:33d103b0283f
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