How does a command find out who called it?
Andre Garzia
andre at andregarzia.com
Wed Feb 1 18:44:48 EST 2012
The way I implement such callbacks is by using a script local
variable. In my script local variable, I have a handler that registers
a callback. This handler will keep track of the target that registered
the callback. When I need to send a callback later, I pick the
original target from that variable.
I've edited the original code below:
The stack script says:
on openCard
start using "minihttp.livecode"
end openCard
The card script says:
on someHandler ...
httpGet "http://blah.com","myCallback"
end someHandler
on myCallback ...
-- do someting brilliant with the data we've requested
end myCallback
Finally, I have a stack called "minihttp.livecode".
The stack script looks like:
local sCallbackA
on httpGet pUrl,pCallback
-- save the callback
put the target into sCallbackA["target"]
put pCallback into sCallbackA["message"]
-- kick off asynchronous httpGet operations with a local callback
mysocketOpen "address","mySocketCallback"
-- now return
end httpGet
on mySocketCallback args
-- Yay! Finally have the data. Hand it back
send sCallbackA["message"] to sCallbackA["target"] in 0 milliseconds
end mySocketCallback
More information about the use-livecode
mailing list