<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
On 11/6/2021 3:01 PM, Nicola Mingotti via Cuis-dev wrote:
<blockquote
cite="mid:66440e94-1015-d445-2e74-19a2ed47180c@gmail.com"
type="cite">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<font size="4"><font face="monospace">Hi guys,<br>
<br>
I was trying to develop my first FFI calls in Cuis today but<br>
I am stuck, i hope some of you can give me some guidance. <br>
<br>
In the attached package there are implemented 2 foreign
functions<br>
TestClass (class) >> time # working <br>
TestClass (class) >> localtime # broken<br>
</font></font><font size="4"><font face="monospace"><font
size="4"><font face="monospace"><br>
---- interactions ----------<br>
TestClass time. " ok
" <br>
TestClass localtime2: (TestClass time). "
broken "<br>
-----------------------------<br>
<br>
</font></font>The error i get is "can not use integer as
pointer".<br>
<br>
Any ideas ?<br>
<br>
bye<br>
Nicola<br>
<br>
</font></font> </blockquote>
<br>
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.<br>
<br>
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.<br>
<br>
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.<br>
<br>
HTH,<br>
<pre class="moz-signature" cols="72">--
Juan Vuletich
<a class="moz-txt-link-abbreviated" href="http://www.cuis-smalltalk.org">www.cuis-smalltalk.org</a>
<a class="moz-txt-link-freetext" href="https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev">https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev</a>
<a class="moz-txt-link-freetext" href="https://github.com/jvuletich">https://github.com/jvuletich</a>
<a class="moz-txt-link-freetext" href="https://www.linkedin.com/in/juan-vuletich-75611b3">https://www.linkedin.com/in/juan-vuletich-75611b3</a>
@JuanVuletich</pre>
</body>
</html>