mSLChampagne commented on a Page, mIRC Arrays v3  -  Jan 16, 2011

Here, this differs from the last one I pasted in that I simplified it. It also has an example at the end of it to better show it's usage.

It does require that you have .NET 2.0 at least I believe, which is really standard to have these days. Unless you're using linux. :> If that's the case then COM will only work (and terribly I might add) through the use of WINE or some other similar emulation.

alias -l inherits if (!$com($1)) halt
alias -l object { if (!$com($2)) .comopen $2 $1 
  return $iif($com($2).progid == $1,$2,$null)
}

alias array { 

  ; REM ## Object initialization ##
  inherits $object(system.collections.arraylist,$1)

  ; REM ## Method handling ##
  if ($2 == sort    ) noop $com($1,sort,1)
  if ($2 == clear   ) noop $com($1,clear,1)
  if ($2 == append  ) noop $com($1,add,1,string,$3)
  if ($2 == remove  ) noop $com($1,remove,1,int,$3)
  if ($2 == insert  ) noop $com($1,insert,1,int,$3,string,$4)
  if ($2 == removeat) noop $com($1,removeat,1,int,$3)
  if ($2 == reverse ) noop $com($1,reverse,1)
  if ($2 == delete  ) .comclose $1

  ; REM ## Property handling ##
  if ($2 == item  ) return $null($com($1,item,3,int,$3)) $com($1).result
  if ($2 == count ) return $null($com($1,count,3)) $com($1).result
  if ($2 == exists) return $null($com($1,contains,3,string,$3)) $com($1).result

}

alias test { 

  var %a = example, %b = 10

  ; REM ## Create an array by the name of "example."
  noop $array(%a)

  ; REM ## Populate the array with some data.
  while (%b) {
    noop $array(%a,append,%b)
    dec %b
  }

  ; REM ## Reverse the array.
  noop $array(%a,reverse)
  linesep

  ; REM ## Enumerate and echo each item in the array.
  %b = 0
  while ($array(%a,item,%b)) { 
    echo -a Item %b $+ : $v1
    inc %b
  }
  linesep

  ; REM ## Determining the size and whether an item (data) exists or not.
  echo -a Count: $array(%a,count)
  linesep
  noop $array(%a,append,z)
  echo -a Exists("z"): $array(%a,exists,z)
  linesep

  ; REM ## Bit sorting the array is the built-in default method shown here.
  noop $array(%a,sort)
  %b = 0
  while ($array(%a,item,%b)) {
    echo -a Item %b $+ : $v1
    inc %b
  }
  linesep

  ; REM ## Clearing and deleting an array.
  noop $array(%a,clear)
  noop $array(%a,delete)

  ; REM ## End of test.
  echo -a End of test.
  linesep

}
 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.