mod_console: Check for commands when not executing in the global environment

Thu, 09 Jul 2009 04:34:55 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Thu, 09 Jul 2009 04:34:55 +0100
changeset 1502
0f895c06e03f
parent 1501
330b8437ac35
child 1503
5970e06d9335

mod_console: Check for commands when not executing in the global environment

plugins/mod_console.lua file | annotate | diff | comparison | revisions
--- a/plugins/mod_console.lua	Wed Jul 08 16:53:59 2009 +0100
+++ b/plugins/mod_console.lua	Thu Jul 09 04:34:55 2009 +0100
@@ -65,7 +65,10 @@
 		(function(session, data)
 			local useglobalenv;
 			
-			if data:match("[!.]$") then
+			if data:match("^>") then
+				data = data:gsub("^>", "");
+				useglobalenv = true;
+			else
 				local command = data:lower();
 				command = data:match("^%w+") or data:match("%p");
 				if commands[command] then
@@ -74,11 +77,6 @@
 				end
 			end
 
-			if data:match("^>") then
-				data = data:gsub("^>", "");
-				useglobalenv = true;
-			end
-			
 			session.env._ = data;
 			
 			local chunk, err = loadstring("return "..data);
@@ -97,6 +95,11 @@
 			
 			local ranok, taskok, message = pcall(chunk);
 			
+			if not (ranok or message or useglobalenv) and commands[data:lower()] then
+				commands[data:lower()](session, data);
+				return;
+			end
+			
 			if not ranok then
 				session.print("Fatal error while running command, it did not complete");
 				session.print("Error: "..taskok);

mercurial