[squeak-dev] Re: FFI: Pass a Smalltalk String as part of a Structure

Udo Schneider Udo.Schneider at homeaddress.de
Sat Oct 24 08:04:15 UTC 2009


Andreas,

thanks for the info. Works perfectly.

CU,

Udo


Andreas Raab schrieb:
> Hi -
> 
> You need to create an instance of ExternalData and pass this in. For 
> example:
> 
> setPath: aString
>   "Set the path in this structure from a Squeak string"
>   | xHandle xData |
>   xHandle:= ExternalAddress allocate: aString size+1.
>   1 to: aString size do:[:i| xHandle byteAt: i-1 put: (aString byteAt: i)].
>   xHandle byteAt: aString size put: 0.
>   xData := ExternalData fromHandle: xHandle type: ExternalType char 
> asPointerType.
>   ^self path: xData
> 
> Hope this helps,
>   - Andreas
> 
> 
> Udo Schneider wrote:
>> Hi,
>>
>> I defined an FFI Structure using
>>
>> MyStruc class>>fields
>>     ^#( #path 'char*) )
>>
>> After calling define Fields I see that the wrappers are generated. 
>> However I not quite sure how to pass a Smalltalk String in.
>>
>> Something like
>>
>> MyStruc new path: '/home/udos/'
>>
>> does not work.
>>
>> Any pointers?
>>
>> CU,
>>
>> Udo
>>
>>
>>
> 
> 
> 




More information about the Squeak-dev mailing list