[Cuis-dev] I need some advice with FFI

Nicola Mingotti nmingotti at gmail.com
Tue Nov 9 02:40:13 PST 2021



On 11/7/21 21:43, Juan Vuletich wrote:
> On 11/6/2021 3:01 PM, Nicola Mingotti via Cuis-dev wrote:
>> Hi guys,
>>
>> I was trying to develop my first FFI calls in Cuis today but
>> I am stuck, i hope some of you can give me some guidance.
>>
>> In the attached package there are implemented 2 foreign functions
>> TestClass (class) >> time         # working
>> TestClass (class) >> localtime    # broken
>>
>> ---- interactions ----------
>> TestClass time.                                      " ok "
>> TestClass localtime2: (TestClass time).              " broken "
>> -----------------------------
>>
>> The error i get is "can not use integer as pointer".
>>
>> Any ideas ?
>>
>> bye
>> Nicola
>>
>
> The C declaration says argument is a pointer, but you are passing an 
> integer. If you want a pointer, you need to set up a byte array with 
> the correct bytes, and pass that. The FFI will pass the pointer.
>
> There are several packages using FFI you can use as examples of 
> working code. I'm pretty sure there is a lot of documentation on 
> Squeak / Cuis FFI if you google a bit. As general advice, I'd say that 
> if you really need FFI, it is best to spend the time in reading about 
> it and playing with existing code. You'll have to spend at least 
> several hours on that. But if you can live in the the happy Smalltalk 
> land instead, it is of course easier.
>
> Also, depending on your needs, and the availability of time to spend 
> on this, you might prefer a VM plugin: It builds the C stack for you.
>
> HTH,
> -- 
> Juan Vuletich
> www.cuis-smalltalk.org
> https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev
> https://github.com/jvuletich
> https://www.linkedin.com/in/juan-vuletich-75611b3
> @JuanVuletich


Hi Juan,

thank you! I will try as soon as possible.

I tried to read all what i could find about Squeak and Cuis, also a 
little bit on Pharo.
With that was able to get started, but then, just a little problem like 
this could put me in the angle.
As next step I will try to dig more into existing Squeak/Cuis FFI examples.

I red about the VM plugin option, that seems more challenging, so i 
though i would be
better to investigate first the FFI. Sooner or later I will need to 
invest some time to understand
also the plugins.

Anyway, when will be able to master the technique i will make docs/video
so that it will be less difficult for future users.

Bye
Nicola














-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20211109/4de7cdad/attachment.htm>


More information about the Cuis-dev mailing list