I've been working with the Batmud custom control codes to try and produce an interpreter. All my work so far has been based on this thread from several years ago, mostly in reference to the code from Reply 7: https://www.gammon.com.au/forum/?id=13873
As noted later in that thread, this doesn't work anywhere there's a local map - though at the moment my theory is that it has more to do with control codes spanning packets than with processing order since *everything* seems to come within control codes.
I believe I have at least a working understanding of what's happening in most of the functions, but the details of the function I'll paste below are beyond me.
function OnPluginPacketReceived (s)
incoming = { }
s, count = string.gsub (s, REGEXP, processSequence)
if count > 0 then
for k, v in ipairs (incoming) do
handleMessage (v.code, v.args)
end -- for each one
end -- some codes found
return s -- return fixed packet
end -- function OnPluginPacketReceived
> 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.
> 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?
> if count > 0 then
Got it, if there are instances/replacements made above
> 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.
> 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.
> ends
yupyup
> return s -- return fixed packet
This is another bit where I'm slightly confused. handleMessage pushes output to the screen within the handler functions. 's' hasn't actually been deleted, it's just been modified through gsub, but I haven't been noticing any duplicate information.
To keep all this in one place:
I'd like to rewrite the OnPluginPacketReceived function to look something like the pseudocode:
If there's anything in the packet buffer, concatenate to start of packet
Regex for first control code open tag
If that tag has a closure then
take what's between them as args
pass code,args to handler for output to screen
remove code open tag, args, code close tag from packet
Else
add remainder of packet to buffer
clear remainder of packet
If packet == "" then
return packetDoes that look like a workable solution? Is there a better way to do this?
Ultimately, once I have the interpreter working, I'd like to keep it standalone since I'd like to add multiple different GUI displays with the data gathered. I haven't had any luck finding a good way to exchange data between scripts, is there a go-to method for doing this? My only real education has been with Python and Java and the bit I've looked at Lua with everything being tables is quite different to me.