incoming = {}
I can’t find anything about this because searches including ‘incoming’ brings up almost every troubleshooting page. It seems to be some form of builtin since it seems to populate from ‘s’ outside what’s written in the code.
That line sets up an empty table “incoming” which is used in processSequence.
s, count = string.gsub (s, REGEXP, processSequence)
This has a function call as what it’s supposed to replace with. wut? Especially since the function requires two arguments, which I don’t see passed?
The string.gsub call matches REGEXP (repeatedly) and for each match calls processSequence supplying as arguments the captures in the regexp (the parts in brackets). It returns an empty string, thus effectively removing the Batmud sequence from the incoming text. The arguments (code and args, which are in the brackets in the regexp) are added to the “incoming” table.
This form of the string.gsub lets you “replace” with a function call rather than a simple string. See http://www.gammon.com.au/scripts/doc.php?lua=string.gsub.
A modified example from that page:
result = string.gsub (s, "%a+", string.upper)
That would return “s” with every alphabetic character converted to upper case by calling the function string.upper.
if count > 0 then
Got it, if there are instances/replacements made above
Yes, if anything found.
for k, v in ipairs (incoming) do
I understand what this is saying to do, but I don’t understand how at this point ‘incoming’ has anything in it since it seems to have been initialized as a table and then left empty.
processSequence put things into incoming.
handleMessage (v.code, v.args)
Pretty straightforward function call, but I don’t understand where v.code and v.args are coming from because I don’t understand/know what ‘incoming’ has inside it.
See above explanation.
|