How to refer to a 'calling' function
Dar Scott
dsc at swcp.com
Thu May 13 13:24:18 EDT 2004
On Thursday, May 13, 2004, at 11:03 AM, John Rule wrote:
> I would like to return a value to a function after waiting for a
> response
> from a socket that already has a handler for reading from the socket.
> When
> the data comes in, I would like to return this value to the 'original'
> function that started everything. What is happening is the reference
> to the
> original function is no longer valid when I want to 'return' the
> value. I
> looked at the 'target' function, but that is not working...is there
> any way
> to refernece functions for directly returning values (some kind of
> internal
> reference)?
The model I use is that used by socket commands that use messages. The
result is sent back to the calling object using either a specified
message handler name or a fixed one.
You need to set up for the callback at the initial call. The caller
can pass the name of the function, if it is not fixed. It can also
pass the long id of the caller, like this:
getCurrentLoad stationNumber, the long id of me -- in this example
the handler name is fixed
I like to combine the name of the function and the long id into a
single value and pass just that. Like this:
put makeCallback("processTemp", the long id of me) into cb
getMotorTemperature pumpNumber, cb
There is an unsupported function exectionContexts() you can use, but I
don't think its use is recommended. It would be nice if there was a
function to get the caller.
I believe libURL uses a compromise that should work most of the time.
I think at the initial request call, it save staves the target; the
caller is likely to be in the path of the target.
If you want some sort of blocking, there are methods, but I have not
been happy with them in complex systems.
Dar Scott
More information about the use-livecode
mailing list