[Home] [Downloads] [Search] [Help/forum]

Log on
Register forum user name Search FAQ

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Plugins
. . -> [Subject]  working with custom control codes (continued)

working with custom control codes (continued)

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Tlaco   (1 post)  [Biography] bio
Date Mon 14 Dec 2020 05:57 PM (UTC)

Amended on Mon 14 Dec 2020 09:04 PM (UTC) by Tlaco

Message
I have a fairly introductory knowledge of programming and mostly work through google, copying stuff, and poking it until it does what I want. This works much better with things that I can at least get to work a little.

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 packet


Does 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.
[Go to top] top

Posted by Nick Gammon   Australia  (22,556 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Mon 14 Dec 2020 11:09 PM (UTC)

Amended on Mon 14 Dec 2020 11:10 PM (UTC) by Nick Gammon

Message
 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.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


575 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]