Building a library with functions with callbacks

Alex Tweedly alex at tweedly.net
Mon Jul 11 20:13:42 EDT 2005


Dar Scott wrote:

>
> On Jul 11, 2005, at 4:08 PM, Alex Tweedly wrote:
>
>> I want to build a library where some of the functions in it have 
>> parameters which are callbacks;
>>   agtMyFunction pData, pCallBackMessage
>
> You can pass 'the long id of me' as an extra parameter.

Ick.

> If that is empty, you can use 'the target'.  That will work 95% of the 
> time and is annoying the other 5%.  I think libURL uses that.

Ugh.

> You can create a "callback value" that you pass, that includes the 
> handler name and the object long id.
>
Oh if only we had macros :-)   (I'm joking ...but they would actually 
help in this case)

> Often, you want to call a handler of a specific name and you need only 
> pass the long id of the object.

I guess I'll use a wrapper around executionContexts.

> You can vote for the enhancement in bugzilla to add a function to get 
> this:  #1954.  Hmmm.  My search came up with 1243 and 2839, too.  
> Dups, maybe.
>
I prefer to use the "original" (i.e. lowest numbered) out of a set of 
dups - but 1243 has already been rejected as "not a bug", so I'll leave 
it alone, and instead I added my votes to #1954. I wish there was a way 
to get the votes on 1243 and 2839 moved over to 1954, so there was a 
more accurate count.

> Your can write your own function to get the object of the caller using 
> the executionContexts property.  The property is not supported, so I'd 
> encourage the wrapper incase it changes.
>
will do - thanks.

Dave Cragg wrote:

> The target will probably work if (using your card script example) the  
> target object calls the card script handler using the normal message  
> hierachy. So if the callback is sent from the library to the target,  
> and there is no handler in the target, it will pass to the card.

Hmmm - but there could be a handler in the target object with the same 
name - and much mayhem would ensue.

(Thanks Mark and Trevor also). I dislike having an extra parameter, so 
I'm going to go with executionContexts inside a wrapper - maybe I'll 
call it revCallerID and hope I get lucky in the future :-)

Actually, I'd really like to have the syntax of "socket" functions 
extended to user-defined functions
    callMyHandler value with message <callback>
I really like Transcipt's neo-English style - just wish it could be used 
for user-defined handlers like it can for built in ones.

-- 
Alex Tweedly       http://www.tweedly.net



-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.323 / Virus Database: 267.8.11/45 - Release Date: 09/07/2005




More information about the use-livecode mailing list