![]() |
||
| Home | SwiftForth Archive | SwiftX Archive | |

Ditto. But, where is the next installment? Just kidding.
-----Original Message-----
From: marc_hawley [mailto:marc_hawley_at_msn.com]
Sent: Tuesday, November 13, 2001 2:56 PM
To: sftalk_at_forth.com
Subject: [sftalk] Re: Tutorial -- Callbacks, part 1
Good stuff! Thanks.
----- Original Message -----
From: "Rick VanNorman" <rick_at_forth.com>
To: <sftalk_at_forth.com>
Sent: Monday, November 12, 2001 11:57 PM
Subject: [sftalk] Tutorial -- Callbacks, part 1
>
> I'm going to be developing (in my copious free time!) an application
> for my personal use. In the interests of furthering the knowledge
> base, I intend to do it online, developing the code (actually, releasing
> it) in an order that I hope will enlighten and edify you, my faithful
> readers.
>
> I would appreciate feedback, questions, suggestions, etc. If my comments
> aren't clear, please say so. If the code has an error, if there are
> typos, inconsistencies, poor usage, anything, please let me know. My
> goal is to have this become a tutorial, and the clearer it is the better
> it will be.
>
> Please be civil and kind and post in public so others may follow along.
>
> The first installment of this application is to discuss the callback
> mechanism.
>
> ----------------------------------------------------------------------
> Callbacks, part 1
> ----------------------------------------------------------------------
>
> What are callbacks?
>
> Callbacks are the Win32 equivalent of an interrupt service. They allow
> Windows to asychronously execute parts of your program at its discretion.
>
> How do you define a callback?
>
> Assuming you have a word FOO that does an appropriate action for the
> callback, you may define it as:
>
> ' FOO 4 CB: FOO-CALLBACK
>
> But be careful -- each callback has its own needs and requirements
> which must be addressed by FOO. For instance, the "4" indicates
> that the callback uses four arguments.
>
> How do callbacks work?
>
> Now we get to the hard bit. Take a look at the definition of CB:
>
> : CB: ( xt n -- ) \ Usage: xt n CB: <name>
> CREATE
> RUNCB ,CALL
> [+ASM] CELLS # RET NOP [-ASM]
> ( xt) , ;
>
> This builds a named SwiftForth data item that, when executed, simply
> returns the address of the data. If you disassembled FOO-CALLBACK, you
> would see something like:
>
> FOO-CALLBACK:
> CALL DOCREATE
> FOO-CALLBACK-DATA:
> CALL RUNCB
> RET #16
> NOP
> DW XT-OF-FOO
>
> So when your code references FOO-CALLBACK, all that happens is that the
> address of FOO-CALLBACK-DATA is pushed onto the Forth data stack. This
> address is normally passed to Windows as a pointer to a callback
> function via an API such as EnumWindows() . Notice that the address
> passed here is an address of executable code, but not at this point
> Forth-specific code. Just a normal call to the routine RUNCB. And that's
> where the Forth-magic is.
>
> And that's where I'll leave off for tonight. More coming soon.
>
> Rick
>
>
> ----------------------------------------------------------------------
> sftalk_at_forth.com The SwiftForth programming discussion email list
> To unsubscribe, send subject "unsubscribe sftalk" to listar_at_forth.com
> For help with listar commands, send subject "help" to listar_at_forth.com
> Archives are located at http://www.forth.com/sftalk -- check them out!
> Search the archives! Visit http://www.forth.com/search for details.
>
----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe sftalk" to listar_at_forth.com
For help with listar commands, send subject "help" to listar_at_forth.com
Archives are located at http://www.forth.com/sftalk -- check them out!
Search the archives! Visit http://www.forth.com/search for details.
----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe sftalk" to listar_at_forth.com
For help with listar commands, send subject "help" to listar_at_forth.com
Archives are located at http://www.forth.com/sftalk -- check them out!
Search the archives! Visit http://www.forth.com/search for details.
Received on Wed Nov 14 2001 - 07:56:08 PST
This archive was generated by hypermail 2.2.0 : Sat Nov 22 2008 - 03:04:19 PST