mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Dec 2002
Posts: 252
T
Talon Offline OP
Fjord artisan
OP Offline
Fjord artisan
T
Joined: Dec 2002
Posts: 252
quite often times if you need things not to evaluate, such as within a timer, you use $!<identifier>.

I think it would be handy for variables to also support this for cleaner, easier to follow code, without having to do like % $+ <varname> or $eval(%<varname>,0) or any other sorts to escape evaluation.

Example:
//var %a = 1 | echo -a %!a = %a

much like you'd quite often do something simple like
//echo -a $!ctime = $ctime

I do get however that this might break some scripts if for some bizarre reason someone uses %! as a variable, but I think that would be slim to none, and would only affect the usage of ! in a variable name from being the very start of the variable. like %a!b should still work, but not %!ab.

Joined: Dec 2008
Posts: 1,515
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,515
Nice idea +1


Need Online mIRC help or an mIRC Scripting Freelancer? -> https://irc.chathub.org <-
Joined: Feb 2003
Posts: 2,812
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
I think, as a backwards-y compatible-y solution... the handling of %!variable would look like this. (As pseudo-coded in mSL for clarity)

Code:
; where $1 is the word being parsed.

if ($left($1,1) == %) {
; this is a variable.

  if ($mid($1,2,1) == !) {
  ; this might be a variable name OR it might be a delayed evaluation.

    if ($var($1,1).local) {
    ; %!variable is a literal local variable name, so let's evaluate it without delay.
    ; (compatibility mode)
      return $eval($1,2)
    }

    elseif ($var($regsubex($1,/^%\K!+/,),1).local) {
    ; %variable (without !'s) is a known local variable, so let's delay evaluation
    ; by removing just one '!' from $1 (eg: from %!!!variable to %!!variable) (new mode)
      return $regsubex($1,/^%\K!/,)
    }

    elseif ($var($1,1).global) {
    ; %!variable is a literal global variable name, so let's evaluate it without
    ; delay. (compatibility mode)
      return $eval($1,2)
    }

    ; else { ; since no known (local or global) variables exist by this name
    ; (eg: %!!!variable) then let's treat it as a delayed evaluation.  (new mode)
    return $regsubex($1,/^%\K!/,)
    ; }
  }

  ; this is just a variable name without '!'.  so try to evaluate it. (as usual)
  return $eval($1,2)

}


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Dec 2002
Posts: 252
T
Talon Offline OP
Fjord artisan
OP Offline
Fjord artisan
T
Joined: Dec 2002
Posts: 252
That's a rather unique idea for backwards compatibility, but really the amount of afftected users would be significantly small, and the solution to anything broken would be a simple find and replace for each loaded script/alias/popup file to find %! and modify it to something else, say %^.

Further info about my topic: "!" has multiple usages already for an escape sequence, why not add it to variables as well?

$identifiers have $!identifier to escape evaluation.
/commands have /!command to escape using a defined alias of that name.

I think variables having %!variable would be a great addition to this already common syntax for escapes.

Figured i'd chime in on some more complex examples to demonstrate why this is useful.

which of these two look cleaner, and easier to follow?

//var %a 0 , %c 0 , %q 0 | scon -at1 var % $+ a % $+ a + 1 , % $+ c % $+ c + $!chan(0) , % $+ q % $+ q + $!query(0) | echo -a $+(%a,/,$scon(0)) active connections, %c Channels and %q Queries.

VS

//var %a 0 , %c 0 , %q 0 | scon -at1 var %!a %!a + 1 , %!c %!c + $!chan(0) , %!q %!q + $!query(0) | echo -a $+(%a,/,$scon(0)) active connections, %c Channels and %q Queries.


Link Copied to Clipboard