Easy way of sending a message

Vincent Coetzee vincent.coetzee at ebucks.com
Fri Feb 6 18:32:53 UTC 2004


Hi Guys

In essence I have created a VM that has an Objective C bridge into  
Cocoa (I looked at using Marcels, but while his is more elegant than  
mine I have had mixed success getting his Squeak project to build under  
Xcode. My goal is to be able to boot a VM that only uses Cocoa for UI  
rather than the current Morphic / MVC type mechanisms. I have about 95%  
of this working very nicely at this stage. However in order to use  
various portions of Cocoa one needs to set delegates for the various  
Cocoa objects to invoke operations on. All of this does take place in a  
different thread(s) anyway. I have created Delegate stubs that store  
externalizable references to the Squeak objects and would like these  
invocations to get converted into Squeak invocations. I have thought  
about using semaphores, I just thought that a callback type mechanism  
would be more elegant. But if as you suggest this is an unnecessary  
complication, I shall return my attention to the mechanism.

Thanks for the help.

Vincent

On Feb 06, 2004, at 20:05, Andreas Raab wrote:

>> I seem to have gotten myself into a pickle
>
> Yes, you have.
>
>> and I was hoping someone had
>> some bright suggestions for me. I need to send an arbitrary message to
>> an arbitrary object in Squeak from within C. I have spent a lot of  
>> time
>> reading the Interpreter and ObjectMemory code, but can not find a  
>> quick
>> primitive to do this. Is there some mechanism for looking up method
>> objects that does not have side effects on the VM state. Specifically  
>> I
>> need the mechanism to implement call backs from C, and can not find a
>> simple function for doing this lookup without side effects.
>
> If you are really into implementing callbacks, check out the stuff I  
> wrote
> in:
>
> http://lists.squeakfoundation.org/pipermail/squeak-dev/2004-February/ 
> 073231.html
>
> However, I would advise you to very carefully think about whether you  
> really
> *have* to have callbacks. In most cases you should be able to "get by"  
> with
> a varying number of workarounds. Depending on your concrete constraints
> (which I have no idea about - it may be helpful to explain in more  
> detail
> what you are working on) you might be able to use one of the following
> alternatives:
>
> - if the message sent from C does not have to complete synchronously,  
> you
> can simply signal a semaphore. This is precisely what (for example) the
> async I/O, network and similar primitives do. Then, a Squeak process  
> can
> pick up the request (such as the message name) via a primitive and run  
> the
> remaining stuff from within Squeak.
>
> - if the above is not an option because you need the message to be  
> processed
> synchronously to return a result, consider running "all of your C  
> code" in a
> separate thread. This would allow you to utilize the same mechanism as  
> the
> above, except that now the C thread could block until the result has  
> been
> computed and is returned from Squeak (via an appropriate primitive  
> which
> releases the C thread).
>
> In any case, you will have a hard time if you try to do all of this  
> stuff
> directly from C and I would advise strongly against the idea of  
> "sending a
> message from C". Try to combine both areas and have Squeak do what it  
> does
> best - dealing with messages and sending them.
>
> Cheers,
>   - Andreas
>
>




More information about the Squeak-dev mailing list