# HG changeset patch # User Matthew Wild # Date 1342976459 -3600 # Node ID bfc52b9137c8ea7605e3ebe34e9d00306cc107d2 # Parent eeff012248654bede9eba1e8792d422f0ee5960b mod_admin_telnet: Replace anonymous function with loop (saves a closure) diff -r eeff01224865 -r bfc52b9137c8 plugins/mod_admin_telnet.lua --- a/plugins/mod_admin_telnet.lua Sun Jul 22 17:08:09 2012 +0100 +++ b/plugins/mod_admin_telnet.lua Sun Jul 22 18:00:59 2012 +0100 @@ -76,22 +76,22 @@ function console_listener.onincoming(conn, data) local session = sessions[conn]; - -- Handle data - (function(session, data) + -- Handle data (loop allows us to break to add \0 after response) + repeat local useglobalenv; - + if data:match("^>") then data = data:gsub("^>", ""); useglobalenv = true; elseif data == "\004" then commands["bye"](session, data); - return; + break; else local command = data:lower(); command = data:match("^%w+") or data:match("%p"); if commands[command] then commands[command](session, data); - return; + break; end end @@ -106,7 +106,7 @@ err = err:gsub("^:%d+: ", ""); err = err:gsub("''", "the end of the line"); session.print("Sorry, I couldn't understand that... "..err); - return; + break; end end @@ -116,26 +116,26 @@ if not (ranok or message or useglobalenv) and commands[data:lower()] then commands[data:lower()](session, data); - return; + break; end if not ranok then session.print("Fatal error while running command, it did not complete"); session.print("Error: "..taskok); - return; + break; end if not message then session.print("Result: "..tostring(taskok)); - return; + break; elseif (not taskok) and message then session.print("Command completed with a problem"); session.print("Message: "..tostring(message)); - return; + break; end session.print("OK: "..tostring(message)); - end)(session, data); + until true session.send(string.char(0)); end