> I am wondering how to use callbacks with c-library calls.
I wanted to do the same thing, for GTK. I made a couple of defining
words, that make functions that can be used as callbacks, but I
haved figured out how to pass data yet. But I can use some of the
GTK widgets, even the file requester. This is the idea....
----
\ for callbacks from gtk to forth
create (cb_stack) 1024 allot \ a tmp stack, who knows where forth's is now
: :cb ( <callback_word> )
header reveal
$55 c, \ push %ebp
$56 c, \ push %esi
$bd c, up@ , \ mov %ebp,user_pointer
$be c, (cb_stack) 1016 + , \ mov %esi,#(cb_stack)+1016 , use a tmp
stack
]
;
: ;cb \ to end call back word
compile [
$5e c, \ pop %esi
$5d c, \ pop %ebp
$c3 c, \ ret
; immediate
\ example
\ variable flag
\ :cb textcb
\ 1 flag !
\ ;cb
----
Then, in the set up code, you do something like
0" okay" gtk_button_new_with_label dbut !
dbut @ 0" clicked" ['] textcb 0 gtk_signal_connect
It's a total hack, of course. I put opcodes in because I don't know
how to make the compile work in a defining word.
I've tested this lightly, but haven't done anything serious with it yet.
If you knew where the caller's stack pointer was, seems like you
could provide a pointer to the parameters. Also, I'm not sure how to
return a value.
Don
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]