作者: Infogulch 最近更新时间: 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 )
关于函数的参数和返回值, 请参阅其源码或 此文档.
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.
关于此函数(集)的更新细节和注意事项, 请参见 AutoHotkey 论坛: http://www.autohotkey.com/forum/viewtopic.php?t=36072
此函数(集)是基于 infogulch`s license 许可的开源项目. 想了解许可详情, 请参见 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 }