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: 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)
Attached Files
Edited by neogia, 20 July 2006 - 03:02 AM.






