Sign in to follow this  
Followers 0

Coroutine Multithreading Udf Library

39 posts in this topic

Posted (edited)

There were alot of requests for this type of library, and I found a thread that had a great idea for it (can be found here credit: ChrisL). So I decided to flesh it out, and I think it turned out well. It is in its beginning version, so forgive me if it's buggy.

Instead of putting lengthy instructions here, I've just included a couple of examples. I will be updating with full instructions later, and more examples. I've also included a helper script, FormatCoCreate.au3. When you run this script, it simply waits for the hotkey "Ctrl+Shift+C". What you do is highlight the function you want to turn into a thread, then press the hotkey, and it puts it into the correct format for you.

A couple of things to note: Variables can be passed in any form except variables of type Object, and DllStruct. Arrays consisting of up to 4 dimensions can be passed, as well as arrays nested in the elements of other arrays. The example scripts display this well. One other thing, the special delimiter, "$[" cannot be included anywhere in your threaded function. "$" and "[" can exist just fine, but not together.

I hope this is useful, let me know what you think and if you have any questions or find any bugs post them in this thread.

Version: 1.0.4 Date: 7/19/06

;===============================================================================
;
; File: Coroutine.au3
; Description: UDF Library used for coroutine multithreading
; Version: 1.0.4
; Date: 7/19/06
; Author: Ben Brightwell
; Credit: ChrisL for the base idea of deploying files as child scripts. Topic
;			can be found here:
;			http://www.autoitscript.com/forum/index.php?showtopic=22048
;
;===============================================================================

;===============================================================================
#cs
	Changelog:
	
	7/19/06 (1.0.4) - Fixed bug where using the substring "func" anywhere in a
						line of code caused it to be truncated. Now the only
						limitation is that the substrings "func" and "endfunc"
						cannot be found at the beginning of a line of code.
	
	4/25/06 (1.0.3) - Fixed bug with using variables that contained the word
						"return"
					- Fixed bug with StringLower()-ing every line of code
						in coroutine script, now case is untouched
					- Fixed the way _CoInclude() works so that included code
						is placed at the top of the file instead of the bottom
					- Fixed a bug with passing a simple string to the script
						an extra dimension indicator was present
	
	4/15/06 (1.0.2) - Truncated version number (Builds are irrelevant)
					- Added support for exp[b][/b]ressions in the return statement
						of a coroutine
						
	3/23/06 (1.0.1.0) - Modified _CoCreate() to handle a function with no 
							parameters
					  - Added "Core Function List" and "Miscellaneous Function 
							List"
					  - Added this Changelog
					  - Changed _CoAddHelper() to _CoInclude()
					  - Fixed a bug in _CoInclude() where the last line of code
							was not being read into the script file
#ce
;===============================================================================

;===============================================================================
#cs
	Core Function List:
	
	_CoCreate()
	Create a coroutine script which can be instanced by _CoStart()
	
	_CoInclude()
	Include helper/wrapper functions to compliment the main body created by
		_CoCreate()
	
	_CoStart()
	Create an instance of a threaded function as created by _CoCreate()
	
	_CoYield()
	NOTE: Only to be used in coroutine scripts
		Pauses the coroutine and yields a value to the main script, returns
		any value passed by the corresponding call to _CoResume()
	
	_CoStatus()
	Returns the status of a coroutine
	
	_CoSend()
	Sends a variable into a child script
	
	_CoResume()
	Unpauses a coroutine, optionally sends a value back to the yielded
		coroutine
	
	_CoGetReturn()
	Retrieves a variable returned by a coroutine
	
	_CoKill()
	Closes a coroutine
	
	_CoCleanup()
	Closes all running coroutines, and deletes their respective temporary script
		files
	
	_CoChangeWorkingDir
	Changes the working directory for storing the temporary script files.
		NOTE: Default is @TempDir
	
	Miscellaneous Function List:
		NOTE: These functions are meant to be called internally by Coroutine.au3
	
	_PackVarToStr()
	Packs a variable into a string for transmission between scripts.
	
	_UnpackStrToVar()
	Unpacks a packed variable-string into its original structure, whether it be
		a string or array.
	
	_RandomFileName()
	Generates a random unused filename for use with _CoCreate()
#ce
;===============================================================================

Edit: v1.0.4 was released(7/19/06)

Edit: uploaded wrong Coroutine.zip earlier, correct version is uploaded at 2:44am CST

Edit: v1.0.3 was released(4/25/06) (Downloads: 123)

Edit: v1.0.2 was released(4/15/06) (Downloads: 24)

Edit: Truncated post was fixed/ v1.0.1.0 was released(3/23/06) (Downloads: 39)

FormatCoCreate.au3

Coroutine.au3

Edited by neogia

Share this post


Link to post
Share on other sites



Posted

Very interesting...

Multi-threading is what I am looking for...

OffTopic: note that there is a post limit and your source was cut off

#)

Share this post


Link to post
Share on other sites

Posted

Very interesting...

Multi-threading is what I am looking for...

OffTopic: note that there is a post limit and your source was cut off

#)

Well, I'm glad it might be of use to you. Let me know if you need some help with it.

OffTopic: Thanks for that, I did think my post was rather short, I guess I'll just change it to contain the function names.

Share this post


Link to post
Share on other sites

Posted

Released Version: 1.0.1.0

Share this post


Link to post
Share on other sites

Posted

Released Version: 1.0.2

Added support for returning expressions from a coroutine. (Didn't realize AutoIt handled that automatically, I thought I would have to create my own lexer.)

Share this post


Link to post
Share on other sites

Posted (edited)

Released Version: 1.0.3

4/25/06 (1.0.3) - Fixed bug with using variable names that contained the word "return"

- Fixed bug with StringLower()-ing every line of code in coroutine script, now case is untouched

- Fixed the way _CoInclude() works so that included code is placed at the top of the file instead of the bottom

- Fixed a bug with passing a simple string to the script an extra dimension indicator was present

Edited by neogia

Share this post


Link to post
Share on other sites

Posted

This is the first time i have actually looked at this in detail and it works perfectly! Well done

Share this post


Link to post
Share on other sites

Posted

Awesome, I was looking for something like this.

Share this post


Link to post
Share on other sites

Posted

This is the first time i have actually looked at this in detail and it works perfectly! Well done

Awesome, I was looking for something like this.

Thanks for the compliments. I'm actually currently working on a large project for work that solves a major problem of mine. I was previously using TCP/IP to communicate between my scripts, but they had to be separately compiled, and reloaded to the server... blah blah blah. One of the major problems was that you had to disable any firewalls to allow the TCP/IP to function. Solved with Std** and Console** communication between scripts!

Share this post


Link to post
Share on other sites

Posted

Ben, a couple of questions.

1. Can a coroutine access global variables in the parent thread or do you have to use _CoSend()?

2. If the parent process is killed forcefully, ie. via Task Manager, is the coroutine process killed as well?

Share this post


Link to post
Share on other sites

Posted

1. Can a coroutine access global variables in the parent thread or do you have to use _CoSend()?

Good question. No, global variables are only global in either the main thread or in the child thread. You either have to a)use _CoSend() to dynamically send a value to the child thread or b)supply the variable in the argument(s) in the call to _CoStart(function, "$arg1,$arg2,$argN"). NOTE: when using _CoSend(), the child script has to "receive" or be "looking" for the variable to be sent.

2. If the parent process is killed forcefully, ie. via Task Manager, is the coroutine process killed as well?

The short answer no. I can affect this change rather simply though, and now that you mention it, I think I will. It will be in the next release.

Thanks for all your input, let me know if you need any further help.

Share this post


Link to post
Share on other sites

Posted (edited)

a question :

$_StartMuliThread = _CoCreate( 	'Func Count($return)|'& _
								'#NoTrayIcon|'& _
								'	Return msgbox( 0, "BLUB"&$return , "number : " & $return  )|'& _
								'EndFunc')
Dim $MBoX[5],$_Run[5]
For $i = 1 To 4
	$MBoX[$i]= _CoStart($_StartMuliThread, '$_Run['&$i&']')
Next
Local $c_Count = 0
While 1
	$c_Count += 1
	
		If _CoStatus($MBoX[$c_Count]) == "returned" Then
			$MBoX[$c_Count]= _CoStart($_StartMuliThread, '$_Run['&$c_Count&']')
			WinMove( "BLUB$_Run["&$c_Count&"]" , "" , Random( 0 , @DesktopWidth-100 ) , Random( 0, @DesktopHeight-100) )
			;_CoKill($MBoX[$c_Count])
		EndIf
	
	If $c_Count == 4 Then $c_Count = 0
WEnd

this wont work as i want it, i want that he creates endless messageboxes, and moves them random but it wont work :< pls help^^

Edited by Busti

Share this post


Link to post
Share on other sites

Posted (edited)

#include <Coroutine.au3>

$_StartMuliThread = _CoCreate(  'Func Count($return)|'& _
                                '#NoTrayIcon|'& _
                                '   Return msgbox( 0, "BLUB"&$return , "number : " & $return  )|'& _
                                'EndFunc')
Dim $MBoX[5],$_Run[5]
For $i = 1 To 4
    $MBoX[$i]= _CoStart($_StartMuliThread, '$_Run['&$i&']')
Next
Local $c_Count = 0
While 1
    $c_Count += 1
    
        If _CoStatus($MBoX[$c_Count]) == "returned" Then
            $MBoX[$c_Count]= _CoStart($_StartMuliThread, '$_Run['&$c_Count&']')
			WinWait("BLUB$_Run["&$c_Count&"]")
            WinMove( "BLUB$_Run["&$c_Count&"]" , "" , Random( 0 , @DesktopWidth-100 ) , Random( 0, @DesktopHeight-100) )
            ;_CoKill($MBoX[$c_Count])
        EndIf
    
    If $c_Count == 4 Then $c_Count = 0
WEnd
oÝ÷ Ù.­h§2Þq©eÁ«+zÛ«)àÓbrj{"µØm~)ݶ°whÁ*ë-i×^u¥¢f¢µ©ÝÜ(®Kwq©è¢¨"ëaȬ~Þvç¶*'jZn®,zÊâ[)ä[(§ÊjYB¡+Z®Ü"¶ýÓ~º}ýjjtߨýßÙz§)ݶ­
­j»n¶)bÍ뽩ZÑ/jWmzö¥¹«^jºÚÉé^éí±*2¢çh¦É-+ºw-Ú+ro'hx,¢g­)à)¶¬jëh×6
For $i = 1 To 4
    $temp = $_Run[$i]
    $MBoX[$i]= _CoStart($_StartMuliThread, '$temp')
Next

Edit: BTW, your _CoCreate() function looks much cleaner when it is edited like that. I might change FormatCoCreate() to stylize the function like that, thanks for the involuntary contribution. :)

Edited by neogia

Share this post


Link to post
Share on other sites

Posted

thank for help^^ i will test it and edit this post^^

no problem, i coult read it like this better :D

Share this post


Link to post
Share on other sites

Posted

New FormatCoCreate helper function released.

Changes

----------

- Now, the code you convert with the FormatCoCreate function keeps most of its readability and looks much nicer (thanks Busti).

Share this post


Link to post
Share on other sites

Posted (edited)

Update 7/20/06: Get v1.1.0 with a bunch of important patches.

Wow, congratulations on the most impressive script I've ever seen! I ran into trouble though. The function I am exporting (using the FormatCoCreate Helper) contains a While $RunFunction = 1 ... WEnd statement, and when exported only the WEnd remains (the While-line is removed).

I have several While-statements in the function, and the rest of them seem intact. Still, there is something wrong with your _CoCreate function as it seems to skip certain lines of the script. When I tried to change While $RunFunction = 1, to While 1, it was exported correctly, but then the EndFunc line was omitted instead. Weird indeed.

On a side note, CoInclude seems to work right, as any function included that way seems to be intact). Is it some kind of "error checking" on your part in the CoCreate function, that excludes certain lines? I'll be happy to show you the script over MSN / in PM so we can solve this bug, but I am not going to post it here since it's private.

Edited by darkthorn

Share this post


Link to post
Share on other sites

Posted (edited)

Update 7/20/06: Get v1.1.0 with a bunch of important patches.

Uhm... Further checking shows that setting "While $RunFunction = 1" to just "While 1" gets it included in the tempscript file. However, I got an error that there was a Func without matching EndFunc... so I checked the file, and noticed that the output file doesn't include full function definitions for YOUR functions! That's when I noticed, to my surprise, that the script just abruptly ended in the middle of the _UnpackStrToVar function. No EndFunc or anything, it ended right in the middle of the code!The file was 2KB. This was with "While 1" in my code.

When I tried it with "While $RunFunction = 1" I got the omitted "While" error again, but the output file contained more of your code, although still truncated and missing vital code. This file was now 5KB instead.

Due to the increased file size it doesn't seem like it could be AutoIt truncating the file due to size limitations, but rather that something in my imported function is throwing off your code completely, since your short, simple functions work fine (the included examples).

Edited by darkthorn

Share this post


Link to post
Share on other sites

Posted

I'm sending you a PM with the code that causes your script to break. Please don't post it on the forums, though.

I'm working on a fix for this right now, but if you'll look at line 183 of Coroutine.au3, you'll see the problem lies in the naming of your variable "$RunFunction" and it's truncating the line because it finds the substring "func". If you rename the variable to something that doesn't include "func", it should be a fine workaround until I release the next version. (ex: $RunFnction)

Thanks for your praise and for the very detailed bug submission. I'll have the fix out soon enough.

Share this post


Link to post
Share on other sites

Posted

Released Version: 1.0.4

7/19/06 (1.0.4) - Fixed bug where using the substring "func" anywhere in a

line of code caused it to be truncated. Now the only

limitation is that the substrings "func" and "endfunc"

cannot be found at the beginning of a line of code.

Share this post


Link to post
Share on other sites

Posted (edited)

Update 7/20/06: Get v1.1.0 with a bunch of important patches.

Released Version: 1.0.4

7/19/06 (1.0.4) - Fixed bug where using the substring "func" anywhere in a

line of code caused it to be truncated. Now the only

limitation is that the substrings "func" and "endfunc"

cannot be found at the beginning of a line of code.

Thanks for a very fast solution to the problem! However, it's not a fix as it breaks the code completely! Did you even check it? Your new code ONLY includes the Func() and EndFunc() of the exported function, and the entire body of code is left out! The resulting temp-file is empty of all the instructions of the exported function!

This is because you've changed the line from "If the line ISN'T the start/end of a function, then write it to the tempfile", to "If the line IS the start/end of a function, then write it to the tempfile". I've corrected your code, below. And as a token of gratitude I've spent some time creating a function for you that correctly classifies lines.

The function is called _LineIsFunction($line), and returns 0 = regular line or 1 = line is func/endfunc. It also sets @error to 1 = start of function (func xxx(args)), or 2 = end of function (endfunc), so that you can work with that value aswell if you want to. How did I do it? It uses regular expressions to 100% accurately classify *any* line. :D

Here is a sample file with very bad code quality (full of errors), to check the accuracy of my function:

Func f1($arg1,$arg2) ; start of function )<
Func f2() ; !!! func f3 blah blah
	   Func f1($arg1,$arg2) ; start of function
	       Func 	f2() ; !!! func f3()?? blah blah
RegularLineofCodeWithFunc()
; Another Line of Code with Func f1()
Function Start?
While $RunFunction = 1 ;this is the line that caused trouble with your script
fUnc f3($RunFunction)
FUNC f4($RunFunction = 1)
How about this line? Is it a Func funcname($argument)? Or is it correctly seen as a regular line?
EndFunc
EndFunc ;==>end of f1 ;D
    EndFunc ; this one has whitespace at the start
	EndFUNC ; this one has a tab and mixed case
		EndfUnc ; this one has two tabs and mixed case
	   Endfunc ;==> End of function
; Endfunc ; End of function with invalid code preceding it
$str = "EndFunc" ; This isn't the end of a function, but your code thinks it is, since you're only
; checking if Func/EndFunc is in the string, and not the actual validity of the string.
Func ; this is an invalid function
Func f5 ; this is another invalid function
Func  f6	 (	) ; this is a valid function full of spaces and tabs
	Func f7 ( ; no matching end bracketoÝ÷ Ø	ݶ¬Ëaz·¬º[Z~׫ºÈ§lºw-í¡ÉZ²ÈÉæX§y«­¢+ÙlÅum	¥¹¹¥¹½Õ¹Ñ¥½¹tÕ¹Ä ÀÌØíÉÄ°ÀÌØíÉȤìÍÑÉнչѥ½¸¤±Ðì)lÉum	¥¹¹¥¹½Õ¹Ñ¥½¹tÕ¹È ¤ìÌÌìÌÌìÌÌìչ̱ ± )lÍum	¥¹¹¥¹½Õ¹Ñ¥½¹t$Õ¹Ä ÀÌØíÉÄ°ÀÌØíÉȤìÍÑÉнչѥ½¸)lÑum	¥¹¹¥¹½Õ¹Ñ¥½¹t$Õ¹%È ¤ìÌÌìÌÌìÌÌìÕ¹Ì ¤üü± ± )lÕumIÕ±È1¥¹tIÕ±É1¥¹½
½]¥Ñ¡Õ¹ ¤)lÙumIÕ±È1¥¹t칽ѡÈ1¥¹½
½Ý¥Ñ Õ¹Ä ¤)lÝumIÕ±È1¥¹tչѥ½¸MÑÉÐü)láumIÕ±È1¥¹t]¡¥±ÀÌØíIչչѥ½¸ôÄíÑ¡¥Ì¥ÌÑ¡±¥¹Ñ¡ÐÕÍÑÉ½Õ±Ý¥Ñ å½ÕÈÍÉ¥ÁÐ)låum	¥¹¹¥¹½Õ¹Ñ¥½¹tU¹Ì ÀÌØíIչչѥ½¸¤)lÄÁum	¥¹¹¥¹½Õ¹Ñ¥½¹tU9Ð ÀÌØíIչչѥ½¸ôĤ)lÄÅumIÕ±È1¥¹t!½Ü½ÕÐÑ¡¥Ì±¥¹ü%Ì¥ÐÕ¹Õ¹¹µ ÀÌØíÉÕµ¹Ð¤ü=ȥ̥нÉÉѱä͸ÌÉձȱ¥¹ü)lÄÉum¹½Õ¹Ñ¥½¹t¹Õ¹)lÄÍum¹½Õ¹Ñ¥½¹t¹Õ¹ìôôÐí¹½Äí)lÄÑum¹½Õ¹Ñ¥½¹t¹Õ¹ìÑ¡¥Ì½¹¡ÌÝ¡¥ÑÍÁÐÑ¡ÍÑÉÐ)lÄÕum¹½Õ¹Ñ¥½¹t%¹U9ìÑ¡¥Ì½¹¡Ìѹµ¥áÍ)lÄÙum¹½Õ¹Ñ¥½¹t$%¹U¹ìÑ¡¥Ì½¹¡ÌÑݼÑ̹µ¥áÍ)lÄÝum¹½Õ¹Ñ¥½¹t$¹Õ¹ìôôÐ칽չѥ½¸)lÄáumIÕ±È1¥¹tì¹Õ¹ì¹½Õ¹Ñ¥½¸Ý¥Ñ ¥¹Ù±¥½ÁÉ¥¹¥Ð)lÄåumIÕ±È1¥¹tÀÌØíÍÑÈôÅÕ½Ðí¹Õ¹ÅÕ½ÐììQ¡¥Ì¥Í¸ÌäíÐÑ¡¹½Õ¹Ñ¥½¸°ÕÐå½ÕȽѡ¥¹­Ì¥Ð¥Ì°Í¥¹å½ÔÌäíɽ¹±ä)lÈÁumIÕ±È1¥¹tì¡­¥¹¥Õ¹½¹Õ¹¥Ì¥¸Ñ¡ÍÑÉ¥¹°¹¹½ÐÑ¡ÑÕ°Ù±¥¥Ñä½Ñ¡ÍÑÉ¥¹¸)lÈÅumIÕ±È1¥¹tÕ¹ìÑ¡¥Ì¥Ì¸¥¹Ù±¥Õ¹Ñ¥½¸)lÈÉumIÕ±È1¥¹tÕ¹ÔìÑ¡¥Ì¥Ì¹½Ñ¡È¥¹Ù±¥Õ¹Ñ¥½¸)lÈÍum	¥¹¹¥¹½Õ¹Ñ¥½¹tÕ¹Ø$ $¤ìÑ¡¥Ì¥ÌÙ±¥Õ¹Ñ¥½¸Õ±°½ÍÁ̹ÑÌ)lÈÑumIÕ±È1¥¹t%Õ¹Ü ì¹¼µÑ¡¥¹¹É­ÐoÝ÷ Ù.®«¨µø±yÚ®¢×(uê'¶¨¶«©Ý«©àyÛajÛhªê-!ûazX§x­ë-j»zwh}§îËb¢p
Ø^ÂÝÆ­¶¬µªí¡ûazX§{
+uú.Ö­r«iË^¯ußÛazwh¶¢YhÂ)àªê-jëh×6ElseIf StringInStr($asFuncLines[$i], "func") == 1 Or StringInStr($asFuncLines[$i], "endfunc") == 1 ThenoÝ÷ Ù8b²+0«[­æ¤±ëÞ¯+ax²+g£
''±¦í²Ø^~éÜýéÝ~éÜ)Þ±©Ýmæèw*¶ºw-Óë(ëb¢x¬¶¬zlw°[§qû§rبÚ/z¸ÊØZ¶Ø^)Þ!#wõ;azËZ®ßÞÚiû§rب©Ýû(¥êߢ¹­êk¢«Â¸­zƧwZ¶z-N­Çhæ¬~e£ºÚ"µÍ[ÙRYÝÓ[RÑ[Ý[Û	ÌÍØÑ[Ó[ÖÉÌÍÚWJH[

That's all there is to it! The function will classify each line, and perform the "Then"-actions on everything but the function start/end (func/endfunc). This is just like your previous StringInStr but with 100% accuracy! :wacko:

Best Regards,

Chris H.

_LineIsFunction.zip

Edited by darkthorn

Share this post


Link to post
Share on other sites

Posted (edited)

Update 7/20/06: Get v1.1.0 with a bunch of important patches.

I should clarify that the original bug is NOT fixed. The function I wrote fixed another bug that had to do with the word "func/endfunc" being matched at invalid places, such as While $RunFunction = 1 being seen as a "Func".

Putting that aside, there is STILL a bug in your code! What we fixed wasn't the real problem. Try the script I sent you again, using my patched Coroutine.au3 1.0.5 in the post below. Then look at the (still truncated) output of YOUR functions. :/

It seems that the bug might have to do with the length of the code I am exporting to _CoStart, or perhaps the length of the final output file. It could even be a bug of AutoIt's file write functions.

Best Regards,

Chris H.

Edited by darkthorn

Share this post


Link to post
Share on other sites

Posted (edited)

Update 7/20/06: Get v1.1.0 with a bunch of important patches.

I've changed every occurance of the StringInStr() Func/EndFunc scans to use _LineIsFunction() instead. So that part of your code is now bug free! :wacko: However, the output is still truncated, and in some parts jumbled aswell. It seems *VERY* unlikely that the bug is in AutoIt's FileWriteLine function, as I've run loads of tests, and even managed to get your script to write non-truncated data by changing the function I was sending to CoCreate.

The output is truncated in most cases, and it always changes with every single character difference in _CoCreate, if you add a character, it changes the output. If you remove a character, it changes the output. The truncate-bug only appears to happen beyond a certain length of the _CoCreate()'d function, but could also depend on WHAT is in the function. Certain words or characters might be causing your code to bug out? No matter what happens though, the full function is copied to the output. It's always the FileWriteLine's for your functions that fail. And I don't understand how, since they're just in one massive blob, one after the other.

As you know your code best, you should take a look at why my example is causing your _CoCreate write actions to end prematurely. I haven't been able to figure it out. Perhaps it has something to do with AutoIt anyway. A rare bug caused by the output of some character, perhaps? :D

Although, I've already verified that FileWriteLine can be called thousands of times in a loop, and create files of seemingly endless size. I've also verified that there is no limit on the number of lines in the output, so that's not why it breaks either. I have no idea why your code breaks during output. In one case, I got 137 lines in the output. Then I changed the function I was sending to _CoCreate a bit, and got 187 lines. It's completely random and seems like it's something in your code, not AutoIt's fault. Unless there is some rare bug in the FileWrite* function...

Either way, until that's solved at least I've attached my bug-fixed version of your Coroutine.au3 UDF, version 1.0.5. If you have a file comparison program you can easily see my changes. If not, I'll point them out to you if you want. Now we just have to figure out why the FileWriteLine actions end prematurely, and why they do it at completely different locations in your functions, depending on the length of the text you feed to _CoCreate.

Best Regards,

Chris H.

Edit: I looked at the return-values of all the FileWriteLine calls, and every single one of them succeeds (returns 1), so that's strange. Not only do they return 1 (successful write), but I noticed that every call gets carried out, even past the point where the output is truncated. That means that your code is NOT prematurely ending the output, and that the bug is in AUTOIT! Phew. That took a lot of investigating to find out. I am going to file a bug report.

Edited by darkthorn

Share this post


Link to post
Share on other sites

Posted (edited)

Update 7/20/06: Get v1.1.0 with a bunch of important patches.

Released Coroutine v1.0.6, ignore previous references to v1.0.5. Use the link at the bottom of the previous post download the archive. It contains the original 1.0.3 source, my patched version (1.0.6), and a Patches.htm file that shows *everything* that has been changed. There is really *no* reason to use the old, bugged version (for those that are reading this and wondering).

Edited by darkthorn

Share this post


Link to post
Share on other sites

Posted

As it turns out, the bug *was* in your code after all, and not in AutoIt. I've fixed it and applied all my other patches, and bumped the version number to 1.1.0.

I've decided to keep the previous posts for historical purposes, since some people might enjoy reading them. However, if you are new here just download the zip file attached to this post to get my latest patched version. I've also included a file called "Patches-1.1.0.html", which shows you in detail what was modified. Check it out.

And without further ado, here's the changelog for v1.1.0:

[ Patched by Darkthorn ]
7/20/06 (1.1.0) * Wrote _LineIsFunction() to correctly identify the start/end of functions.
				- Replaced the previous, buggy StringInStr() matches with the above function.
					This means that your functions will no longer get incorrectly cut off
					when they contain the words "Func" or "EndFunc" inside the function
					definition.
				* Fixed a bug in _CoChangeWorkingDir(), it didn't work before as the variable 
					wasn't being used anywhere. The following changes were made:
				- Changed _CoChangeWorkingDir() from $workingDir = $sDir to $sWorkingDir = $sDir.
				- Changed _RandomFileName() from FileGetShortName(@TempDir) to FileGetShortName($sWorkingDir)
				* The documentation for _CoInclude() says that it returns 1 on success, but it
					didn't return anything on success, this has been fixed so that it returns 1.
				* Added documentation for _LineIsFunction(), and added it to the "Miscellaneous Function List".
				* Fixed an extremely severe bug where the very important FileClose() command was
					omitted by the _CoInclude() function which appends functions to the output
					script. This in turn makes AutoIt go crazy and causes it to truncate/jumble
					the file contents whenever you try to access the file again. Not only that,
					but any subsequent attempts to reopen the file for writing (such as another
					call to _CoInclude()), would cause AutoIt to hang since the file would still be
					locked from before. This fixed two bugs:
				- Output files are no longer truncated/jumbled when you use _CoInclude() to append functions.
				- _CoInclude() no longer hangs AutoIt on subsequent calls, since the file is now free to reopen.
[ Patched by Darkthorn ]

Enjoy!

Chris H.

Coroutine_1.1.0.zip

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0




  • Recently Browsing   0 members

    No registered users viewing this page.