mod_console: Check for commands when not executing in the global environment
authorMatthew Wild <mwild1@gmail.com>
Thu, 9 Jul 2009 03:34:55 +0000 (04:34 +0100)
committerMatthew Wild <mwild1@gmail.com>
Thu, 9 Jul 2009 03:34:55 +0000 (04:34 +0100)
plugins/mod_console.lua

index 0d6b5e41e980144a879cade979c27273f475af8a..556f0c5d58b879bb7416422e811d4553875929ab 100644 (file)
@@ -65,7 +65,10 @@ function console_listener.listener(conn, data)
                (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 @@ function console_listener.listener(conn, data)
                                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 @@ function console_listener.listener(conn, data)
                        
                        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);