[Cuis-dev] I need some advice with FFI

Juan Vuletich juan at jvuletich.org
Sun Nov 7 12:43:13 PST 2021

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.


Juan Vuletich

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20211107/878d6449/attachment.htm>

More information about the Cuis-dev mailing list