Author: Infogulch Last Modified: nonexistent
There have been requests for real arrays in ahk for a long time, and people have come up with several not to shabby solutions by putting the array in one var. (e.g. AHKA, SimpleArray) But for several (good) reasons, some don't want to use those, and instead choose to use AHK's psuedo arrays.
Psuedo arrays are OK, but they're limited. There are some things that psuedo-arrays just can't do, like passing an array as a func param. Other things are just a big pain and give people headaches, like inserting or removing an element in an array. (not overwriting and clearing) What I present here is a way to alleviate these headaches.
pgArray_Insert( ArrayName, Idx, p1, p2="", p3="", p4="", p5="" )
pgArray_Rotate( ArrayName, FromIdx, ToIdx )
pgArray_Shift( ArrayName, Idx=1, HowFar=1 )
pgArray_Swap( ByRef Var1, ByRef Var2 )
For more details of the functions's parameters and return value, please see it's source code or the document.
The documentation is copied part from author`s forum post about the library.
This library works extensively with global variables only, as it is exactly designed for. Thats why it is not strictly stdlib conform.
For update's details and remarks related to the functions, please see the AutoHotkey Forum: http://www.autohotkey.com/forum/viewtopic.php?t=36072
The functions is an open source item under the infogulch`s license license. For details, please see infogulch-license.txt
; #Include pgArray.ahk #NoEnv SendMode Input SetWorkingDir %A_ScriptDir% ; Note that there are some more examples at the bottom of the code above #SingleInstance, Force GoSub SetVars ;inserting to a specific index: pgArray_Insert("Array", 3, "Inserted starting @ 3", "another string"), Display("Inserting:") ;removing an element: pgArray_Shift("Array", 3), Display("Removing #3:") ;shifting 5 to 2 pgArray_Rotate( "Array", 5, 2), Display("Rotated 5 to 2:") ;popping the last element: pgArray_Shift( "Array", -1 ), Display("popped the last element:") ;inserting several elements at the end: pgArray_Insert("Array", 0, "Added to end", "added more"), Display("added to end") return SetVars: Array0=7 Array1=one Array2=two Array3=three Array4=four Array5=five Array6=six Array7=seven Return Display(x) { ;demonstration script specific - Infogulch local Info Info := x "`n" Loop % Array0 Info .= A_Index ":`t" Array%A_Index% "`n" MsgBox % Info GoSub SetVars ;reset the vars for the next function }