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

Gammon Forum

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

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  AddTrigger parsing escaped characters
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

AddTrigger parsing escaped characters

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


Posted by Rollanz   (8 posts)  [Biography] bio
Date Sun 17 Aug 2014 04:23 PM (UTC)

Amended on Sun 17 Aug 2014 08:09 PM (UTC) by Nick Gammon

Message
I am trying to make an alias for highlighting names using AddTrigger function. However, the AddTrigger function is parsing [[\b]] string that I'm using to delimit the words. The code I'm using is below.


blank=[[\b]]
highlightFormat=blank.."%1"..blank
triggerName="%1".."Highlight"

AddTrigger(triggerName, highlightFormat, "", trigger_flag.Enabled+trigger_flag.RegularExpression+trigger_flag.KeepEvaluating+trigger_flag.IgnoreCase+trigger_flag.Replace, custom_colour.Custom3, 0, "", "")


What I'm trying to get is a trigger along the lines of "\bRollanz\b"

What's I'm getting instead:
Rollanz Something not displayable on the forum.

Thanks in advance.
[Go to top] top

Posted by Nick Gammon   Australia  (21,674 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sun 17 Aug 2014 08:12 PM (UTC)
Message
Template:version Please help us by advising the version of MUSHclient you are using. Use the Help menu -> About MUSHclient.


I can't reproduce that.

In the Immediate window I tried:


blank=[[\b]]
highlightFormat=blank.."foo"..blank
triggerName="foo".."Highlight"

check (AddTrigger(triggerName, highlightFormat, "", trigger_flag.Enabled+trigger_flag.RegularExpression+trigger_flag.KeepEvaluating+trigger_flag.IgnoreCase+trigger_flag.Replace, custom_colour.Custom3, 0, "", ""))


The resulting trigger was:


<triggers>
  <trigger
   custom_colour="3"
   enabled="y"
   ignore_case="y"
   keep_evaluating="y"
   match="\bfoo\b"
   name="fooHighlight"
   regexp="y"
   sequence="100"
   variable="fooHighlight"
  >
  </trigger>
</triggers>


So it looks like it worked OK.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (21,674 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Sun 17 Aug 2014 10:04 PM (UTC)

Amended on Sun 17 Aug 2014 10:05 PM (UTC) by Nick Gammon

Message
See: http://www.gammon.com.au/scripts/doc.php?dialog=IDD_PREFS_P9

Scroll down to: Translate Backslash Sequences

Maybe the \b is being turned into a backspace, so try making it: \\b

- Nick Gammon

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

Posted by Rollanz   (8 posts)  [Biography] bio
Date Reply #3 on Sun 17 Aug 2014 11:40 PM (UTC)
Message
[[\\b]] worked, and it was the only combination of \ and [ and " I hadn't tried yet.

A couple of curious observations:
1) I did not have the "translate backslash sequences" box checked, and checking/unchecking it did not seem to make a difference to the resulting trigger.

2) "\\b" did not while [[\\b]] did.

Could me having language for non-unicode programs set to English(Canada) have something to do with the unusual result?
[Go to top] top

Posted by Nick Gammon   Australia  (21,674 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Mon 18 Aug 2014 04:10 AM (UTC)

Amended on Mon 18 Aug 2014 04:12 AM (UTC) by Nick Gammon

Message
I wouldn't think Unicode is the problem.

Your non-printable characters in your first post are indeed 0x08 characters, that is, backspace.

The option "translate backslash sequences" only applies to the command window, not to the Send box in triggers/aliases which unconditionally translate them. This can be annoying because it means in Lua you then need to double the backslashes, or even quadruple them if you use normal Lua strings, eg.


"\\\\b" 


This is because the MUSHclient processing converts that to:



"\\b" 


And then Lua string processing converts it to:


"\b" 


Except that in the square brackets backslashes are ignored by Lua, so you don't need to quadruple them, only double them.

If you use a script file (and put the function name in the script box) then you drop down to normal Lua behaviour, which halves the number of backslashes needed.

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


2,673 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]