mIRC Home    About    Download    Register    News    Help

Print Thread
How to pass a dynamic set of parameters to alias #268885 11/05/21 03:32 PM
Joined: Jan 2009
Posts: 21
I
Imk0tter Offline OP
Ameglian cow
OP Offline
Ameglian cow
I
Joined: Jan 2009
Posts: 21
//noop $example(this,is,a,test,this2,is2,a2,test2)

Code
alias example {
  ;inputs:
 ;any number of inputs / 4

  var %astart $iif($hget(MAKETOK, COUNT),$v1,0)
  maketok MAKETOK V MAKETOKTEST
  maketok MAKETOK V $str(TEST., $floor($calc($0 / 4)))
  var %aend $iif($hget(MAKETOK, COUNT),$v1,0)

  var %bstart $iif($hget(MAKETOK, COUNT),$v1,0)
  maketok MAKETOK V OBJECT_REFERENCE
  var %bend $iif($hget(MAKETOK, COUNT),$v1,0)

  var %cstart $iif($hget(MAKETOK,COUNT),$v1,0) + 1
  maketok MAKETOK V $*
  var %cend $iif($hget(MAKETOK,COUNT),$v1,0)

  return $meval(MAKETOK,%astart,%aend,%bstart,%bend,%cstart,%cend)
}

alias mprop {
  return $iif($2,$token($1,2-,46),$token($1,1,46))
}
alias maketok {
  hinc -m $1 COUNT
  hadd -m $+ $iif($2 == B,b) $1 $hget($1,COUNT) $3-
}
alias meval {
  var %tokentable $1

  var %astart $2 + 1
  var %aend $3
  var %acount $calc(%aend - %astart + 1)

  var %bstart $4 + 1
  var %bend $5
  var %bcount $calc(%bend - %bstart + 1)

  var %cstart $6
  var %cend $$7
  var %ccount $calc(%cend - %cstart + 1)

  var %aregex $regsubex($str(.,%acount),/(.)/g,$+($,hget,$chr(40),%tokentable,$chr(44),$calc(\n + %astart - 1),$chr(41),$chr(35)))
  var %bregex $regsubex($str(.,%bcount),/(.)/g,$+($,hget,$chr(40),%tokentable,$chr(44),$calc(\n + %bstart - 1),$chr(41),$chr(35)))
  var %cregex $regsubex($str(.,%ccount),/(.)/g,$+($,hget,$chr(40),%tokentable,$chr(44),$calc(\n + %cstart - 1),$chr(41),$chr(35)))
  
  tokenize 35 %aregex

  var %function [ [ $1 ] ]
  var %prop [ [ $2 ] ]

  var %regex $+($,%function,.,$mprop(%prop),$chr(40),$replace(%bregex %cregex,$chr(35),$chr(32) $chr(44) $chr(32)),$chr(41),.,$mprop(%prop,1))


  return [ [ %regex ] ]
}
;;;;;;;;;;;;;;;;;;;;;;;;
; END HELPER FUNCTIONS ;
;;;;;;;;;;;;;;;;;;;;;;;;


alias MAKETOKTEST.TEST {
  var %object $1

  echo -a -TEST-
  echo -a OBJECT: %object
  echo -a  $+ $2 @ $3
  echo -a  $+ $4 @ $5
  echo -a -END TEST-

  if $prop {
    var %astart $iif($hget(MAKETOK,COUNT),$v1,0)
    maketok MAKETOK V maketoktest
    maketok MAKETOK V $prop
    var %aend $iif($hget(MAKETOK,COUNT),$v1,0)

    var %bstart $iif($hget(MAKETOK,COUNT),$v1,0)
    maketok MAKETOK V %object
    var %bend $iif($hget(MAKETOK,COUNT),$v1,0)

    var %cstart $iif($hget(MAKETOK,COUNT),$v1,0) + 6
    maketok MAKETOK V $*
    var %cend $iif($hget(MAKETOK,COUNT),$v1,0)

    echo -a TOKEN-COUNT $0 : A-START: %astart A-END: %aend B-START: %bstart B-END: %bend C-START: %cstart CEND: %cend
    return $meval(MAKETOK,%astart,%aend,%bstart,%bend,%cstart,%cend)
  }
  if ($hget(MAKETOK)) hfree MAKETOK
}
;;;;;;;;;;;;;;;;;;;;;;
; END TEST FUNCTIONS ;
;;;;;;;;;;;;;;;;;;;;;;

Last edited by Imk0tter; 11/05/21 08:51 PM.
Re: How to pass a dynamic set of parameters to alias [Re: Imk0tter] #268892 11/05/21 09:33 PM
Joined: Jan 2009
Posts: 21
I
Imk0tter Offline OP
Ameglian cow
OP Offline
Ameglian cow
I
Joined: Jan 2009
Posts: 21
Code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Code for passing dynamic variables to the $meval function ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;      var %astart $iif($hget(MAKETOK, COUNT),$v1,0)         ; For passing variables to the $meval function (or your own function)                      ;
;      maketok MAKETOK V ClassName                           ;                                                                                          ;
;      maketok MAKETOK V $prop                               ;                                                                                          ;
;      var %aend $iif($hget(MAKETOK, COUNT),$v1,0)           ;                                                                                          ;
;                                                            ;                                                                                          ;
;      var %bstart $iif($hget(MAKETOK, COUNT),$v1,0)         ; For passing variables before the $N- tokens are passed (any number of variables allowed  ;
;      maketok MAKETOK V SomeValue                           ;    these variables will be before the $N- tokens.                                        ;
;      maketok MAKETOK V SomeValue2                          ;                                                                                          ;
;      var %bend $iif($hget(MAKETOK, COUNT),$v1,0)           ;                                                                                          ;
;                                                            ;                                                                                          ;
;      var %cstart $iif($hget(MAKETOK,COUNT),$v1,0) + 1      ; Starting token number (if trying to pass $2- to a function you put + 2 instead of  +1    ; 
;      maketok MAKETOK V $*                                  ;    (which is for tokens $1-)                                                             ;
;      var %cend $iif($hget(MAKETOK,COUNT),$v1,0)            ;                                                                                          ;
;                                                           ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;             
;      return $meval(MAKETOK,%astart,%aend,%bstart,%bend,%cstart,%cend) ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;alias example {
  ;inputs:
 ;any number of inputs / 4

  var %astart $iif($hget(MAKETOK, COUNT),$v1,0)
  maketok MAKETOK V MAKETOKTEST
  maketok MAKETOK V $str(TEST., $floor($calc($0 / 4)))
  var %aend $iif($hget(MAKETOK, COUNT),$v1,0)

  var %bstart $iif($hget(MAKETOK, COUNT),$v1,0)
  maketok MAKETOK V OBJECT_REFERENCE
  var %bend $iif($hget(MAKETOK, COUNT),$v1,0)

  var %cstart $iif($hget(MAKETOK,COUNT),$v1,0) + 1
  maketok MAKETOK V $*
  var %cend $iif($hget(MAKETOK,COUNT),$v1,0)

  return $meval(MAKETOK,%astart,%aend,%bstart,%bend,%cstart,%cend)
}

alias mprop {
  return $iif($2,$token($1,2-,46),$token($1,1,46))
}
alias maketok {
    hinc -m $1 COUNT
    hadd -m $+ $iif($2 == B,b) $1 $hget($1,COUNT) $3-
}
alias meval {
  var %tokentable $1

  var %astart $2 + 1
  var %aend $3
  var %acount $calc(%aend - %astart + 1)

  var %bstart $4 + 1
  var %bend $5
  var %bcount $calc(%bend - %bstart + 1)

  var %cstart $6
  var %cend $$7
  var %ccount $calc(%cend - %cstart + 1)

  var %aregex $regsubex($str(.,%acount),/(.)/g,$+($,hget,$chr(40),%tokentable,$chr(44),$calc(\n + %astart - 1),$chr(41),$chr(35)))
  var %bregex $regsubex($str(.,%bcount),/(.)/g,$+($,hget,$chr(40),%tokentable,$chr(44),$calc(\n + %bstart - 1),$chr(41),$chr(35)))
  var %cregex $regsubex($str(.,%ccount),/(.)/g,$+($,hget,$chr(40),%tokentable,$chr(44),$calc(\n + %cstart - 1),$chr(41),$chr(35)))
  
  tokenize 35 %aregex

  var %function [ [ $1 ] ]
  var %prop [ [ $2 ] ]

  var %regex $+($,%function,.,$mprop(%prop),$chr(40),$replace(%bregex %cregex,$chr(35),$chr(32) $chr(44) $chr(32)),$chr(41),.,$mprop(%prop,1))


  return [ [ %regex ] ]
}
;;;;;;;;;;;;;;;;;;;;;;;;
; END HELPER FUNCTIONS ;
;;;;;;;;;;;;;;;;;;;;;;;;


alias MAKETOKTEST.TEST {
  var %object $1

  echo -a -TEST-
  echo -a OBJECT: %object
  echo -a  $+ $2 @ $3
  echo -a  $+ $4 @ $5
  echo -a -END TEST-

  if $prop {
    var %astart $iif($hget(MAKETOK,COUNT),$v1,0)
    maketok MAKETOK V maketoktest
    maketok MAKETOK V $prop
    var %aend $iif($hget(MAKETOK,COUNT),$v1,0)

    var %bstart $iif($hget(MAKETOK,COUNT),$v1,0)
    maketok MAKETOK V %object
    var %bend $iif($hget(MAKETOK,COUNT),$v1,0)

    var %cstart $iif($hget(MAKETOK,COUNT),$v1,0) + 6
    maketok MAKETOK V $*
    var %cend $iif($hget(MAKETOK,COUNT),$v1,0)

    echo -a TOKEN-COUNT $0 : A-START: %astart A-END: %aend B-START: %bstart B-END: %bend C-START: %cstart CEND: %cend
    return $meval(MAKETOK,%astart,%aend,%bstart,%bend,%cstart,%cend)
  }
  if ($hget(MAKETOK)) hfree MAKETOK
}
;;;;;;;;;;;;;;;;;;;;;;
; END TEST FUNCTIONS ;
;;;;;;;;;;;;;;;;;;;;;;

Last edited by Imk0tter; 12/05/21 12:33 AM.
Re: How to pass a dynamic set of parameters to alias [Re: Imk0tter] #268910 13/05/21 11:16 PM
Joined: Jan 2009
Posts: 21
I
Imk0tter Offline OP
Ameglian cow
OP Offline
Ameglian cow
I
Joined: Jan 2009
Posts: 21
Code
alias mevaltest {

  var %astart $MAKETOKCOUNT
  MAKETOK Some
  MAKETOK TEST:SOME:PARAMETERS:PLEASE. $+ $prop
  MAKETOK MSL++_1
  MAKETOK $false
  var %aend $MAKETOKCOUNT

  var %bstart $MAKETOKCOUNT
  MAKETOK MSL++_1
  MAKETOK VARIABLE1
  MAKETOK VALUE1
  MAKETOK MSL++_1
  MAKETOK VARIABLE2
  MAKETOK VALUE2
  var %bend $MAKETOKCOUNT

  var %cstart $MAKETOKCOUNT + 1
  MAKETOK $*
  var %cend $MAKETOKCOUNT
  return $meval(%astart,%aend,%bstart,%bend,%cstart,%cend)
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Code for passing dynamic variables to the $meval function ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;      var %astart $MAKETOKCOUNT         ; For passing variables to the $meval function (or your own function)                      ;
;      maketok MAKETOK V ClassName                           ;                                                                                          ;
;      maketok MAKETOK V $prop                               ;                                                                                          ;
;      var %aend $MAKETOKCOUNT           ;                                                                                          ;
;                                                            ;                                                                                          ;
;      var %bstart $MAKETOKCOUNT         ; For passing variables before the $N- tokens are passed (any number of variables allowed  ;
;      maketok MAKETOK V SomeValue                           ;    these variables will be before the $N- tokens.                                        ;
;      maketok MAKETOK V SomeValue2                          ;                                                                                          ;
;      var %bend $MAKETOKCOUNT           ;                                                                                          ;
;                                                            ;                                                                                          ;
;      var %cstart $MAKETOKCOUNT + 1      ; Starting token number (if trying to pass $2- to a function you put + 2 instead of  +1    ; 
;      maketok MAKETOK V $*                                  ;    (which is for tokens $1-)                                                             ;
;      var %cend $MAKETOKCOUNT            ;                                                                                          ;
;                                                           ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;             
;      return $meval(MAKETOK,%astart,%aend,%bstart,%bend,%cstart,%cend) ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
alias -l meval {
  var %astart $1
  var %aend $2
  var %acount %aend - %astart

  var %bstart $3
  var %bend $4
  var %bcount %bend - %bstart

  var %cstart $5 - 1
  var %cend $$6
  var %ccount %cend - %cstart

  var %localVariables

  var %x 1
  while %x <= %acount {
    var %y %x + %astart
    var %localVariables %localVariables $+ $chr(255) $+ $ $+ getmaketok $+ [ ( ] $+ %y $+ [ ) ]
    inc %x
  }

  tokenize 255 %localVariables

  var %class [ [ $1 ] ]
  var %prop [ [ $2 ] ]
  var %object [ [ $3 ] ]
  var %isObjectCall [ [ $4 ] ]

  var %header,%footer 

  var %x 1
  while %x <= %bcount {
    var %y %x + %bstart
    var %header %header $+ $chr(255) $+ $ $+ getmaketok $+ [ ( ] $+ %y $+ [ ) ]
    inc %x
  }

  var %x 1
  while %x <= %ccount {
    var %y %x + %cstart
    var %footer %footer $+ $chr(255) $+ $ $+ getmaketok $+ [ ( ] $+ %y $+ [ ) ]
    inc %x
  }

  var %eval,%endeval

  var %eval $ $+ %class $+ . $+ $fprop($mprop(%prop)) $+ [ ( ] $+ [ $fprop($mprop(%prop),2-) ] $+ [ , ]
  var %endeval [ ) ] $+ . $+ [ $mprop(%prop,1) ]

  ;;;;;;;;;;;;;;;;;
  ;if !%isObjectCall {
  ;  if $isPublic(%class,$fprop($mprop(%prop))) || ($isPrivate(%class,$fprop($mprop(%prop))) && $fprop($mprop(%prop)) == INIT) {
  ;    var %eval $ $+ %class $+ . $+ $fprop($mprop(%prop)) $+ [ ( ] $+ $fprop($mprop(%prop),2-) $+ [ , ]
  ;    var %endeval [ ) ] $+ . $+ [ $mprop(%prop,1) ]
  ;  }
  ;  else if $IsException(%class, $fprop($mprop(%prop))) {
  ;    var %eval $ $+ %class $+ .EXCEPTION. $+ $fprop($mprop(%prop)) $+ [ ( ] $+ $fprop($mprop(%prop),2-) $+ [ , ]
  ;    var %endeval [ ) ] $+ . $+ $mprop(%prop,1)
  ;  }
  ;  else {
  ;    if ($IsInstance(%obejct))  {
  ;      UNMAKETOK
  ;      return $catch(%object, NoOperation, $scriptline, $token($token($script,-1,96),1,46), $qt($fprop($mprop(%prop))) is not a public member of class $qt(%class))
  ;    }
  ;    else {
  ;      UNMAKETOK
  ;      return $catch(Class, NoOperation, $scriptline, $token($token($script,-1,96),1,46), $qt($fprop($mprop(%prop))) is not a public member of class $qt(%class)).class
  ;    }
  ;  }
  ;}
  ;else {
  ;  var %eval $ $+ OBJECT $+ [ ( ]
  ;  var %endeval [ ) ] $+ . $+ $prop
  ;}
  ;;;;;;;;;;;;;;;;;;

  tokenize 255 %header $+ %footer
  
  var %x 1
  while %x <= $0 {
    if %x == $0 {
      var %eval %eval $+ [ $ $+ [ %x ] ]
    }
    else {
      var %eval %eval $+ [ $ $+ [ %x ] ] $+ [ , ]
    }
    inc %x
  }  
  return [ [ %eval ] $+ [ %endeval ] ]
}
;;;;;;;;;;;;;
; End meval ;
;;;;;;;;;;;;;
alias -l MAKETOK {
  hinc -m MAKETOK COUNT
  hadd MAKETOK $hget(MAKETOK,COUNT) $1-
}

alias -l MAKETOKCOUNT {
  if $hget(MAKETOK,COUNT) {
    return $v1
  }
  return 0
}

alias -l UNMAKETOK {
  if ($hget(MAKETOK)) hfree MAKETOK
}

alias -l GETMAKETOK {
  return $hget(MAKETOK, $1)
}

alias -l Some.TEST {
  var %params $1
  var %object $2

  echo -a TEST BEGINNING
  var %x 1
  echo -a PROP: $prop
  while %x <= $0 {
    echo -a Token Number %x $+ : [ $ $+ [ %x ] ]
    inc %x
  }
  echo -a TEST END
  if $prop {
    var %astart $MAKETOKCOUNT
    MAKETOK Some
    MAKETOK $prop
    MAKETOK %object
    MAKETOK $false
    var %aend $MAKETOKCOUNT

    var %bstart $MAKETOKCOUNT
    MAKETOK %object
    var %bend $MAKETOKCOUNT

    var %cstart $MAKETOKCOUNT + 3
    MAKETOK $*
    var %cend $MAKETOKCOUNT

    return $meval(%astart,%aend,%bstart,%bend,%cstart,%cend)
  }
  UNMAKETOK
  return 1
}