[squeak-dev] Pass C string into Squeak

vagy vagy at freemail.gr
Wed Jan 6 11:09:43 UTC 2010


On Wed, 06 Jan 2010 08:42:10 +0200, Ang BeePeng <beepeng86 at yahoo.com>  
wrote:

>
> Hi.
>
> I wish I can get some help on this. I want to pass a C string into  
> Squeak. I
> saw "primitiveStringAtPut", "primitiveStringReplace" etc.. I'm thinking  
> of
> call a primitive in smalltalk, pass an empty String object onto stack,  
> then
> have interpreter/primitive to fill in the String. Any better way to  
> achieve
> that? What precaution should I take, to prevent C string from causing  
> error
> once it is in Squeak?
>
> Thanks.
>
> Ang Beepeng

Hi, you can also use FFI for that. If your C routine is exported in a DLL
(or .so, etc.) and returns a C null terminated string you are almost there.
Then you just need to call this function and FFI will take care of  
returning
a String for you. Just note that you will get back a copy of your C string.

Cheers
  - Vagelis



More information about the Squeak-dev mailing list