Quote:
partial = string.gsub (partial, "(.-)\n",
function (line)
table.insert (t, line)
return ""
end)
partial = string.gsub (partial, "\r\n\027%[0m> ", "\n\027%[0m")
partial = string.gsub (partial, "\r\n> ", "\n")
No, once you have done the string.gsub, all the lines except the last partial one will be in the table "t", not in the string "partial", so doing a string.gsub on that won't achieve anything.
So now you have a table of lines, so you do your matches on that, eg.
partial = ""
function OnPluginPacketReceived (s)
-- get rid of carriage-returns
partial = partial .. string.gsub (s, "\r", "")
local t = {}
-- turn finished lines into table t
partial = string.gsub (partial, "(.-)\n",
function (line)
table.insert (t, line)
return ""
end)
-- get rid of prompts (in a regexp, ^ indicates the start of a line)
for i, line in ipairs (t) do
t [i] = string.gsub (line, "^\027%[0m> ", "\027%[0m")
t [i] = string.gsub (line, "^> ", "")
end -- for
-- reassemble completed packet with line-based corrections
local fixed_packet = ""
-- drop completely empty lines
for i, line in ipairs (t) do
if line ~= "" then
fixed_packet = fixed_packet .. line .. "\n"
end -- if
end -- for
return fixed_packet
end -- OnPluginPacketReceived
(Disclaimer: I didn't test or compile the above code).
Quote:
It doesn't actually display the query "Name:" and "Password:" until after I have already typed them in...
That is exactly what you expect to happen if you batch up lines until you get a newline character. You probably need to do nothing with the incoming packets until some flag is set to indicate you have finished the login sequence.
Or, use the "auto-login" function in MUSHclient which sends down the username and password as soon as you connect, so they will be supplied even if you don't see the question. |