FILE COMPARISON
Produced: 7/20/2006 9:34:06 PM
   
Mode:  All Lines  
   
Left file: Coroutine-1.0.3 (Original).au3  
Right file: Coroutine.au3  
1 ;=============================================================================== = 1 ;===============================================================================
2 ;   2 ;
3 ; File: Coroutine.au3   3 ; File: Coroutine.au3
4 ; Description: UDF Library used for coroutine multithreading   4 ; Description: UDF Library used for coroutine multithreading
5 ; Version: 1.0.3 <> 5 ; Version: 1.1.0
6 ; Date: 4/25/06   6 ; Date: 7/20/06
7 ; Author: Ben Brightwell = 7 ; Author: Ben Brightwell
    <> 8 ; Credit:       ChrisH (darkthorn) for a huge amount of severe bug fixes.
8 ; Credit: ChrisL for the base idea of deploying files as child scripts. Topic   9 ;       ChrisL for the base idea of deploying files as child scripts. Topic
9 ;                       can be found here: = 10 ;                       can be found here:
10 ;                       http://www.autoitscript.com/forum/index.php?showtopic=22048   11 ;                       http://www.autoitscript.com/forum/index.php?showtopic=22048
11 ;   12 ;
12 ;===============================================================================   13 ;===============================================================================
13     14  
14 ;===============================================================================   15 ;===============================================================================
15 #cs   16 #cs
16         Changelog:   17         Changelog:
17         <> 18  
      19         [ Patched by Darkthorn ]
      20         7/20/06 (1.1.0) * Wrote _LineIsFunction() to correctly identify the start/end of functions.
      21                         - Replaced the previous, buggy StringInStr() matches with the above function.
      22                                 This means that your functions will no longer get incorrectly cut off
      23                                 when they contain the words "Func" or "EndFunc" inside the function
      24                                 definition.
      25                         * Fixed a bug in _CoChangeWorkingDir(), it didn't work before as the variable
      26                                 wasn't being used anywhere. The following changes were made:
      27                         - Changed _CoChangeWorkingDir() from $workingDir = $sDir to $sWorkingDir = $sDir.
      28                         - Changed _RandomFileName() from FileGetShortName(@TempDir) to FileGetShortName($sWorkingDir)
      29                         * The documentation for _CoInclude() says that it returns 1 on success, but it
      30                                 didn't return anything on success, this has been fixed so that it returns 1.
      31                         * Added documentation for _LineIsFunction(), and added it to the "Miscellaneous Function List".
      32                         * Fixed an extremely severe bug where the very important FileClose() command was
      33                                 omitted by the _CoInclude() function which appends functions to the output
      34                                 script. This in turn makes AutoIt go crazy and causes it to truncate/jumble
      35                                 the file contents whenever you try to access the file again. Not only that,
      36                                 but any subsequent attempts to reopen the file for writing (such as another
      37                                 call to _CoInclude()), would cause AutoIt to hang since the file would still be
      38                                 locked from before. This fixed two bugs:
      39                         - Output files are no longer truncated/jumbled when you use _CoInclude() to append functions.
      40                         - _CoInclude() no longer hangs AutoIt on subsequent calls, since the file is now free to reopen.
      41         [ Patched by Darkthorn ]
      42  
18         4/25/06 (1.0.3) - Fixed bug with using variables that contained the word = 43         4/25/06 (1.0.3) - Fixed bug with using variables that contained the word
19                                                 "return"   44                                                 "return"
20                                         - Fixed bug with StringLower()-ing every line of code   45                                         - Fixed bug with StringLower()-ing every line of code
21                                                 in coroutine script, now case is untouched   46                                                 in coroutine script, now case is untouched
22                                         - Fixed the way _CoInclude() works so that included code   47                                         - Fixed the way _CoInclude() works so that included code
23                                                 is placed at the top of the file instead of the bottom   48                                                 is placed at the top of the file instead of the bottom
24                                         - Fixed a bug with passing a simple string to the script   49                                         - Fixed a bug with passing a simple string to the script
25                                                 an extra dimension indicator was present   50                                                 an extra dimension indicator was present
26           51        
27         4/15/06 (1.0.2) - Truncated version number (Builds are irrelevant)   52         4/15/06 (1.0.2) - Truncated version number (Builds are irrelevant)
28                                         - Added support for expressions in the return statement   53                                         - Added support for expressions in the return statement
29                                                 of a coroutine   54                                                 of a coroutine
30                                                   55                                                
31         3/23/06 (1.0.1.0) - Modified _CoCreate() to handle a function with no   56         3/23/06 (1.0.1.0) - Modified _CoCreate() to handle a function with no
32                                                         parameters   57                                                         parameters
33                                           - Added "Core Function List" and "Miscellaneous Function   58                                           - Added "Core Function List" and "Miscellaneous Function
34                                                         List"   59                                                         List"
35                                           - Added this Changelog   60                                           - Added this Changelog
36                                           - Changed _CoAddHelper() to _CoInclude()   61                                           - Changed _CoAddHelper() to _CoInclude()
37                                           - Fixed a bug in _CoInclude() where the last line of code   62                                           - Fixed a bug in _CoInclude() where the last line of code
38                                                         was not being read into the script file   63                                                         was not being read into the script file
39 #ce   64 #ce
40 ;===============================================================================   65 ;===============================================================================
41     66  
42 ;===============================================================================   67 ;===============================================================================
43 #cs   68 #cs
44         Core Function List:   69         Core Function List:
45           70        
46         _CoCreate()   71         _CoCreate()
47         Create a coroutine script which can be instanced by _CoStart()   72         Create a coroutine script which can be instanced by _CoStart()
48           73        
49         _CoInclude()   74         _CoInclude()
50         Include helper/wrapper functions to compliment the main body created by   75         Include helper/wrapper functions to compliment the main body created by
51                 _CoCreate()   76                 _CoCreate()
52           77        
53         _CoStart()   78         _CoStart()
54         Create an instance of a threaded function as created by _CoCreate()   79         Create an instance of a threaded function as created by _CoCreate()
55           80        
56         _CoYield()   81         _CoYield()
57         NOTE: Only to be used in coroutine scripts   82         NOTE: Only to be used in coroutine scripts
58                 Pauses the coroutine and yields a value to the main script, returns   83                 Pauses the coroutine and yields a value to the main script, returns
59                 any value passed by the corresponding call to _CoResume()   84                 any value passed by the corresponding call to _CoResume()
60           85        
61         _CoStatus()   86         _CoStatus()
62         Returns the status of a coroutine   87         Returns the status of a coroutine
63           88        
64         _CoSend()   89         _CoSend()
65         Sends a variable into a child script   90         Sends a variable into a child script
66           91        
67         _CoResume()   92         _CoResume()
68         Unpauses a coroutine, optionally sends a value back to the yielded   93         Unpauses a coroutine, optionally sends a value back to the yielded
69                 coroutine   94                 coroutine
70           95        
71         _CoGetReturn()   96         _CoGetReturn()
72         Retrieves a variable returned by a coroutine   97         Retrieves a variable returned by a coroutine
73           98        
74         _CoKill()   99         _CoKill()
75         Closes a coroutine   100         Closes a coroutine
76           101        
77         _CoCleanup()   102         _CoCleanup()
78         Closes all running coroutines, and deletes their respective temporary script   103         Closes all running coroutines, and deletes their respective temporary script
79                 files   104                 files
80           105        
81         _CoChangeWorkingDir   106         _CoChangeWorkingDir
82         Changes the working directory for storing the temporary script files.   107         Changes the working directory for storing the temporary script files.
83                 NOTE: Default is @TempDir   108                 NOTE: Default is @TempDir
84           109        
85         Miscellaneous Function List:   110         Miscellaneous Function List:
86                 NOTE: These functions are meant to be called internally by Coroutine.au3   111                 NOTE: These functions are meant to be called internally by Coroutine.au3
87           112        
88         _PackVarToStr()   113         _PackVarToStr()
89         Packs a variable into a string for transmission between scripts.   114         Packs a variable into a string for transmission between scripts.
90           115        
91         _UnpackStrToVar()   116         _UnpackStrToVar()
92         Unpacks a packed variable-string into its original structure, whether it be   117         Unpacks a packed variable-string into its original structure, whether it be
93                 a string or array.   118                 a string or array.
    <> 119  
      120         _LineIsFunction()
      121         Classifies the given line as either the start/end of a function, or as a regular line.
94         = 122        
95         _RandomFileName()   123         _RandomFileName()
96         Generates a random unused filename for use with _CoCreate()   124         Generates a random unused filename for use with _CoCreate()
97 #ce   125 #ce
98 ;===============================================================================   126 ;===============================================================================
99     127  
100 Local $avCoThreads[1][2] ;[n] == iCoThreadID [n][0] == sFilePath [n][1] == iNumParams   128 Local $avCoThreads[1][2] ;[n] == iCoThreadID [n][0] == sFilePath [n][1] == iNumParams
101 $avCoThreads[0][0] = 0 ;Number of Multi-threaded Functions   129 $avCoThreads[0][0] = 0 ;Number of Multi-threaded Functions
102 Local $avPIDs[1][2] ;[n][0] == iPID [n][1] == iCoThreadID   130 Local $avPIDs[1][2] ;[n][0] == iPID [n][1] == iCoThreadID
103 $avPIDs[0][0] = 0 ;Number of iPID's created   131 $avPIDs[0][0] = 0 ;Number of iPID's created
104 Local $sWorkingDir = @TempDir   132 Local $sWorkingDir = @TempDir
105     133  
106 ;===============================================================================   134 ;===============================================================================
107 ;   135 ;
108 ; Function Name:    _CoCreate()   136 ; Function Name:    _CoCreate()
109 ; Description:      Create a child script for use with _CoStart()   137 ; Description:      Create a child script for use with _CoStart()
110 ; Parameter(s):     $sFuncRawText - A delimited string containing the lines of   138 ; Parameter(s):     $sFuncRawText - A delimited string containing the lines of
111 ;                                               the threaded function. Default delimiter is "|". Example:   139 ;                                               the threaded function. Default delimiter is "|". Example:
112 ;                                               "Func MyFunc($test1)|Return $test1|EndFunc"   140 ;                                               "Func MyFunc($test1)|Return $test1|EndFunc"
113 ;                                       $sDelimiter - A string containing the delimiter used in   141 ;                                       $sDelimiter - A string containing the delimiter used in
114 ;                                               $sFuncRawText (Default = "|")   142 ;                                               $sFuncRawText (Default = "|")
115 ; Return Value(s):  On Success - Returns the CoThreadID associated with the   143 ; Return Value(s):  On Success - Returns the CoThreadID associated with the
116 ;                                                                       created thread.   144 ;                                                                       created thread.
117 ;                   On Failure - 0 and @error set to:   145 ;                   On Failure - 0 and @error set to:
118 ;                                                                       1 - Invalid delimiter or delimiter not found   146 ;                                                                       1 - Invalid delimiter or delimiter not found
119 ;                                                                       2 - File could not be created, check working   147 ;                                                                       2 - File could not be created, check working
120 ;                                                                               directory access permissions   148 ;                                                                               directory access permissions
121 ;                                                                       3 - Function parameters not formatted   149 ;                                                                       3 - Function parameters not formatted
122 ;                                                                               correctly. Try eliminating white space:   150 ;                                                                               correctly. Try eliminating white space:
123 ;                                                                               Ex: Func MyFunc($test1,$test2,$test3)   151 ;                                                                               Ex: Func MyFunc($test1,$test2,$test3)
124 ;                                                                       4 - Return line not formatted correctly.   152 ;                                                                       4 - Return line not formatted correctly.
125 ; Author(s):        Ben Brightwell   153 ; Author(s):        Ben Brightwell
126 ;   154 ;
127 ;===============================================================================   155 ;===============================================================================
128 Func _CoCreate($sFuncRawText, $sDelimiter = "|")   156 Func _CoCreate($sFuncRawText, $sDelimiter = "|")
129         Local $asFuncLines = StringSplit($sFuncRawText, $sDelimiter)   157         Local $asFuncLines = StringSplit($sFuncRawText, $sDelimiter)
130         Local $bUnpackStrToVarUsed = 1 ; Determines if source for _UnpackStrToVar() is required in child script   158         Local $bUnpackStrToVarUsed = 1 ; Determines if source for _UnpackStrToVar() is required in child script
131         Local $bPackVarToStrUsed = 0 ; Determines if source for _PackVarToStr() is required in child script   159         Local $bPackVarToStrUsed = 0 ; Determines if source for _PackVarToStr() is required in child script
132         Local $bCoYieldUsed = 0 ; Determines if source for _CoYield() is required in child script   160         Local $bCoYieldUsed = 0 ; Determines if source for _CoYield() is required in child script
133         Local $hFile = "" ; For writing to the child script file   161         Local $hFile = "" ; For writing to the child script file
134         Local $asParams = "" ; Array of parameters pulled from the line: "Func MyFunction($test1, $test2, $test3)" in $sFuncRawText   162         Local $asParams = "" ; Array of parameters pulled from the line: "Func MyFunction($test1, $test2, $test3)" in $sFuncRawText
135         Local $asReturnLine = "" ; Line parsed from $sFuncRawText to contain the value that is passed as "Return $value"   163         Local $asReturnLine = "" ; Line parsed from $sFuncRawText to contain the value that is passed as "Return $value"
136         If IsArray($asFuncLines) Then   164         If IsArray($asFuncLines) Then
137                 ReDim $avCoThreads[$avCoThreads[0][0] + 2][2]   165                 ReDim $avCoThreads[$avCoThreads[0][0] + 2][2]
138                 $avCoThreads[0][0] += 1   166                 $avCoThreads[0][0] += 1
139                 $avCoThreads[$avCoThreads[0][0]][0] = _RandomFileName()   167                 $avCoThreads[$avCoThreads[0][0]][0] = _RandomFileName()
140                 $hFile = FileOpen($avCoThreads[$avCoThreads[0][0]][0], 2)   168                 $hFile = FileOpen($avCoThreads[$avCoThreads[0][0]][0], 2)
141                 If $hFile == -1 Then   169                 If $hFile == -1 Then
142                         SetError(2) ; File could not be created, check working directory access permissions   170                         SetError(2) ; File could not be created, check working directory access permissions
143                         Return 0 ; failure   171                         Return 0 ; failure
144                 EndIf   172                 EndIf
145                 $asParams = StringRegExp($asFuncLines[1] & " ", "(\$.*?)(?:[ ,\\)])", 3)   173                 $asParams = StringRegExp($asFuncLines[1] & " ", "(\$.*?)(?:[ ,\\)])", 3)
146                 If IsArray($asParams) Then   174                 If IsArray($asParams) Then
147                         $avCoThreads[$avCoThreads[0][0]][1] = UBound($asParams)   175                         $avCoThreads[$avCoThreads[0][0]][1] = UBound($asParams)
148                         If IsArray($asParams) Then   176                         If IsArray($asParams) Then
149                                 FileWriteLine($hFile, 'Local $sParamsInStr = "" ; Used to pass in parameters')   177                                 FileWriteLine($hFile, 'Local $sParamsInStr = "" ; Used to pass in parameters')
150                                 FileWriteLine($hFile, 'Local $iNumChrsToRead = 0 ; Used for parameter strings longer than 64Kb')   178                                 FileWriteLine($hFile, 'Local $iNumChrsToRead = 0 ; Used for parameter strings longer than 64Kb')
151                                 FileWriteLine($hFile, 'Local $sReturnStr = ""')   179                                 FileWriteLine($hFile, 'Local $sReturnStr = ""')
152                                 FileWriteLine($hFile, 'While ConsoleRead(0,true) == 0')   180                                 FileWriteLine($hFile, 'While ConsoleRead(0,true) == 0')
153                                 FileWriteLine($hFile, '  Sleep(10)')   181                                 FileWriteLine($hFile, '  Sleep(10)')
154                                 FileWriteLine($hFile, 'WEnd')   182                                 FileWriteLine($hFile, 'WEnd')
155                                 FileWriteLine($hFile, '$sParamsInStr = ConsoleRead()')   183                                 FileWriteLine($hFile, '$sParamsInStr = ConsoleRead()')
156                                 FileWriteLine($hFile, '$iNumChrsToRead = StringRegExp($sParamsInStr, "(\d*?)(\#)(?:\$\[)", 1)')   184                                 FileWriteLine($hFile, '$iNumChrsToRead = StringRegExp($sParamsInStr, "(\d*?)(\#)(?:\$\[)", 1)')
157                                 FileWriteLine($hFile, '$sParamsInStr = StringTrimLeft($sParamsInStr, $iNumChrsToRead[1])')   185                                 FileWriteLine($hFile, '$sParamsInStr = StringTrimLeft($sParamsInStr, $iNumChrsToRead[1])')
158                                 FileWriteLine($hFile, 'While StringLen($sParamsInStr) < $iNumChrsToRead[0]')   186                                 FileWriteLine($hFile, 'While StringLen($sParamsInStr) < $iNumChrsToRead[0]')
159                                 FileWriteLine($hFile, '  $sParamsInStr &= ConsoleRead()')   187                                 FileWriteLine($hFile, '  $sParamsInStr &= ConsoleRead()')
160                                 FileWriteLine($hFile, 'WEnd')   188                                 FileWriteLine($hFile, 'WEnd')
161                                 For $i = 0 To UBound($asParams) - 1   189                                 For $i = 0 To UBound($asParams) - 1
162                                         FileWriteLine($hFile, $asParams[$i] & " = _UnpackStrToVar($sParamsInStr)")   190                                         FileWriteLine($hFile, $asParams[$i] & " = _UnpackStrToVar($sParamsInStr)")
163                                 Next   191                                 Next
164                         EndIf   192                         EndIf
165                 ElseIf Not StringInStr($asFuncLines[1], "$") Then   193                 ElseIf Not StringInStr($asFuncLines[1], "$") Then
166                         FileWriteLine($hFile, ';No function parameters')   194                         FileWriteLine($hFile, ';No function parameters')
167                 Else   195                 Else
168                         SetError(3) ; Function parameters not formatted correctly   196                         SetError(3) ; Function parameters not formatted correctly
169                         Return 0 ; failure   197                         Return 0 ; failure
170                 EndIf   198                 EndIf
171                 For $i = 1 To $asFuncLines[0] - 1   199                 For $i = 1 To $asFuncLines[0] - 1
172                         If StringInStr($asFuncLines[$i], "return ") And Not StringInStr($asFuncLines[$i], ";") And Not StringInStr($asFuncLines[$i], "=") Then   200                         If StringInStr($asFuncLines[$i], "return ") And Not StringInStr($asFuncLines[$i], ";") And Not StringInStr($asFuncLines[$i], "=") Then
173                                 $asReturnLine = StringRegExp($asFuncLines[$i], "(?i:return[:space:]*)(.*)", 1)   201                                 $asReturnLine = StringRegExp($asFuncLines[$i], "(?i:return[:space:]*)(.*)", 1)
174                                 If IsArray($asReturnLine) Then   202                                 If IsArray($asReturnLine) Then
175                                         FileWriteLine($hFile, '$sExpStr = ' &$asReturnLine[0])   203                                         FileWriteLine($hFile, '$sExpStr = ' &$asReturnLine[0])
176                                         FileWriteLine($hFile, '$sExpStr = _PackVarToStr($sExpStr)')   204                                         FileWriteLine($hFile, '$sExpStr = _PackVarToStr($sExpStr)')
177                                         FileWriteLine($hFile, 'ConsoleWrite("return" & StringLen($sExpStr) & $sExpStr)')   205                                         FileWriteLine($hFile, 'ConsoleWrite("return" & StringLen($sExpStr) & $sExpStr)')
178                                         $bPackVarToStrUsed = 1   206                                         $bPackVarToStrUsed = 1
179                                 Else   207                                 Else
180                                         SetError(4) ; Return line not formatted correctly   208                                         SetError(4) ; Return line not formatted correctly
181                                         Return 0 ; failure   209                                         Return 0 ; failure
182                                 EndIf   210                                 EndIf
183                         ElseIf Not StringInStr($asFuncLines[$i], "func") And Not StringInStr($asFuncLines[$i], "endfunc") Then <> 211                         ElseIf Not _LineIsFunction($asFuncLines[$i]) Then
184                                 FileWriteLine($hFile, $asFuncLines[$i]) = 212                                 FileWriteLine($hFile, $asFuncLines[$i])
185                                 If StringInStr($asFuncLines[$i], "_coyield") Then   213                                 If StringInStr($asFuncLines[$i], "_coyield") Then
186                                         $bCoYieldUsed = 1   214                                         $bCoYieldUsed = 1
187                                 EndIf   215                                 EndIf
188                         EndIf   216                         EndIf
189                 Next   217                 Next
190                 If $bCoYieldUsed == 1 Then   218                 If $bCoYieldUsed == 1 Then
191                         FileWriteLine($hFile, 'Func _CoYield($bPeek, $sVarName = "")')   219                         FileWriteLine($hFile, 'Func _CoYield($bPeek, $sVarName = "")')
192                         FileWriteLine($hFile, '  If $bPeek == 1 Then')   220                         FileWriteLine($hFile, '  If $bPeek == 1 Then')
193                         FileWriteLine($hFile, '         If ConsoleRead(0,true) <> 0 Then')   221                         FileWriteLine($hFile, '         If ConsoleRead(0,true) <> 0 Then')
194                         FileWriteLine($hFile, '                 $vResumeVar = ConsoleRead()')   222                         FileWriteLine($hFile, '                 $vResumeVar = ConsoleRead()')
195                         FileWriteLine($hFile, '                 $vResumeVar = _UnpackStrToVar($vResumeVar)')   223                         FileWriteLine($hFile, '                 $vResumeVar = _UnpackStrToVar($vResumeVar)')
196                         FileWriteLine($hFile, '                 SetExtended(1)')   224                         FileWriteLine($hFile, '                 SetExtended(1)')
197                         FileWriteLine($hFile, '                 Return $vResumeVar')   225                         FileWriteLine($hFile, '                 Return $vResumeVar')
198                         FileWriteLine($hFile, '         Else')   226                         FileWriteLine($hFile, '         Else')
199                         FileWriteLine($hFile, '                 SetExtended(0)')   227                         FileWriteLine($hFile, '                 SetExtended(0)')
200                         FileWriteLine($hFile, '                 Return ""')   228                         FileWriteLine($hFile, '                 Return ""')
201                         FileWriteLine($hFile, '         EndIf')   229                         FileWriteLine($hFile, '         EndIf')
202                         FileWriteLine($hFile, '  Else')   230                         FileWriteLine($hFile, '  Else')
203                         FileWriteLine($hFile, '         Local $vVarNameEval = "" ; If $sVarName equates to a declared variable, a copy of it is stored here')   231                         FileWriteLine($hFile, '         Local $vVarNameEval = "" ; If $sVarName equates to a declared variable, a copy of it is stored here')
204                         FileWriteLine($hFile, '         Local $vResumeVar = "" ; When _CoResume() is called to unpause script, a variable can be passed')   232                         FileWriteLine($hFile, '         Local $vResumeVar = "" ; When _CoResume() is called to unpause script, a variable can be passed')
205                         FileWriteLine($hFile, '         If StringLeft($sVarName, 1) == "$" Then StringReplace($sVarName, "$", "")')   233                         FileWriteLine($hFile, '         If StringLeft($sVarName, 1) == "$" Then StringReplace($sVarName, "$", "")')
206                         FileWriteLine($hFile, '         If IsDeclared($sVarName) Then')   234                         FileWriteLine($hFile, '         If IsDeclared($sVarName) Then')
207                         FileWriteLine($hFile, '                 $vVarNameEval = Eval($sVarName)')   235                         FileWriteLine($hFile, '                 $vVarNameEval = Eval($sVarName)')
208                         FileWriteLine($hFile, '                 $vVarNameEval = _PackVarToStr($vVarNameEval)')   236                         FileWriteLine($hFile, '                 $vVarNameEval = _PackVarToStr($vVarNameEval)')
209                         FileWriteLine($hFile, '                 ConsoleWrite("yield" & StrLen($vVarNameEval) & $vVarNameEval)')   237                         FileWriteLine($hFile, '                 ConsoleWrite("yield" & StrLen($vVarNameEval) & $vVarNameEval)')
210                         FileWriteLine($hFile, '         Else')   238                         FileWriteLine($hFile, '         Else')
211                         FileWriteLine($hFile, '                 $vVarName = _PackVarToStr($vVarName)')   239                         FileWriteLine($hFile, '                 $vVarName = _PackVarToStr($vVarName)')
212                         FileWriteLine($hFile, '                 ConsoleWrite("yield" & StrLen($vVarName) & $vVarName')   240                         FileWriteLine($hFile, '                 ConsoleWrite("yield" & StrLen($vVarName) & $vVarName')
213                         FileWriteLine($hFile, '         EndIf')   241                         FileWriteLine($hFile, '         EndIf')
214                         FileWriteLine($hFile, '         While ConsoleRead(0,true) == 0')   242                         FileWriteLine($hFile, '         While ConsoleRead(0,true) == 0')
215                         FileWriteLine($hFile, '                 Sleep(10)')   243                         FileWriteLine($hFile, '                 Sleep(10)')
216                         FileWriteLine($hFile, '         WEnd')   244                         FileWriteLine($hFile, '         WEnd')
217                         FileWriteLine($hFile, '         $vResumeVar = ConsoleRead()')   245                         FileWriteLine($hFile, '         $vResumeVar = ConsoleRead()')
218                         FileWriteLine($hFile, '         $vResumeVar = _UnpackStrToVar($vResumeVar)')   246                         FileWriteLine($hFile, '         $vResumeVar = _UnpackStrToVar($vResumeVar)')
219                         FileWriteLine($hFile, '         Return $vResumeVar')   247                         FileWriteLine($hFile, '         Return $vResumeVar')
220                         FileWriteLine($hFile, '  EndIf')   248                         FileWriteLine($hFile, '  EndIf')
221                         FileWriteLine($hFile, 'EndFunc')   249                         FileWriteLine($hFile, 'EndFunc')
222                 EndIf   250                 EndIf
223                 If $bUnpackStrToVarUsed == 1 Then   251                 If $bUnpackStrToVarUsed == 1 Then
224                         FileWriteLine($hFile, 'Func _UnpackStrToVar(ByRef $sVarStr)')   252                         FileWriteLine($hFile, 'Func _UnpackStrToVar(ByRef $sVarStr)')
225                         FileWriteLine($hFile, ' Local $aiNumDims = StringRegExp($sVarStr, ''(?:\$\[)(\d*)(?:\]\$)(\#)'', 1)')   253                         FileWriteLine($hFile, ' Local $aiNumDims = StringRegExp($sVarStr, ''(?:\$\[)(\d*)(?:\]\$)(\#)'', 1)')
226                         FileWriteLine($hFile, ' Local $aiDimSizes[1] ; To contain the size of each dimension as passed through $sVarStr')   254                         FileWriteLine($hFile, ' Local $aiDimSizes[1] ; To contain the size of each dimension as passed through $sVarStr')
227                         FileWriteLine($hFile, ' Local $aiDimSize = "" ; To contain the size of current dimension and string position for stripping')   255                         FileWriteLine($hFile, ' Local $aiDimSize = "" ; To contain the size of current dimension and string position for stripping')
228                         FileWriteLine($hFile, ' Local $avRetArr[1] ; To be redimensioned and have $sVarStr parsed and stored into as an array')   256                         FileWriteLine($hFile, ' Local $avRetArr[1] ; To be redimensioned and have $sVarStr parsed and stored into as an array')
229                         FileWriteLine($hFile, ' Local $avElementStr = "" ; To contain each element as a string as it is parsed from $sVarStr')   257                         FileWriteLine($hFile, ' Local $avElementStr = "" ; To contain each element as a string as it is parsed from $sVarStr')
230                         FileWriteLine($hFile, ' If IsArray($aiNumDims) Then')   258                         FileWriteLine($hFile, ' If IsArray($aiNumDims) Then')
231                         FileWriteLine($hFile, '         $sVarStr = StringTrimLeft($sVarStr, $aiNumDims[1])')   259                         FileWriteLine($hFile, '         $sVarStr = StringTrimLeft($sVarStr, $aiNumDims[1])')
232                         FileWriteLine($hFile, '         If $aiNumDims[0] > 0 Then')   260                         FileWriteLine($hFile, '         If $aiNumDims[0] > 0 Then')
233                         FileWriteLine($hFile, '                 ReDim $aiDimSizes[$aiNumDims[0]]')   261                         FileWriteLine($hFile, '                 ReDim $aiDimSizes[$aiNumDims[0]]')
234                         FileWriteLine($hFile, '                 For $iCounter1 = 0 To $aiNumDims[0] - 1')   262                         FileWriteLine($hFile, '                 For $iCounter1 = 0 To $aiNumDims[0] - 1')
235                         FileWriteLine($hFile, '                         $aiDimSize = StringRegExp($sVarStr, ''(?:\$\[)(\d*)(?:\]\$)(\#)'', 1)')   263                         FileWriteLine($hFile, '                         $aiDimSize = StringRegExp($sVarStr, ''(?:\$\[)(\d*)(?:\]\$)(\#)'', 1)')
236                         FileWriteLine($hFile, '                         $aiDimSizes[$iCounter1] = $aiDimSize[0]')   264                         FileWriteLine($hFile, '                         $aiDimSizes[$iCounter1] = $aiDimSize[0]')
237                         FileWriteLine($hFile, '                         $sVarStr = StringTrimLeft($sVarStr, $aiDimSize[1])')   265                         FileWriteLine($hFile, '                         $sVarStr = StringTrimLeft($sVarStr, $aiDimSize[1])')
238                         FileWriteLine($hFile, '                 Next')   266                         FileWriteLine($hFile, '                 Next')
239                         FileWriteLine($hFile, '         EndIf')   267                         FileWriteLine($hFile, '         EndIf')
240                         FileWriteLine($hFile, '         Select')   268                         FileWriteLine($hFile, '         Select')
241                         FileWriteLine($hFile, '                 Case $aiNumDims[0] == 0')   269                         FileWriteLine($hFile, '                 Case $aiNumDims[0] == 0')
242                         FileWriteLine($hFile, '                         If StringInStr($sVarStr, "$[") Then')   270                         FileWriteLine($hFile, '                         If StringInStr($sVarStr, "$[") Then')
243                         FileWriteLine($hFile, '                                 $avElementStr = StringRegExp($sVarStr, ''(.*?)(\#)(?:\$\[)'', 1)')   271                         FileWriteLine($hFile, '                                 $avElementStr = StringRegExp($sVarStr, ''(.*?)(\#)(?:\$\[)'', 1)')
244                         FileWriteLine($hFile, '                                 $sVarStr = StringTrimLeft($sVarStr, $avElementStr[1])')   272                         FileWriteLine($hFile, '                                 $sVarStr = StringTrimLeft($sVarStr, $avElementStr[1])')
245                         FileWriteLine($hFile, '                                 If $avElementStr[0] <> "<nil>" Then')   273                         FileWriteLine($hFile, '                                 If $avElementStr[0] <> "<nil>" Then')
246                         FileWriteLine($hFile, '                                         Return $avElementStr[0]')   274                         FileWriteLine($hFile, '                                         Return $avElementStr[0]')
247                         FileWriteLine($hFile, '                                 Else')   275                         FileWriteLine($hFile, '                                 Else')
248                         FileWriteLine($hFile, '                                         Return ""')   276                         FileWriteLine($hFile, '                                         Return ""')
249                         FileWriteLine($hFile, '                                 EndIf')   277                         FileWriteLine($hFile, '                                 EndIf')
250                         FileWriteLine($hFile, '                         Else')   278                         FileWriteLine($hFile, '                         Else')
251                         FileWriteLine($hFile, '                                 If $sVarStr == "<nil>" Then')   279                         FileWriteLine($hFile, '                                 If $sVarStr == "<nil>" Then')
252                         FileWriteLine($hFile, '                                         Return ""')   280                         FileWriteLine($hFile, '                                         Return ""')
253                         FileWriteLine($hFile, '                                 Else')   281                         FileWriteLine($hFile, '                                 Else')
254                         FileWriteLine($hFile, '                                         Return $sVarStr')   282                         FileWriteLine($hFile, '                                         Return $sVarStr')
255                         FileWriteLine($hFile, '                                 EndIf')   283                         FileWriteLine($hFile, '                                 EndIf')
256                         FileWriteLine($hFile, '                         EndIf')   284                         FileWriteLine($hFile, '                         EndIf')
257                         FileWriteLine($hFile, '                 Case $aiNumDims[0] == 1')   285                         FileWriteLine($hFile, '                 Case $aiNumDims[0] == 1')
258                         FileWriteLine($hFile, '                         ReDim $avRetArr[$aiDimSizes[0]]')   286                         FileWriteLine($hFile, '                         ReDim $avRetArr[$aiDimSizes[0]]')
259                         FileWriteLine($hFile, '                         For $iCounter1 = 0 To $aiDimSizes[0] - 1')   287                         FileWriteLine($hFile, '                         For $iCounter1 = 0 To $aiDimSizes[0] - 1')
260                         FileWriteLine($hFile, '                                 $avRetArr[$iCounter1] = _UnpackStrToVar($sVarStr) ; In case element holds another array (Recursive)')   288                         FileWriteLine($hFile, '                                 $avRetArr[$iCounter1] = _UnpackStrToVar($sVarStr) ; In case element holds another array (Recursive)')
261                         FileWriteLine($hFile, '                         Next')   289                         FileWriteLine($hFile, '                         Next')
262                         FileWriteLine($hFile, '                 Case $aiNumDims[0] == 2')   290                         FileWriteLine($hFile, '                 Case $aiNumDims[0] == 2')
263                         FileWriteLine($hFile, '                         ReDim $avRetArr[$aiDimSizes[0]][$aiDimSizes[1]]')   291                         FileWriteLine($hFile, '                         ReDim $avRetArr[$aiDimSizes[0]][$aiDimSizes[1]]')
264                         FileWriteLine($hFile, '                         For $iCounter1 = 0 To $aiDimSizes[0] - 1')   292                         FileWriteLine($hFile, '                         For $iCounter1 = 0 To $aiDimSizes[0] - 1')
265                         FileWriteLine($hFile, '                                 For $iCounter2 = 0 To $aiDimSizes[1] - 1')   293                         FileWriteLine($hFile, '                                 For $iCounter2 = 0 To $aiDimSizes[1] - 1')
266                         FileWriteLine($hFile, '                                         $avRetArr[$iCounter1][$iCounter2] = _UnpackStrToVar($sVarStr) ; In case element holds another array (Recursive)')   294                         FileWriteLine($hFile, '                                         $avRetArr[$iCounter1][$iCounter2] = _UnpackStrToVar($sVarStr) ; In case element holds another array (Recursive)')
267                         FileWriteLine($hFile, '                                 Next')   295                         FileWriteLine($hFile, '                                 Next')
268                         FileWriteLine($hFile, '                         Next')   296                         FileWriteLine($hFile, '                         Next')
269                         FileWriteLine($hFile, '                 Case $aiNumDims[0] == 3')   297                         FileWriteLine($hFile, '                 Case $aiNumDims[0] == 3')
270                         FileWriteLine($hFile, '                         ReDim $avRetArr[$aiDimSizes[0]][$aiDimSizes[1]][$aiDimSizes[2]]')   298                         FileWriteLine($hFile, '                         ReDim $avRetArr[$aiDimSizes[0]][$aiDimSizes[1]][$aiDimSizes[2]]')
271                         FileWriteLine($hFile, '                         For $iCounter1 = 0 To $aiDimSizes[0] - 1')   299                         FileWriteLine($hFile, '                         For $iCounter1 = 0 To $aiDimSizes[0] - 1')
272                         FileWriteLine($hFile, '                                 For $iCounter2 = 0 To $aiDimSizes[1] - 1')   300                         FileWriteLine($hFile, '                                 For $iCounter2 = 0 To $aiDimSizes[1] - 1')
273                         FileWriteLine($hFile, '                                         For $iCounter3 = 0 To $aiDimSizes[2] - 1')   301                         FileWriteLine($hFile, '                                         For $iCounter3 = 0 To $aiDimSizes[2] - 1')
274                         FileWriteLine($hFile, '                                                 $avRetArr[$iCounter1][$iCounter2][$iCounter3] = _UnpackStrToVar($sVarStr) ; In case element holds another array (Recursive)')   302                         FileWriteLine($hFile, '                                                 $avRetArr[$iCounter1][$iCounter2][$iCounter3] = _UnpackStrToVar($sVarStr) ; In case element holds another array (Recursive)')
275                         FileWriteLine($hFile, '                                         Next')   303                         FileWriteLine($hFile, '                                         Next')
276                         FileWriteLine($hFile, '                                 Next')   304                         FileWriteLine($hFile, '                                 Next')
277                         FileWriteLine($hFile, '                         Next')   305                         FileWriteLine($hFile, '                         Next')
278                         FileWriteLine($hFile, '                 Case $aiNumDims[0] == 4')   306                         FileWriteLine($hFile, '                 Case $aiNumDims[0] == 4')
279                         FileWriteLine($hFile, '                         ReDim $avRetArr[$aiDimSizes[0]][$aiDimSizes[1]][$aiDimSizes[2]][$aiDimSizes[3]]')   307                         FileWriteLine($hFile, '                         ReDim $avRetArr[$aiDimSizes[0]][$aiDimSizes[1]][$aiDimSizes[2]][$aiDimSizes[3]]')
280                         FileWriteLine($hFile, '                         For $iCounter1 = 0 To $aiDimSizes[0] - 1')   308                         FileWriteLine($hFile, '                         For $iCounter1 = 0 To $aiDimSizes[0] - 1')
281                         FileWriteLine($hFile, '                                 For $iCounter2 = 0 To $aiDimSizes[1] - 1')   309                         FileWriteLine($hFile, '                                 For $iCounter2 = 0 To $aiDimSizes[1] - 1')
282                         FileWriteLine($hFile, '                                         For $iCounter3 = 0 To $aiDimSizes[2] - 1')   310                         FileWriteLine($hFile, '                                         For $iCounter3 = 0 To $aiDimSizes[2] - 1')
283                         FileWriteLine($hFile, '                                                 For $iCounter4 = 0 To $aiDimSizes[3] - 1')   311                         FileWriteLine($hFile, '                                                 For $iCounter4 = 0 To $aiDimSizes[3] - 1')
284                         FileWriteLine($hFile, '                                                         $avRetArr[$iCounter1][$iCounter2][$iCounter3][$iCounter4] = _UnpackStrToVar($sVarStr) ; In case element holds another array (Recursive)')   312                         FileWriteLine($hFile, '                                                         $avRetArr[$iCounter1][$iCounter2][$iCounter3][$iCounter4] = _UnpackStrToVar($sVarStr) ; In case element holds another array (Recursive)')
285                         FileWriteLine($hFile, '                                                 Next')   313                         FileWriteLine($hFile, '                                                 Next')
286                         FileWriteLine($hFile, '                                         Next')   314                         FileWriteLine($hFile, '                                         Next')
287                         FileWriteLine($hFile, '                                 Next')   315                         FileWriteLine($hFile, '                                 Next')
288                         FileWriteLine($hFile, '                         Next')   316                         FileWriteLine($hFile, '                         Next')
289                         FileWriteLine($hFile, '         EndSelect')   317                         FileWriteLine($hFile, '         EndSelect')
290                         FileWriteLine($hFile, '         Return $avRetArr')   318                         FileWriteLine($hFile, '         Return $avRetArr')
291                         FileWriteLine($hFile, ' EndIf')   319                         FileWriteLine($hFile, ' EndIf')
292                         FileWriteLine($hFile, 'EndFunc   ;==>_UnpackStrToVar')   320                         FileWriteLine($hFile, 'EndFunc   ;==>_UnpackStrToVar')
293                 EndIf   321                 EndIf
294                 If $bPackVarToStrUsed == 1 Then   322                 If $bPackVarToStrUsed == 1 Then
295                         FileWriteLine($hFile, 'Func _PackVarToStr(ByRef $vPackVar)')   323                         FileWriteLine($hFile, 'Func _PackVarToStr(ByRef $vPackVar)')
296                         FileWriteLine($hFile, ' Local $iNumDims = UBound($vPackVar, 0) ; Number of dimensions of $vPackVar')   324                         FileWriteLine($hFile, ' Local $iNumDims = UBound($vPackVar, 0) ; Number of dimensions of $vPackVar')
297                         FileWriteLine($hFile, ' Local $sVarStr = "$[" & $iNumDims & "]$" ; Return string of packed variable')   325                         FileWriteLine($hFile, ' Local $sVarStr = "$[" & $iNumDims & "]$" ; Return string of packed variable')
298                         FileWriteLine($hFile, ' Local $iCounter1 = "" ; Nested Counter')   326                         FileWriteLine($hFile, ' Local $iCounter1 = "" ; Nested Counter')
299                         FileWriteLine($hFile, ' Local $iCounter2 = "" ; Nested Counter')   327                         FileWriteLine($hFile, ' Local $iCounter2 = "" ; Nested Counter')
300                         FileWriteLine($hFile, ' Local $iCounter3 = "" ; Nested Counter')   328                         FileWriteLine($hFile, ' Local $iCounter3 = "" ; Nested Counter')
301                         FileWriteLine($hFile, ' Local $iCounter4 = "" ; Nested Counter')   329                         FileWriteLine($hFile, ' Local $iCounter4 = "" ; Nested Counter')
302                         FileWriteLine($hFile, ' For $i = 1 To $iNumDims')   330                         FileWriteLine($hFile, ' For $i = 1 To $iNumDims')
303                         FileWriteLine($hFile, '         $sVarStr &= "$[" & UBound($vPackVar, $i) & "]$"')   331                         FileWriteLine($hFile, '         $sVarStr &= "$[" & UBound($vPackVar, $i) & "]$"')
304                         FileWriteLine($hFile, ' Next')   332                         FileWriteLine($hFile, ' Next')
305                         FileWriteLine($hFile, ' Select')   333                         FileWriteLine($hFile, ' Select')
306                         FileWriteLine($hFile, '         Case $iNumDims == 0')   334                         FileWriteLine($hFile, '         Case $iNumDims == 0')
307                         FileWriteLine($hFile, '                 If $vPackVar == "" Then')   335                         FileWriteLine($hFile, '                 If $vPackVar == "" Then')
308                         FileWriteLine($hFile, '                         $sVarStr &= "<nil>"')   336                         FileWriteLine($hFile, '                         $sVarStr &= "<nil>"')
309                         FileWriteLine($hFile, '                 Else')   337                         FileWriteLine($hFile, '                 Else')
310                         FileWriteLine($hFile, '                         $sVarStr &= $vPackVar')   338                         FileWriteLine($hFile, '                         $sVarStr &= $vPackVar')
311                         FileWriteLine($hFile, '                 EndIf')   339                         FileWriteLine($hFile, '                 EndIf')
312                         FileWriteLine($hFile, '         Case $iNumDims == 1')   340                         FileWriteLine($hFile, '         Case $iNumDims == 1')
313                         FileWriteLine($hFile, '                 For $iCounter1 = 0 To UBound($vPackVar, 1) - 1')   341                         FileWriteLine($hFile, '                 For $iCounter1 = 0 To UBound($vPackVar, 1) - 1')
314                         FileWriteLine($hFile, '                         If $vPackVar[$iCounter1] == "" And UBound($vPackVar[$iCounter1], 0) == 0 Then')   342                         FileWriteLine($hFile, '                         If $vPackVar[$iCounter1] == "" And UBound($vPackVar[$iCounter1], 0) == 0 Then')
315                         FileWriteLine($hFile, '                                 $sVarStr &= "$[0]$<nil>"')   343                         FileWriteLine($hFile, '                                 $sVarStr &= "$[0]$<nil>"')
316                         FileWriteLine($hFile, '                         Else')   344                         FileWriteLine($hFile, '                         Else')
317                         FileWriteLine($hFile, '                                 $sVarStr &= _PackVarToStr($vPackVar[$iCounter1])')   345                         FileWriteLine($hFile, '                                 $sVarStr &= _PackVarToStr($vPackVar[$iCounter1])')
318                         FileWriteLine($hFile, '                         EndIf')   346                         FileWriteLine($hFile, '                         EndIf')
319                         FileWriteLine($hFile, '                 Next')   347                         FileWriteLine($hFile, '                 Next')
320                         FileWriteLine($hFile, '         Case $iNumDims == 2')   348                         FileWriteLine($hFile, '         Case $iNumDims == 2')
321                         FileWriteLine($hFile, '                 For $iCounter1 = 0 To UBound($vPackVar, 1) - 1')   349                         FileWriteLine($hFile, '                 For $iCounter1 = 0 To UBound($vPackVar, 1) - 1')
322                         FileWriteLine($hFile, '                         For $iCounter2 = 0 To UBound($vPackVar, 2) - 1')   350                         FileWriteLine($hFile, '                         For $iCounter2 = 0 To UBound($vPackVar, 2) - 1')
323                         FileWriteLine($hFile, '                                 If $vPackVar[$iCounter1][$iCounter2] == "" And UBound($vPackVar[$iCounter1][$iCounter2], 0) == 0 Then')   351                         FileWriteLine($hFile, '                                 If $vPackVar[$iCounter1][$iCounter2] == "" And UBound($vPackVar[$iCounter1][$iCounter2], 0) == 0 Then')
324                         FileWriteLine($hFile, '                                         $sVarStr &= "$[0]$<nil>"')   352                         FileWriteLine($hFile, '                                         $sVarStr &= "$[0]$<nil>"')
325                         FileWriteLine($hFile, '                                 Else')   353                         FileWriteLine($hFile, '                                 Else')
326                         FileWriteLine($hFile, '                                         $sVarStr &= _PackVarToStr($vPackVar[$iCounter1][$iCounter2])')   354                         FileWriteLine($hFile, '                                         $sVarStr &= _PackVarToStr($vPackVar[$iCounter1][$iCounter2])')
327                         FileWriteLine($hFile, '                                 EndIf')   355                         FileWriteLine($hFile, '                                 EndIf')
328                         FileWriteLine($hFile, '                         Next')   356                         FileWriteLine($hFile, '                         Next')
329                         FileWriteLine($hFile, '                 Next')   357                         FileWriteLine($hFile, '                 Next')
330                         FileWriteLine($hFile, '         Case $iNumDims == 3')   358                         FileWriteLine($hFile, '         Case $iNumDims == 3')
331                         FileWriteLine($hFile, '                 For $iCounter1 = 0 To UBound($vPackVar, 1) - 1')   359                         FileWriteLine($hFile, '                 For $iCounter1 = 0 To UBound($vPackVar, 1) - 1')
332                         FileWriteLine($hFile, '                         For $iCounter2 = 0 To UBound($vPackVar, 2) - 1')   360                         FileWriteLine($hFile, '                         For $iCounter2 = 0 To UBound($vPackVar, 2) - 1')
333                         FileWriteLine($hFile, '                                 For $iCounter3 = 0 To UBound($vPackVar, 3) - 1')   361                         FileWriteLine($hFile, '                                 For $iCounter3 = 0 To UBound($vPackVar, 3) - 1')
334                         FileWriteLine($hFile, '                                         If $vPackVar[$iCounter1][$iCounter2][$iCounter3] == "" And UBound($vPackVar[$iCounter1][$iCounter2][$iCounter3], 0) == 0 Then')   362                         FileWriteLine($hFile, '                                         If $vPackVar[$iCounter1][$iCounter2][$iCounter3] == "" And UBound($vPackVar[$iCounter1][$iCounter2][$iCounter3], 0) == 0 Then')
335                         FileWriteLine($hFile, '                                                 $sVarStr &= "$[0]$<nil>"')   363                         FileWriteLine($hFile, '                                                 $sVarStr &= "$[0]$<nil>"')
336                         FileWriteLine($hFile, '                                         Else')   364                         FileWriteLine($hFile, '                                         Else')
337                         FileWriteLine($hFile, '                                                 $sVarStr &= _PackVarToStr($vPackVar[$iCounter1][$iCounter2][$iCounter3])')   365                         FileWriteLine($hFile, '                                                 $sVarStr &= _PackVarToStr($vPackVar[$iCounter1][$iCounter2][$iCounter3])')
338                         FileWriteLine($hFile, '                                         EndIf')   366                         FileWriteLine($hFile, '                                         EndIf')
339                         FileWriteLine($hFile, '                                 Next')   367                         FileWriteLine($hFile, '                                 Next')
340                         FileWriteLine($hFile, '                         Next')   368                         FileWriteLine($hFile, '                         Next')
341                         FileWriteLine($hFile, '                 Next')   369                         FileWriteLine($hFile, '                 Next')
342                         FileWriteLine($hFile, '         Case $iNumDims == 4')   370                         FileWriteLine($hFile, '         Case $iNumDims == 4')
343                         FileWriteLine($hFile, '                 For $iCounter1 = 0 To UBound($vPackVar, 1) - 1')   371                         FileWriteLine($hFile, '                 For $iCounter1 = 0 To UBound($vPackVar, 1) - 1')
344                         FileWriteLine($hFile, '                         For $iCounter2 = 0 To UBound($vPackVar, 2) - 1')   372                         FileWriteLine($hFile, '                         For $iCounter2 = 0 To UBound($vPackVar, 2) - 1')
345                         FileWriteLine($hFile, '                                 For $iCounter3 = 0 To UBound($vPackVar, 3) - 1')   373                         FileWriteLine($hFile, '                                 For $iCounter3 = 0 To UBound($vPackVar, 3) - 1')
346                         FileWriteLine($hFile, '                                         For $iCounter4 = 0 To UBound($vPackVar, 4) - 1')   374                         FileWriteLine($hFile, '                                         For $iCounter4 = 0 To UBound($vPackVar, 4) - 1')
347                         FileWriteLine($hFile, '                                                 If $vPackVar[$iCounter1][$iCounter2][$iCounter3][$iCounter4] == "" And UBound($vPackVar[$iCounter1][$iCounter2][$iCounter3][$iCounter4], 0) == 0 Then')   375                         FileWriteLine($hFile, '                                                 If $vPackVar[$iCounter1][$iCounter2][$iCounter3][$iCounter4] == "" And UBound($vPackVar[$iCounter1][$iCounter2][$iCounter3][$iCounter4], 0) == 0 Then')
348                         FileWriteLine($hFile, '                                                         $sVarStr &= "$[0]$<nil>"')   376                         FileWriteLine($hFile, '                                                         $sVarStr &= "$[0]$<nil>"')
349                         FileWriteLine($hFile, '                                                 Else')   377                         FileWriteLine($hFile, '                                                 Else')
350                         FileWriteLine($hFile, '                                                         $sVarStr &= _PackVarToStr($vPackVar[$iCounter1][$iCounter2][$iCounter3][$iCounter4])')   378                         FileWriteLine($hFile, '                                                         $sVarStr &= _PackVarToStr($vPackVar[$iCounter1][$iCounter2][$iCounter3][$iCounter4])')
351                         FileWriteLine($hFile, '                                                 EndIf')   379                         FileWriteLine($hFile, '                                                 EndIf')
352                         FileWriteLine($hFile, '                                         Next')   380                         FileWriteLine($hFile, '                                         Next')
353                         FileWriteLine($hFile, '                                 Next')   381                         FileWriteLine($hFile, '                                 Next')
354                         FileWriteLine($hFile, '                         Next')   382                         FileWriteLine($hFile, '                         Next')
355                         FileWriteLine($hFile, '                 Next')   383                         FileWriteLine($hFile, '                 Next')
356                         FileWriteLine($hFile, ' EndSelect')   384                         FileWriteLine($hFile, ' EndSelect')
357                         FileWriteLine($hFile, ' Return $sVarStr')   385                         FileWriteLine($hFile, ' Return $sVarStr')
358                         FileWriteLine($hFile, 'EndFunc   ;==>_PackVarToStr')   386                         FileWriteLine($hFile, 'EndFunc   ;==>_PackVarToStr')
359                 EndIf   387                 EndIf
360                 FileClose($hFile)   388                 FileClose($hFile)
361                 Return $avCoThreads[0][0]   389                 Return $avCoThreads[0][0]
362         Else   390         Else
363                 SetError(1) ; Invalid delimiter or delimiter not found   391                 SetError(1) ; Invalid delimiter or delimiter not found
364                 Return 0 ; failure   392                 Return 0 ; failure
365         EndIf   393         EndIf
366 EndFunc   ;==>_CoCreate   394 EndFunc   ;==>_CoCreate
367     395  
368 ;===============================================================================   396 ;===============================================================================
369 ;   397 ;
370 ; Function Name:    _CoYield()   398 ; Function Name:    _CoYield()
371 ; Description:      Yield a value to the main script and pause the   399 ; Description:      Yield a value to the main script and pause the
372 ;                                               coroutine, only usable by the coroutine   400 ;                                               coroutine, only usable by the coroutine
373 ; Parameter(s):     $sVarName - String containing the name of the variable   401 ; Parameter(s):     $sVarName - String containing the name of the variable
374 ;                                               to pass to the main script. If string does not contain   402 ;                                               to pass to the main script. If string does not contain
375 ;                                               the name of a declared variable, it is passed as a   403 ;                                               the name of a declared variable, it is passed as a
376 ;                                               literal string.   404 ;                                               literal string.
377 ; Return Value(s):  The variable passed by the corresponding call to _CoResume()   405 ; Return Value(s):  The variable passed by the corresponding call to _CoResume()
378 ; Author(s):        Ben Brightwell   406 ; Author(s):        Ben Brightwell
379 ;   407 ;
380 ;===============================================================================   408 ;===============================================================================
381 ;~ Func _CoYield($bPeek, $sVarName = "")   409 ;~ Func _CoYield($bPeek, $sVarName = "")
382 ;~      If $bPeek == 1 Then   410 ;~      If $bPeek == 1 Then
383 ;~              If ConsoleRead(0,true) <> 0 Then   411 ;~              If ConsoleRead(0,true) <> 0 Then
384 ;~                      $vResumeVar = ConsoleRead()   412 ;~                      $vResumeVar = ConsoleRead()
385 ;~                      $vResumeVar = _UnpackStrToVar($vResumeVar)   413 ;~                      $vResumeVar = _UnpackStrToVar($vResumeVar)
386 ;~                      SetExtended(1)   414 ;~                      SetExtended(1)
387 ;~                      Return $vResumeVar   415 ;~                      Return $vResumeVar
388 ;~              Else   416 ;~              Else
389 ;~                      SetExtended(0)   417 ;~                      SetExtended(0)
390 ;~                      Return ""   418 ;~                      Return ""
391 ;~              EndIf   419 ;~              EndIf
392 ;~      Else   420 ;~      Else
393 ;~              Local $vVarNameEval = "" ; If $sVarName equates to a declared variable, a copy of it is stored here   421 ;~              Local $vVarNameEval = "" ; If $sVarName equates to a declared variable, a copy of it is stored here
394 ;~              Local $vResumeVar = "" ; When _CoResume() is called to unpause script, a variable can be passed   422 ;~              Local $vResumeVar = "" ; When _CoResume() is called to unpause script, a variable can be passed
395 ;~              If StringLeft($sVarName, 1) == "$" Then StringReplace($sVarName, "$", "")   423 ;~              If StringLeft($sVarName, 1) == "$" Then StringReplace($sVarName, "$", "")
396 ;~              If IsDeclared($sVarName) Then   424 ;~              If IsDeclared($sVarName) Then
397 ;~                      $vVarNameEval = Eval($sVarName)   425 ;~                      $vVarNameEval = Eval($sVarName)
398 ;~                      $vVarNameEval = _PackVarToStr($vVarNameEval)   426 ;~                      $vVarNameEval = _PackVarToStr($vVarNameEval)
399 ;~                      ConsoleWrite("yield" & StrLen($vVarNameEval) & $vVarNameEval)   427 ;~                      ConsoleWrite("yield" & StrLen($vVarNameEval) & $vVarNameEval)
400 ;~              Else   428 ;~              Else
401 ;~                      $vVarName = _PackVarToStr($vVarName)   429 ;~                      $vVarName = _PackVarToStr($vVarName)
402 ;~                      ConsoleWrite("yield" & StrLen($vVarName) & $vVarName   430 ;~                      ConsoleWrite("yield" & StrLen($vVarName) & $vVarName
403 ;~              EndIf   431 ;~              EndIf
404 ;~              While ConsoleRead(0,true) == 0   432 ;~              While ConsoleRead(0,true) == 0
405 ;~                      Sleep(50)   433 ;~                      Sleep(50)
406 ;~              WEnd   434 ;~              WEnd
407 ;~              $vResumeVar = ConsoleRead()   435 ;~              $vResumeVar = ConsoleRead()
408 ;~              $vResumeVar = _UnpackStrToVar($vResumeVar)   436 ;~              $vResumeVar = _UnpackStrToVar($vResumeVar)
409 ;~              Return $vResumeVar   437 ;~              Return $vResumeVar
410 ;~      EndIf   438 ;~      EndIf
411 ;~ EndFunc   439 ;~ EndFunc
412     440  
413 ;===============================================================================   441 ;===============================================================================
414 ;   442 ;
415 ; Function Name:    _CoInclude()   443 ; Function Name:    _CoInclude()
416 ; Description:      Include a UDF(s) in the coroutine script.   444 ; Description:      Include a UDF(s) in the coroutine script.
417 ;                                               NOTE: #include <something.au3> will work in _CoCreate()   445 ;                                               NOTE: #include <something.au3> will work in _CoCreate()
418 ;                                               but keep in mind that the "something.au3" file must   446 ;                                               but keep in mind that the "something.au3" file must
419 ;                                               exist on the computer that is running the script.   447 ;                                               exist on the computer that is running the script.
420 ; Parameter(s):     $iCoThreadID - The thread to add the include to   448 ; Parameter(s):     $iCoThreadID - The thread to add the include to
421 ;                                       $sFuncRawText - The function text, delimited by $sDelimiter   449 ;                                       $sFuncRawText - The function text, delimited by $sDelimiter
422 ;                                       $sDelimiter - Used to delimit $sFuncRawText (Default "|")   450 ;                                       $sDelimiter - Used to delimit $sFuncRawText (Default "|")
423 ; Return Value(s):  Success - 1   451 ; Return Value(s):  Success - 1
424 ;                                       Failure - 0 and @error set to:   452 ;                                       Failure - 0 and @error set to:
425 ;                                                               1 - Invalid iCoThreadID   453 ;                                                               1 - Invalid iCoThreadID
426 ;                                                               2 - Invalid delimiter or delimiter not found   454 ;                                                               2 - Invalid delimiter or delimiter not found
427 ;                                                               3 - Code formatted incorrectly. Namely mis-   455 ;                                                               3 - Code formatted incorrectly. Namely mis-
428 ;                                                                       matched number of "Func ..." and "EndFunc"   456 ;                                                                       matched number of "Func ..." and "EndFunc"
429 ;                                                                       lines.   457 ;                                                                       lines.
430 ;                                                               4 - Script file could not be opened.   458 ;                                                               4 - Script file could not be opened.
431 ; Author(s):        Ben Brightwell   459 ; Author(s):        Ben Brightwell
432 ;   460 ;
433 ;===============================================================================   461 ;===============================================================================
434 Func _CoInclude($iCoThreadID, $sFuncRawText, $sDelimiter = "|")   462 Func _CoInclude($iCoThreadID, $sFuncRawText, $sDelimiter = "|")
435         Local $asFuncLines = "" ; Array holding the lines of code stripped from $sFuncRawText   463         Local $asFuncLines = "" ; Array holding the lines of code stripped from $sFuncRawText
436         Local $sFormattedCode = "" ; String to write to the script file   464         Local $sFormattedCode = "" ; String to write to the script file
437         Local $iNumFuncs = 0 ; Number of lines that contain "Func ...". Used for minimal codechecking   465         Local $iNumFuncs = 0 ; Number of lines that contain "Func ...". Used for minimal codechecking
438         Local $iNumEndFuncs = 0 ; Number of lines that contain "EndFunc". Used for minimal codechecking   466         Local $iNumEndFuncs = 0 ; Number of lines that contain "EndFunc". Used for minimal codechecking
439         Local $iFileCheck = 0 ; Used to check if file was written to correctly.   467         Local $iFileCheck = 0 ; Used to check if file was written to correctly.
440         Local $sPrevContents = "" ; Used to store contents of original coroutine script.   468         Local $sPrevContents = "" ; Used to store contents of original coroutine script.
441         Local $hFile = "" ; Handle for source file   469         Local $hFile = "" ; Handle for source file
442         If $iCoThreadID <= $avCoThreads[0][0] Then   470         If $iCoThreadID <= $avCoThreads[0][0] Then
443                 $asFuncLines = StringSplit($sFuncRawText, $sDelimiter)   471                 $asFuncLines = StringSplit($sFuncRawText, $sDelimiter)
444                 If IsArray($asFuncLines) Then   472                 If IsArray($asFuncLines) Then
445                         $sFormattedCode &= ';============' & @CRLF   473                         $sFormattedCode &= ';============' & @CRLF
446                         $sFormattedCode &= ';Include Code' & @CRLF   474                         $sFormattedCode &= ';Include Code' & @CRLF
447                         $sFormattedCode &= ';============' & @CRLF   475                         $sFormattedCode &= ';============' & @CRLF
448                         For $i = 1 To $asFuncLines[0]   476                         For $i = 1 To $asFuncLines[0]
449                                 If StringInStr($asFuncLines[$i], "endfunc") Then <> 477                                 If _LineIsFunction($asFuncLines[$i]) Then
      478                                         If @Error = 1 Then
450                                         $iNumEndFuncs += 1   479                                                 $iNumFuncs += 1
451                                 ElseIf StringInStr($asFuncLines[$i], "func") Then   480                                         Else ; error is 2
452                                         $iNumFuncs += 1   481                                                 $iNumEndFuncs += 1
      482                                         EndIf
453                                 EndIf = 483                                 EndIf
454                         Next   484                         Next
455                         If $iNumFuncs == $iNumEndFuncs Then   485                         If $iNumFuncs == $iNumEndFuncs Then
456                                 For $i = 1 To $asFuncLines[0]   486                                 For $i = 1 To $asFuncLines[0]
457                                         $sFormattedCode &= $asFuncLines[$i] & @CRLF   487                                         $sFormattedCode &= $asFuncLines[$i] & @CRLF
458                                 Next   488                                 Next
459                         Else   489                         Else
460                                 SetError(3) ; Code formatted incorrectly   490                                 SetError(3) ; Code formatted incorrectly
461                                 Return 0 ; failure   491                                 Return 0 ; failure
462                         EndIf   492                         EndIf
463                 Else   493                 Else
464                         SetError(2) ; Delimiter not found in $sFuncRawText   494                         SetError(2) ; Delimiter not found in $sFuncRawText
465                         Return 0 ; failure   495                         Return 0 ; failure
466                 EndIf   496                 EndIf
467                 $sPrevContents = FileRead($avCoThreads[$iCoThreadID][0]) <> 497                 $sPrevContents = FileRead($avCoThreads[$iCoThreadID][0]) ; read old contents
468                 $hFile = FileOpen($avCoThreads[$iCoThreadID][0], 2)   498                 $hFile = FileOpen($avCoThreads[$iCoThreadID][0], 2) ; mode 2=overwrite
469                 If FileWrite($hFile, $sFormattedCode) == 0 Then   499                 If FileWrite($hFile, $sFormattedCode) == 0 Then ; write header to file
470                         SetError(4) ; File could not be written to = 500                         SetError(4) ; File could not be written to
471                         Return 0 ; failure   501                         Return 0 ; failure
472                 Else   502                 Else
473                         FileClose($hFile) <> 503                         FileClose($hFile) ; close file to reopen in another mode
474                         $hFile = FileOpen($avCoThreads[$iCoThreadID][0], 1)   504                         $hFile = FileOpen($avCoThreads[$iCoThreadID][0], 1) ; mode 1=append
475                         FileWrite($hFile, $sPrevContents)   505                         FileWrite($hFile, $sPrevContents) ; re-add old content
      506                         FileClose($hFile) ; important: close the file, which you forgot
476                 EndIf = 507                 EndIf
477         Else   508         Else
478                 SetError(1) ; Invalid iCoThreadID   509                 SetError(1) ; Invalid iCoThreadID
479                 Return 0 ; <> 510                 Return 0 ; failure
480         EndIf = 511         EndIf
    -+ 512         Return 1 ; success
481 EndFunc = 513 EndFunc
482     514  
483 ;===============================================================================   515 ;===============================================================================
484 ;   516 ;
485 ; Function Name:    _CoStart()   517 ; Function Name:    _CoStart()
486 ; Description:      Create a coroutine from a thread created by _CoCreate()   518 ; Description:      Create a coroutine from a thread created by _CoCreate()
487 ; Parameter(s):     $iCoThreadID - as returned by _CoCreate()   519 ; Parameter(s):     $iCoThreadID - as returned by _CoCreate()
488 ;                                       $sParamStr - the string you would call a normal function   520 ;                                       $sParamStr - the string you would call a normal function
489 ;                                               with. Example: MyFunc($test1, $test2)   521 ;                                               with. Example: MyFunc($test1, $test2)
490 ;                                               $sParamStr = "$test1, $test2"   522 ;                                               $sParamStr = "$test1, $test2"
491 ; Return Value(s):  On Success - the PID of the created coroutine   523 ; Return Value(s):  On Success - the PID of the created coroutine
492 ;                   On Failure - -1 and sets @error to:   524 ;                   On Failure - -1 and sets @error to:
493 ;                                                                       1 - Invalid iCoThreadID   525 ;                                                                       1 - Invalid iCoThreadID
494 ;                                                                       2 - Parameter string formatted incorrectly   526 ;                                                                       2 - Parameter string formatted incorrectly
495 ; Author(s):        Ben Brightwell   527 ; Author(s):        Ben Brightwell
496 ;   528 ;
497 ;===============================================================================   529 ;===============================================================================
498 Func _CoStart($iCoThreadID, $sParamStr = "")   530 Func _CoStart($iCoThreadID, $sParamStr = "")
499         Local $sPackedParamStr = "" ; If arrays exist in $sParamStr, then they need to be packed into a string   531         Local $sPackedParamStr = "" ; If arrays exist in $sParamStr, then they need to be packed into a string
500         Local $asParams = "" ; Holds individual parameters parsed from $sParamStr   532         Local $asParams = "" ; Holds individual parameters parsed from $sParamStr
501         Local $sStrippedParam = "" ; Holds a parameter stripped of "$" and ","   533         Local $sStrippedParam = "" ; Holds a parameter stripped of "$" and ","
502         Local $vParamEval = "" ; If $sStrippedParam is a valid variable, a temporary one is evaluated to this container   534         Local $vParamEval = "" ; If $sStrippedParam is a valid variable, a temporary one is evaluated to this container
503         Local $sParamLiteral = "" ; If a non-variable is passed, it is interpreted as a literal   535         Local $sParamLiteral = "" ; If a non-variable is passed, it is interpreted as a literal
504         If $iCoThreadID <= $avCoThreads[0][0] And $iCoThreadID <> 0 Then   536         If $iCoThreadID <= $avCoThreads[0][0] And $iCoThreadID <> 0 Then
505                 ReDim $avPIDs[$avPIDs[0][0] + 2][2]   537                 ReDim $avPIDs[$avPIDs[0][0] + 2][2]
506                 $avPIDs[0][0] += 1   538                 $avPIDs[0][0] += 1
507                 If $sParamStr <> "" Then   539                 If $sParamStr <> "" Then
508                         If StringRight($sParamStr, 1) <> "," Then   540                         If StringRight($sParamStr, 1) <> "," Then
509                                 $sParamStr &= "," ; Makes $sParamStr easier to parse with StringRegExp   541                                 $sParamStr &= "," ; Makes $sParamStr easier to parse with StringRegExp
510                         EndIf   542                         EndIf
511                         $asParams = StringRegExp($sParamStr, '(".*?".*?,|[^ ]*?[ ]?,)*', 3)   543                         $asParams = StringRegExp($sParamStr, '(".*?".*?,|[^ ]*?[ ]?,)*', 3)
512                         If Not IsArray($asParams) Then   544                         If Not IsArray($asParams) Then
513                                 SetError(2) ; Parameter string not formatted correctly   545                                 SetError(2) ; Parameter string not formatted correctly
514                                 Return -1 ; failure   546                                 Return -1 ; failure
515                         EndIf   547                         EndIf
516                         For $i = 0 To UBound($asParams) - 1   548                         For $i = 0 To UBound($asParams) - 1
517                                 If StringInStr($asParams[$i], "$") Then   549                                 If StringInStr($asParams[$i], "$") Then
518                                         $sStrippedParam = StringReplace(StringReplace($asParams[$i], "$", ""), ",", "")   550                                         $sStrippedParam = StringReplace(StringReplace($asParams[$i], "$", ""), ",", "")
519                                         If IsDeclared($sStrippedParam) Then   551                                         If IsDeclared($sStrippedParam) Then
520                                                 $vParamEval = Eval($sStrippedParam)   552                                                 $vParamEval = Eval($sStrippedParam)
521                                                 $sPackedParamStr &= _PackVarToStr($vParamEval)   553                                                 $sPackedParamStr &= _PackVarToStr($vParamEval)
522                                         Else   554                                         Else
523                                                 $sParamLiteral = StringTrimRight($asParams[$i], 1)   555                                                 $sParamLiteral = StringTrimRight($asParams[$i], 1)
524                                                 $sPackedParamStr &= _PackVarToStr($sParamLiteral)   556                                                 $sPackedParamStr &= _PackVarToStr($sParamLiteral)
525                                         EndIf   557                                         EndIf
526                                 Else   558                                 Else
527                                         $sParamLiteral = StringTrimRight($asParams[$i], 1)   559                                         $sParamLiteral = StringTrimRight($asParams[$i], 1)
528                                         $sPackedParamStr &= _PackVarToStr($sParamLiteral)   560                                         $sPackedParamStr &= _PackVarToStr($sParamLiteral)
529                                 EndIf   561                                 EndIf
530                         Next   562                         Next
531                 EndIf   563                 EndIf
532                 $avPIDs[$avPIDs[0][0]][0] = Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & $avCoThreads[$iCoThreadID][0] & '"', "", "", 7)   564                 $avPIDs[$avPIDs[0][0]][0] = Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & $avCoThreads[$iCoThreadID][0] & '"', "", "", 7)
533                 If StringLen($sPackedParamStr) > 0 Then   565                 If StringLen($sPackedParamStr) > 0 Then
534                         StdinWrite($avPIDs[$avPIDs[0][0]][0], StringLen($sPackedParamStr) & $sPackedParamStr)   566                         StdinWrite($avPIDs[$avPIDs[0][0]][0], StringLen($sPackedParamStr) & $sPackedParamStr)
535                 EndIf   567                 EndIf
536                 $avPIDs[$avPIDs[0][0]][1] = $iCoThreadID   568                 $avPIDs[$avPIDs[0][0]][1] = $iCoThreadID
537                 Return $avPIDs[$avPIDs[0][0]][0]   569                 Return $avPIDs[$avPIDs[0][0]][0]
538         Else   570         Else
539                 SetError(1) ;Invalid iCoThreadID   571                 SetError(1) ;Invalid iCoThreadID
540                 Return -1 ; failure   572                 Return -1 ; failure
541         EndIf   573         EndIf
542 EndFunc   ;==>_CoStart   574 EndFunc   ;==>_CoStart
543     575  
544 ;===============================================================================   576 ;===============================================================================
545 ;   577 ;
546 ; Function Name:    _CoStatus()   578 ; Function Name:    _CoStatus()
547 ; Description:      Determines the status of a PID returned by _CoStart()   579 ; Description:      Determines the status of a PID returned by _CoStart()
548 ; Parameter(s):     $iPID - PID as returned by _CoStart()   580 ; Parameter(s):     $iPID - PID as returned by _CoStart()
549 ; Return Value(s):  On Success - Returns the status of the coroutine   581 ; Return Value(s):  On Success - Returns the status of the coroutine
550 ;                                               Possible values: "yielded" - yielded a value, script paused   582 ;                                               Possible values: "yielded" - yielded a value, script paused
551 ;                                                                                "running" - running   583 ;                                                                                "running" - running
552 ;                                                                                "returned" - coroutine dead, with a return value   584 ;                                                                                "returned" - coroutine dead, with a return value
553 ;                                                                                "dead" - coroutine dead with no return value   585 ;                                                                                "dead" - coroutine dead with no return value
554 ;                   On Failure - Returns empty string ("") and sets error to 1   586 ;                   On Failure - Returns empty string ("") and sets error to 1
555 ; Author(s):        Ben Brightwell   587 ; Author(s):        Ben Brightwell
556 ;   588 ;
557 ;===============================================================================   589 ;===============================================================================
558 Func _CoStatus($iPID)   590 Func _CoStatus($iPID)
559         Local $bPIDFound = 0 ; Used to search for a PID created by _CoStart()   591         Local $bPIDFound = 0 ; Used to search for a PID created by _CoStart()
560         For $i = 1 To $avPIDs[0][0]   592         For $i = 1 To $avPIDs[0][0]
561                 If $avPIDs[$i][0] == $iPID Then   593                 If $avPIDs[$i][0] == $iPID Then
562                         $bPIDFound = 1   594                         $bPIDFound = 1
563                 EndIf   595                 EndIf
564         Next   596         Next
565         If $bPIDFound == 1 Then   597         If $bPIDFound == 1 Then
566                 Select   598                 Select
567                         Case ProcessExists($iPID) <> 0   599                         Case ProcessExists($iPID) <> 0
568                                 If StdoutRead($iPID, 5, True) == "yield" Then   600                                 If StdoutRead($iPID, 5, True) == "yield" Then
569                                         Return "yielded"   601                                         Return "yielded"
570                                 ElseIf StdoutRead($iPID, 6, True) == "return" Then   602                                 ElseIf StdoutRead($iPID, 6, True) == "return" Then
571                                         Return "returned" ; Coroutine returned, but return string is longer than console buffer   603                                         Return "returned" ; Coroutine returned, but return string is longer than console buffer
572                                 Else   604                                 Else
573                                         Return "running"   605                                         Return "running"
574                                 EndIf   606                                 EndIf
575                         Case ProcessExists($iPID) == 0   607                         Case ProcessExists($iPID) == 0
576                                 If StdoutRead($iPID, 0, True) <> 0 Then   608                                 If StdoutRead($iPID, 0, True) <> 0 Then
577                                         Return "returned"   609                                         Return "returned"
578                                 Else   610                                 Else
579                                         Return "dead"   611                                         Return "dead"
580                                 EndIf   612                                 EndIf
581                 EndSelect   613                 EndSelect
582         Else   614         Else
583                 SetError(1) ;$PID not created with _CoStart()   615                 SetError(1) ;$PID not created with _CoStart()
584                 Return ""   616                 Return ""
585         EndIf   617         EndIf
586 EndFunc   ;==>_CoStatus   618 EndFunc   ;==>_CoStatus
587     619  
588 ;===============================================================================   620 ;===============================================================================
589 ;   621 ;
590 ; Function Name:    _CoSend()   622 ; Function Name:    _CoSend()
591 ; Description:      Sends a variable to the child script.   623 ; Description:      Sends a variable to the child script.
592 ; Parameter(s):     $iPID - PID as returned by _CoStart()   624 ; Parameter(s):     $iPID - PID as returned by _CoStart()
593 ; Return Value(s):  On Success - none   625 ; Return Value(s):  On Success - none
594 ;                   On Failure - Returns empty string ("") and sets error to 1   626 ;                   On Failure - Returns empty string ("") and sets error to 1
595 ; Author(s):        Ben Brightwell   627 ; Author(s):        Ben Brightwell
596 ;   628 ;
597 ;===============================================================================   629 ;===============================================================================
598 Func _CoSend($iPID, $vInVar)   630 Func _CoSend($iPID, $vInVar)
599         If _CoStatus($iPID) <> "dead" And _CoStatus($iPID) <> "returned" And _CoStatus($iPID) <> "yielded" Then   631         If _CoStatus($iPID) <> "dead" And _CoStatus($iPID) <> "returned" And _CoStatus($iPID) <> "yielded" Then
600                 StdinWrite($iPID, _PackVarToStr($vInVar))   632                 StdinWrite($iPID, _PackVarToStr($vInVar))
601         Else   633         Else
602                 SetError(1)   634                 SetError(1)
603                 Return ""   635                 Return ""
604         EndIf   636         EndIf
605 EndFunc   637 EndFunc
606     638  
607 ;===============================================================================   639 ;===============================================================================
608 ;   640 ;
609 ; Function Name:    _CoResume()   641 ; Function Name:    _CoResume()
610 ; Description:      Resumes a paused coroutine and returns the yielded variable   642 ; Description:      Resumes a paused coroutine and returns the yielded variable
611 ; Parameter(s):     $iPID - PID as returned by _CoStart()   643 ; Parameter(s):     $iPID - PID as returned by _CoStart()
612 ; Return Value(s):  On Success - Resumes paused coroutine and returns variable   644 ; Return Value(s):  On Success - Resumes paused coroutine and returns variable
613 ;                                               yielded by _CoYield()   645 ;                                               yielded by _CoYield()
614 ;                   On Failure - Returns empty string ("") and sets error to 1   646 ;                   On Failure - Returns empty string ("") and sets error to 1
615 ; Author(s):        Ben Brightwell   647 ; Author(s):        Ben Brightwell
616 ;   648 ;
617 ;===============================================================================   649 ;===============================================================================
618 Func _CoResume($iPID, $vInVar = "")   650 Func _CoResume($iPID, $vInVar = "")
619         Local $sReturnStr = "" ; Contains return string   651         Local $sReturnStr = "" ; Contains return string
620         Local $iNumChrsToRead = 0 ; Number of chars to read   652         Local $iNumChrsToRead = 0 ; Number of chars to read
621         Local $iTotalChrsRead = 0 ; Total chars currently read   653         Local $iTotalChrsRead = 0 ; Total chars currently read
622         If _CoStatus($iPID) == "yielded" Then   654         If _CoStatus($iPID) == "yielded" Then
623                 If StdoutRead($iPID, 0, True) > 5 Then   655                 If StdoutRead($iPID, 0, True) > 5 Then
624                         $sReturnStr = StringTrimLeft(StdoutRead($iPID), 5)   656                         $sReturnStr = StringTrimLeft(StdoutRead($iPID), 5)
625                         $iNumChrsToRead = StringRegExp($sReturnStr, "(\d*?)(\#)(?:\$\[)", 1)   657                         $iNumChrsToRead = StringRegExp($sReturnStr, "(\d*?)(\#)(?:\$\[)", 1)
626                         $sReturnStr = StringTrimLeft($sReturnStr, $iNumChrsToRead[1])   658                         $sReturnStr = StringTrimLeft($sReturnStr, $iNumChrsToRead[1])
627                         While StringLen($sReturnStr) <= $iNumChrsToRead[0]   659                         While StringLen($sReturnStr) <= $iNumChrsToRead[0]
628                                 $sReturnStr &= StdoutRead($iPID)   660                                 $sReturnStr &= StdoutRead($iPID)
629                         WEnd   661                         WEnd
630                         StdinWrite($iPID, _PackVarToStr($vInVar))   662                         StdinWrite($iPID, _PackVarToStr($vInVar))
631                         Return _UnpackStrToVar($sReturnStr)   663                         Return _UnpackStrToVar($sReturnStr)
632                 EndIf   664                 EndIf
633         Else   665         Else
634                 SetError(1) ;$PID is not yielded   666                 SetError(1) ;$PID is not yielded
635                 Return ""   667                 Return ""
636         EndIf   668         EndIf
637 EndFunc   ;==>_CoResume   669 EndFunc   ;==>_CoResume
638     670  
639 ;===============================================================================   671 ;===============================================================================
640 ;   672 ;
641 ; Function Name:    _CoGetReturn()   673 ; Function Name:    _CoGetReturn()
642 ; Description:      Returns the variable returned by a coroutine   674 ; Description:      Returns the variable returned by a coroutine
643 ; Parameter(s):     $iPID - PID as returned by _CoStart()   675 ; Parameter(s):     $iPID - PID as returned by _CoStart()
644 ; Return Value(s):  On Success - Returns variable returned by coroutine   676 ; Return Value(s):  On Success - Returns variable returned by coroutine
645 ;                   On Failure - Returns empty string ("") and sets error to 1   677 ;                   On Failure - Returns empty string ("") and sets error to 1
646 ; Author(s):        Ben Brightwell   678 ; Author(s):        Ben Brightwell
647 ;   679 ;
648 ;===============================================================================   680 ;===============================================================================
649 Func _CoGetReturn($iPID)   681 Func _CoGetReturn($iPID)
650         Local $sReturnStr = "" ; Contains return string   682         Local $sReturnStr = "" ; Contains return string
651         Local $iNumChrsToRead = 0 ; Number of chars to read   683         Local $iNumChrsToRead = 0 ; Number of chars to read
652         Local $iTotalChrsRead = 0 ; Total chars currently read   684         Local $iTotalChrsRead = 0 ; Total chars currently read
653         If _CoStatus($iPID) == "returned" Then   685         If _CoStatus($iPID) == "returned" Then
654                 $sReturnStr = StdoutRead($iPID)   686                 $sReturnStr = StdoutRead($iPID)
655                 $iNumChrsToRead = StringRegExp($sReturnStr, "(\d*?)(\#)(?:\$\[)", 1)   687                 $iNumChrsToRead = StringRegExp($sReturnStr, "(\d*?)(\#)(?:\$\[)", 1)
656                 $sReturnStr = StringTrimLeft($sReturnStr, $iNumChrsToRead[1])   688                 $sReturnStr = StringTrimLeft($sReturnStr, $iNumChrsToRead[1])
657                 While StringLen($sReturnStr) < $iNumChrsToRead[0]   689                 While StringLen($sReturnStr) < $iNumChrsToRead[0]
658                         $sReturnStr &= StdoutRead($iPID)   690                         $sReturnStr &= StdoutRead($iPID)
659                 WEnd   691                 WEnd
660                 Return _UnpackStrToVar($sReturnStr)   692                 Return _UnpackStrToVar($sReturnStr)
661         Else   693         Else
662                 SetError(1) ; $PID not returned   694                 SetError(1) ; $PID not returned
663                 Return ""   695                 Return ""
664         EndIf   696         EndIf
665 EndFunc   ;==>_CoGetReturn   697 EndFunc   ;==>_CoGetReturn
666     698  
667 ;===============================================================================   699 ;===============================================================================
668 ;   700 ;
669 ; Function Name:    _CoKill()   701 ; Function Name:    _CoKill()
670 ; Description:      Kills a running coroutine   702 ; Description:      Kills a running coroutine
671 ; Parameter(s):     $iPID - PID as returned by _CoStart()   703 ; Parameter(s):     $iPID - PID as returned by _CoStart()
672 ; Return Value(s):  On Success - Returns 1   704 ; Return Value(s):  On Success - Returns 1
673 ;                   On Failure - Returns 0   705 ;                   On Failure - Returns 0
674 ; Author(s):        Ben Brightwell   706 ; Author(s):        Ben Brightwell
675 ;   707 ;
676 ;===============================================================================   708 ;===============================================================================
677 Func _CoKill($iPID)   709 Func _CoKill($iPID)
678         If ProcessExists($iPID) <> 0 Then   710         If ProcessExists($iPID) <> 0 Then
679                 ProcessClose($iPID)   711                 ProcessClose($iPID)
680                 Return 1   712                 Return 1
681         Else   713         Else
682                 Return 0   714                 Return 0
683         EndIf   715         EndIf
684 EndFunc   ;==>_CoKill   716 EndFunc   ;==>_CoKill
685     717  
686 ;===============================================================================   718 ;===============================================================================
687 ;   719 ;
688 ; Function Name:    _CoCleanup()   720 ; Function Name:    _CoCleanup()
689 ; Description:      Kills all coroutines and deletes their respective temp files   721 ; Description:      Kills all coroutines and deletes their respective temp files
690 ; Parameter(s):     none   722 ; Parameter(s):     none
691 ; Return Value(s):  none   723 ; Return Value(s):  none
692 ; Author(s):        Ben Brightwell   724 ; Author(s):        Ben Brightwell
693 ;   725 ;
694 ;===============================================================================   726 ;===============================================================================
695 Func _CoCleanup()   727 Func _CoCleanup()
696         For $i = 1 To $avPIDs[0][0]   728         For $i = 1 To $avPIDs[0][0]
697                 _CoKill($avPIDs[$i][0])   729                 _CoKill($avPIDs[$i][0])
698         Next   730         Next
699         For $i = 1 To $avCoThreads[0][0]   731         For $i = 1 To $avCoThreads[0][0]
700                 FileDelete($avCoThreads[$i][0])   732                 FileDelete($avCoThreads[$i][0])
701         Next   733         Next
702 EndFunc   ;==>_CoCleanup   734 EndFunc   ;==>_CoCleanup
703     735  
704 ;===============================================================================   736 ;===============================================================================
705 ;   737 ;
706 ; Function Name:    _CoChangeWorkingDir()   738 ; Function Name:    _CoChangeWorkingDir()
707 ; Description:      Changes the directory to store coroutine temp files in   739 ; Description:      Changes the directory to store coroutine temp files in
708 ;                                               NOTE: does not currently check for proper directory   740 ;                                               NOTE: does not currently check for proper directory
709 ;                                               structure   741 ;                                               structure
710 ; Parameter(s):     $sDir = String representing the new working directory   742 ; Parameter(s):     $sDir = String representing the new working directory
711 ; Return Value(s):  none   743 ; Return Value(s):  none
712 ; Author(s):        Ben Brightwell   744 ; Author(s):        Ben Brightwell
713 ;   745 ;
714 ;===============================================================================   746 ;===============================================================================
715 Func _CoChangeWorkingDir($sDir)   747 Func _CoChangeWorkingDir($sDir)
716         $workingDir = $sDir <> 748         $sWorkingDir = $sDir
717 EndFunc   ;==>_CoChangeWorkingDir = 749 EndFunc   ;==>_CoChangeWorkingDir
718     750  
719 ;===============================================================================   751 ;===============================================================================
720 ;   752 ;
721 ; Function Name:    _UnpackStrToVar()   753 ; Function Name:    _UnpackStrToVar()
722 ; Description:      Turns a packed variable string back into a variable.   754 ; Description:      Turns a packed variable string back into a variable.
723 ; Parameter(s):     $sVarStr = A packed variable string as returned by _PackVarToStr()   755 ; Parameter(s):     $sVarStr = A packed variable string as returned by _PackVarToStr()
724 ; Return Value(s):  Variable of type that was passed to _PackVarToStr()   756 ; Return Value(s):  Variable of type that was passed to _PackVarToStr()
725 ; Author(s):        Ben Brightwell   757 ; Author(s):        Ben Brightwell
726 ;   758 ;
727 ;===============================================================================   759 ;===============================================================================
728 Func _UnpackStrToVar(ByRef $sVarStr)   760 Func _UnpackStrToVar(ByRef $sVarStr)
729         Local $aiNumDims = StringRegExp($sVarStr, '(?:\$\[)(\d*)(?:\]\$)(\#)', 1)   761         Local $aiNumDims = StringRegExp($sVarStr, '(?:\$\[)(\d*)(?:\]\$)(\#)', 1)
730         Local $aiDimSizes[1] ; To contain the size of each dimension as passed through $sVarStr   762         Local $aiDimSizes[1] ; To contain the size of each dimension as passed through $sVarStr
731         Local $aiDimSize = "" ; To contain the size of current dimension and string position for stripping   763         Local $aiDimSize = "" ; To contain the size of current dimension and string position for stripping
732         Local $avRetArr[1] ; To be redimensioned and have $sVarStr parsed and stored into as an array   764         Local $avRetArr[1] ; To be redimensioned and have $sVarStr parsed and stored into as an array
733         Local $avElementStr = "" ; To contain each element as a string as it is parsed from $sVarStr   765         Local $avElementStr = "" ; To contain each element as a string as it is parsed from $sVarStr
734         If IsArray($aiNumDims) Then   766         If IsArray($aiNumDims) Then
735                 $sVarStr = StringTrimLeft($sVarStr, $aiNumDims[1])   767                 $sVarStr = StringTrimLeft($sVarStr, $aiNumDims[1])
736                 If $aiNumDims[0] > 0 Then   768                 If $aiNumDims[0] > 0 Then
737                         ReDim $aiDimSizes[$aiNumDims[0]]   769                         ReDim $aiDimSizes[$aiNumDims[0]]
738                         For $iCounter1 = 0 To $aiNumDims[0] - 1   770                         For $iCounter1 = 0 To $aiNumDims[0] - 1
739                                 $aiDimSize = StringRegExp($sVarStr, '(?:\$\[)(\d*)(?:\]\$)(\#)', 1)   771                                 $aiDimSize = StringRegExp($sVarStr, '(?:\$\[)(\d*)(?:\]\$)(\#)', 1)
740                                 $aiDimSizes[$iCounter1] = $aiDimSize[0]   772                                 $aiDimSizes[$iCounter1] = $aiDimSize[0]
741                                 $sVarStr = StringTrimLeft($sVarStr, $aiDimSize[1])   773                                 $sVarStr = StringTrimLeft($sVarStr, $aiDimSize[1])
742                         Next   774                         Next
743                 EndIf   775                 EndIf
744                 Select   776                 Select
745                         Case $aiNumDims[0] == 0   777                         Case $aiNumDims[0] == 0
746                                 If StringInStr($sVarStr, "$[") Then   778                                 If StringInStr($sVarStr, "$[") Then
747                                         $avElementStr = StringRegExp($sVarStr, '(.*?)(\#)(?:\$\[)', 1)   779                                         $avElementStr = StringRegExp($sVarStr, '(.*?)(\#)(?:\$\[)', 1)
748                                         $sVarStr = StringTrimLeft($sVarStr, $avElementStr[1])   780                                         $sVarStr = StringTrimLeft($sVarStr, $avElementStr[1])
749                                         If $avElementStr[0] <> "<nil>" Then   781                                         If $avElementStr[0] <> "<nil>" Then
750                                                 Return $avElementStr[0]   782                                                 Return $avElementStr[0]
751                                         Else   783                                         Else
752                                                 Return ""   784                                                 Return ""
753                                         EndIf   785                                         EndIf
754                                 Else   786                                 Else
755                                         If $sVarStr == "<nil>" Then   787                                         If $sVarStr == "<nil>" Then
756                                                 Return ""   788                                                 Return ""
757                                         Else   789                                         Else
758                                                 Return $sVarStr   790                                                 Return $sVarStr
759                                         EndIf   791                                         EndIf
760                                 EndIf   792                                 EndIf
761                         Case $aiNumDims[0] == 1   793                         Case $aiNumDims[0] == 1
762                                 ReDim $avRetArr[$aiDimSizes[0]]   794                                 ReDim $avRetArr[$aiDimSizes[0]]
763                                 For $iCounter1 = 0 To $aiDimSizes[0] - 1   795                                 For $iCounter1 = 0 To $aiDimSizes[0] - 1
764                                         $avRetArr[$iCounter1] = _UnpackStrToVar($sVarStr) ; In case element holds another array (Recursive)   796                                         $avRetArr[$iCounter1] = _UnpackStrToVar($sVarStr) ; In case element holds another array (Recursive)
765                                 Next   797                                 Next
766                         Case $aiNumDims[0] == 2   798                         Case $aiNumDims[0] == 2
767                                 ReDim $avRetArr[$aiDimSizes[0]][$aiDimSizes[1]]   799                                 ReDim $avRetArr[$aiDimSizes[0]][$aiDimSizes[1]]
768                                 For $iCounter1 = 0 To $aiDimSizes[0] - 1   800                                 For $iCounter1 = 0 To $aiDimSizes[0] - 1
769                                         For $iCounter2 = 0 To $aiDimSizes[1] - 1   801                                         For $iCounter2 = 0 To $aiDimSizes[1] - 1
770                                                 $avRetArr[$iCounter1][$iCounter2] = _UnpackStrToVar($sVarStr) ; In case element holds another array (Recursive)   802                                                 $avRetArr[$iCounter1][$iCounter2] = _UnpackStrToVar($sVarStr) ; In case element holds another array (Recursive)
771                                         Next   803                                         Next
772                                 Next   804                                 Next
773                         Case $aiNumDims[0] == 3   805                         Case $aiNumDims[0] == 3
774                                 ReDim $avRetArr[$aiDimSizes[0]][$aiDimSizes[1]][$aiDimSizes[2]]   806                                 ReDim $avRetArr[$aiDimSizes[0]][$aiDimSizes[1]][$aiDimSizes[2]]
775                                 For $iCounter1 = 0 To $aiDimSizes[0] - 1   807                                 For $iCounter1 = 0 To $aiDimSizes[0] - 1
776                                         For $iCounter2 = 0 To $aiDimSizes[1] - 1   808                                         For $iCounter2 = 0 To $aiDimSizes[1] - 1
777                                                 For $iCounter3 = 0 To $aiDimSizes[2] - 1   809                                                 For $iCounter3 = 0 To $aiDimSizes[2] - 1
778                                                         $avRetArr[$iCounter1][$iCounter2][$iCounter3] = _UnpackStrToVar($sVarStr) ; In case element holds another array (Recursive)   810                                                         $avRetArr[$iCounter1][$iCounter2][$iCounter3] = _UnpackStrToVar($sVarStr) ; In case element holds another array (Recursive)
779                                                 Next   811                                                 Next
780                                         Next   812                                         Next
781                                 Next   813                                 Next
782                         Case $aiNumDims[0] == 4   814                         Case $aiNumDims[0] == 4
783                                 ReDim $avRetArr[$aiDimSizes[0]][$aiDimSizes[1]][$aiDimSizes[2]][$aiDimSizes[3]]   815                                 ReDim $avRetArr[$aiDimSizes[0]][$aiDimSizes[1]][$aiDimSizes[2]][$aiDimSizes[3]]
784                                 For $iCounter1 = 0 To $aiDimSizes[0] - 1   816                                 For $iCounter1 = 0 To $aiDimSizes[0] - 1
785                                         For $iCounter2 = 0 To $aiDimSizes[1] - 1   817                                         For $iCounter2 = 0 To $aiDimSizes[1] - 1
786                                                 For $iCounter3 = 0 To $aiDimSizes[2] - 1   818                                                 For $iCounter3 = 0 To $aiDimSizes[2] - 1
787                                                         For $iCounter4 = 0 To $aiDimSizes[3] - 1   819                                                         For $iCounter4 = 0 To $aiDimSizes[3] - 1
788                                                                 $avRetArr[$iCounter1][$iCounter2][$iCounter3][$iCounter4] = _UnpackStrToVar($sVarStr) ; In case element holds another array (Recursive)   820                                                                 $avRetArr[$iCounter1][$iCounter2][$iCounter3][$iCounter4] = _UnpackStrToVar($sVarStr) ; In case element holds another array (Recursive)
789                                                         Next   821                                                         Next
790                                                 Next   822                                                 Next
791                                         Next   823                                         Next
792                                 Next   824                                 Next
793                 EndSelect   825                 EndSelect
794                 Return $avRetArr   826                 Return $avRetArr
795         EndIf   827         EndIf
796 EndFunc   ;==>_UnpackStrToVar   828 EndFunc   ;==>_UnpackStrToVar
797     829  
798 ;===============================================================================   830 ;===============================================================================
799 ;   831 ;
800 ; Function Name:    _PackVarToStr()   832 ; Function Name:    _PackVarToStr()
801 ; Description:      Packs a variable into a string form for sending to another   833 ; Description:      Packs a variable into a string form for sending to another
802 ;                                               script. Maintains array integrity up to 4 dimensions.   834 ;                                               script. Maintains array integrity up to 4 dimensions.
803 ;                                               Also supports nested arrays inside array elements.   835 ;                                               Also supports nested arrays inside array elements.
804 ; Parameter(s):     $vPackVar = Variable to be packed into a string.   836 ; Parameter(s):     $vPackVar = Variable to be packed into a string.
805 ;                                               NOTE: Variables of type Object or DllStructs are not yet   837 ;                                               NOTE: Variables of type Object or DllStructs are not yet
806 ;                                               supported.   838 ;                                               supported.
807 ; Return Value(s):  Returns packed string to be unpacked by _UnpackStrToVar()   839 ; Return Value(s):  Returns packed string to be unpacked by _UnpackStrToVar()
808 ; Author(s):        Ben Brightwell   840 ; Author(s):        Ben Brightwell
809 ;   841 ;
810 ;===============================================================================   842 ;===============================================================================
811 Func _PackVarToStr(ByRef $vPackVar)   843 Func _PackVarToStr(ByRef $vPackVar)
812         Local $iNumDims = UBound($vPackVar, 0) ; Number of dimensions of $vPackVar   844         Local $iNumDims = UBound($vPackVar, 0) ; Number of dimensions of $vPackVar
813         Local $sVarStr = "$[" & $iNumDims & "]$" ; Return string of packed variable   845         Local $sVarStr = "$[" & $iNumDims & "]$" ; Return string of packed variable
814         Local $iCounter1 = "" ; Nested Counter   846         Local $iCounter1 = "" ; Nested Counter
815         Local $iCounter2 = "" ; Nested Counter   847         Local $iCounter2 = "" ; Nested Counter
816         Local $iCounter3 = "" ; Nested Counter   848         Local $iCounter3 = "" ; Nested Counter
817         Local $iCounter4 = "" ; Nested Counter   849         Local $iCounter4 = "" ; Nested Counter
818         For $i = 1 To $iNumDims   850         For $i = 1 To $iNumDims
819                 $sVarStr &= "$[" & UBound($vPackVar, $i) & "]$"   851                 $sVarStr &= "$[" & UBound($vPackVar, $i) & "]$"
820         Next   852         Next
821         Select   853         Select
822                 Case $iNumDims == 0   854                 Case $iNumDims == 0
823                         If $vPackVar == "" Then   855                         If $vPackVar == "" Then
824                                 $sVarStr &= "<nil>"   856                                 $sVarStr &= "<nil>"
825                         Else   857                         Else
826                                 $sVarStr &= $vPackVar   858                                 $sVarStr &= $vPackVar
827                         EndIf   859                         EndIf
828                 Case $iNumDims == 1   860                 Case $iNumDims == 1
829                         For $iCounter1 = 0 To UBound($vPackVar, 1) - 1   861                         For $iCounter1 = 0 To UBound($vPackVar, 1) - 1
830                                 If $vPackVar[$iCounter1] == "" And UBound($vPackVar[$iCounter1], 0) == 0 Then   862                                 If $vPackVar[$iCounter1] == "" And UBound($vPackVar[$iCounter1], 0) == 0 Then
831                                         $sVarStr &= "$[0]$<nil>"   863                                         $sVarStr &= "$[0]$<nil>"
832                                 Else   864                                 Else
833                                         $sVarStr &= _PackVarToStr($vPackVar[$iCounter1])   865                                         $sVarStr &= _PackVarToStr($vPackVar[$iCounter1])
834                                 EndIf   866                                 EndIf
835                         Next   867                         Next
836                 Case $iNumDims == 2   868                 Case $iNumDims == 2
837                         For $iCounter1 = 0 To UBound($vPackVar, 1) - 1   869                         For $iCounter1 = 0 To UBound($vPackVar, 1) - 1
838                                 For $iCounter2 = 0 To UBound($vPackVar, 2) - 1   870                                 For $iCounter2 = 0 To UBound($vPackVar, 2) - 1
839                                         If $vPackVar[$iCounter1][$iCounter2] == "" And UBound($vPackVar[$iCounter1][$iCounter2], 0) == 0 Then   871                                         If $vPackVar[$iCounter1][$iCounter2] == "" And UBound($vPackVar[$iCounter1][$iCounter2], 0) == 0 Then
840                                                 $sVarStr &= "$[0]$<nil>"   872                                                 $sVarStr &= "$[0]$<nil>"
841                                         Else   873                                         Else
842                                                 $sVarStr &= _PackVarToStr($vPackVar[$iCounter1][$iCounter2])   874                                                 $sVarStr &= _PackVarToStr($vPackVar[$iCounter1][$iCounter2])
843                                         EndIf   875                                         EndIf
844                                 Next   876                                 Next
845                         Next   877                         Next
846                 Case $iNumDims == 3   878                 Case $iNumDims == 3
847                         For $iCounter1 = 0 To UBound($vPackVar, 1) - 1   879                         For $iCounter1 = 0 To UBound($vPackVar, 1) - 1
848                                 For $iCounter2 = 0 To UBound($vPackVar, 2) - 1   880                                 For $iCounter2 = 0 To UBound($vPackVar, 2) - 1
849                                         For $iCounter3 = 0 To UBound($vPackVar, 3) - 1   881                                         For $iCounter3 = 0 To UBound($vPackVar, 3) - 1
850                                                 If $vPackVar[$iCounter1][$iCounter2][$iCounter3] == "" And UBound($vPackVar[$iCounter1][$iCounter2][$iCounter3], 0) == 0 Then   882                                                 If $vPackVar[$iCounter1][$iCounter2][$iCounter3] == "" And UBound($vPackVar[$iCounter1][$iCounter2][$iCounter3], 0) == 0 Then
851                                                         $sVarStr &= "$[0]$<nil>"   883                                                         $sVarStr &= "$[0]$<nil>"
852                                                 Else   884                                                 Else
853                                                         $sVarStr &= _PackVarToStr($vPackVar[$iCounter1][$iCounter2][$iCounter3])   885                                                         $sVarStr &= _PackVarToStr($vPackVar[$iCounter1][$iCounter2][$iCounter3])
854                                                 EndIf   886                                                 EndIf
855                                         Next   887                                         Next
856                                 Next   888                                 Next
857                         Next   889                         Next
858                 Case $iNumDims == 4   890                 Case $iNumDims == 4
859                         For $iCounter1 = 0 To UBound($vPackVar, 1) - 1   891                         For $iCounter1 = 0 To UBound($vPackVar, 1) - 1
860                                 For $iCounter2 = 0 To UBound($vPackVar, 2) - 1   892                                 For $iCounter2 = 0 To UBound($vPackVar, 2) - 1
861                                         For $iCounter3 = 0 To UBound($vPackVar, 3) - 1   893                                         For $iCounter3 = 0 To UBound($vPackVar, 3) - 1
862                                                 For $iCounter4 = 0 To UBound($vPackVar, 4) - 1   894                                                 For $iCounter4 = 0 To UBound($vPackVar, 4) - 1
863                                                         If $vPackVar[$iCounter1][$iCounter2][$iCounter3][$iCounter4] == "" And UBound($vPackVar[$iCounter1][$iCounter2][$iCounter3][$iCounter4], 0) == 0 Then   895                                                         If $vPackVar[$iCounter1][$iCounter2][$iCounter3][$iCounter4] == "" And UBound($vPackVar[$iCounter1][$iCounter2][$iCounter3][$iCounter4], 0) == 0 Then
864                                                                 $sVarStr &= "$[0]$<nil>"   896                                                                 $sVarStr &= "$[0]$<nil>"
865                                                         Else   897                                                         Else
866                                                                 $sVarStr &= _PackVarToStr($vPackVar[$iCounter1][$iCounter2][$iCounter3][$iCounter4])   898                                                                 $sVarStr &= _PackVarToStr($vPackVar[$iCounter1][$iCounter2][$iCounter3][$iCounter4])
867                                                         EndIf   899                                                         EndIf
868                                                 Next   900                                                 Next
869                                         Next   901                                         Next
870                                 Next   902                                 Next
871                         Next   903                         Next
872         EndSelect   904         EndSelect
873         Return $sVarStr   905         Return $sVarStr
874 EndFunc   ;==>_PackVarToStr   906 EndFunc   ;==>_PackVarToStr
875     907  
876 ;===============================================================================   908 ;===============================================================================
877 ;   909 ;
    <> 910 ; Function Name:    _LineIsFunction()
      911 ; Description:      Classifies the given line as either the start/end of a function, or as a regular line.
      912 ;               Uses regular expressions to match every possible scenario.
      913 ; Parameter(s):     $vLine = The string to be classified.
      914 ; Return Value(s):  On Success - 1, this line is the start/end of a function. Sets @Error to:
      915 ;                                                       1 - Line is the start of a function
      916 ;                                                       2 - Line is the end of a function
      917 ;                       On Failure - 0, this line isn't a function.
      918 ; Author(s):        Chris H. (darkthorn)
      919 ;
      920 ;===============================================================================
      921 Func _LineIsFunction($vLine)
      922         ; Classify the type of line. First check if this line is an EndFunc.
      923         If StringRegExp($vLine, "^\s*(?i:EndFunc)", 2) Then
      924                 ; Success. Pattern Matched. This is the end of a function.
      925                 SetError(2) ; line is endfunc
      926                 Return 1 ; success
      927         Else
      928                 ; Failure. Pattern not matched. This is not the end of a function. So let's check if it's the start of a function.
      929                 If StringRegExp($vLine, "^\s*(?i:Func)\s+\S+\s*\(.*\)", 2) Then
      930                         ; Success. Pattern Matched. This is the start of a function.
      931                         SetError(1) ; line is func
      932                         Return 1 ; success
      933                 Else
      934                         ; Failure. Pattern not matched. Since this wasn't the start of a function either, treat it as a normal line.
      935                         SetError(0) ; line isn't function
      936                         Return 0 ; failure
      937                 EndIf
      938         EndIf
      939 EndFunc   ;==>_LineIsFunction
      940  
      941 ;===============================================================================
      942 ;
878 ; Function Name:    _RandomFileName() = 943 ; Function Name:    _RandomFileName()
879 ; Description:      Generates a random file name in the working directory so that   944 ; Description:      Generates a random file name in the working directory so that
880 ;                                               the a filename is not repeated for up to 10000 coroutine   945 ;                                               the a filename is not repeated for up to 10000 coroutine
881 ;                                               scripts per main script.   946 ;                                               scripts per main script.
882 ; Parameter(s):     none   947 ; Parameter(s):     none
883 ; Return Value(s):  FileGetShortName-converted string representing the full path   948 ; Return Value(s):  FileGetShortName-converted string representing the full path
884 ;                                               to the temporary file, including the .au3 extension   949 ;                                               to the temporary file, including the .au3 extension
885 ; Author(s):        Ben Brightwell   950 ; Author(s):        Ben Brightwell
886 ;   951 ;
887 ;===============================================================================   952 ;===============================================================================
888 Func _RandomFileName()   953 Func _RandomFileName()
889         $name = FileGetShortName($sWorkingDir) & "\" & StringTrimRight(@ScriptName, 4) & Random(0, 10000, 1) & ".au3"   954         $name = FileGetShortName($sWorkingDir) & "\" & StringTrimRight(@ScriptName, 4) & Random(0, 10000, 1) & ".au3"
890         $found = 0   955         $found = 0
891         For $i = 1 To $avCoThreads[0][0]   956         For $i = 1 To $avCoThreads[0][0]
892                 If $name == $avCoThreads[$i][0] Then   957                 If $name == $avCoThreads[$i][0] Then
893                         $found = 1   958                         $found = 1
894                 EndIf   959                 EndIf
895         Next   960         Next
896         While $found == 1   961         While $found == 1
897                 $found = 0   962                 $found = 0
898                 $name = FileGetShortName(@TempDir) & "\" & StringTrimRight(@ScriptName, 4) & Random(0, 10000, 1) & ".au3" <> 963                 $name = FileGetShortName($sWorkingDir) & "\" & StringTrimRight(@ScriptName, 4) & Random(0, 10000, 1) & ".au3"
899                 For $i = 1 To $avCoThreads[0][0] = 964                 For $i = 1 To $avCoThreads[0][0]
900                         If $name == $avCoThreads[$i][0] Then   965                         If $name == $avCoThreads[$i][0] Then
901                                 $found = 1   966                                 $found = 1
902                         EndIf   967                         EndIf
903                 Next   968                 Next
904         WEnd   969         WEnd
905         Return $name   970         Return $name
906 EndFunc   ;==>_RandomFileName   971 EndFunc   ;==>_RandomFileName