[squeak-dev] Re: [Pharo-project] Alien FFI

Vassili Bykov smalltalkbigot at gmail.com
Mon Nov 24 23:23:56 UTC 2008


On Mon, Nov 24, 2008 at 1:29 PM, Igor Stasenko <siguctua at gmail.com> wrote:
>
> how about
> 'foo' asAlien: #CString
> 'foo' asAlien: #UnicodeString
>
> and generic form:
> anyObject asAlien: #someAlienType
>
> the key point is to let object itself decide how to convert to
> appropriate alien object, because there is no other who knows better
> how to perform a conversion.

Yes, there is. This is why I said C and Smalltalk worlds are too
different. There are cases when you only know what at the call site
what representation you want. For example, an array of strings can be
represented as a null-terminated array of pointers or a double
null-terminated buffer where one null-terminated string follows
another.

> A conversion requires a collaboration between object to be converted
> and destination type.

Exactly, but often there is no Smalltalk equivalent of the destination
type. Because of that a more tractable code results when the
representation is manufactured somewhere close to the foreign call
site, relying on public API of the Smalltalk object, rather than by
magical methods sprinkled throughout the system.

> There is no way to make ' Alien newCString: arbirtatyObject ' working
> without putting/using special behavior into arbirtatyObject.

But I'm not advocating for the argument of newCString: to be an
arbitrary object.

Cheers,

--Vassili



More information about the Squeak-dev mailing list