<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<br>
<br>
<div class="moz-cite-prefix">On 11/7/21 21:43, Juan Vuletich wrote:<br>
</div>
<blockquote type="cite" cite="mid:61883A61.8050109@jvuletich.org">
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
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" moz-do-not-send="true">www.cuis-smalltalk.org</a>
<a class="moz-txt-link-freetext" href="https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev" moz-do-not-send="true">https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev</a>
<a class="moz-txt-link-freetext" href="https://github.com/jvuletich" moz-do-not-send="true">https://github.com/jvuletich</a>
<a class="moz-txt-link-freetext" href="https://www.linkedin.com/in/juan-vuletich-75611b3" moz-do-not-send="true">https://www.linkedin.com/in/juan-vuletich-75611b3</a>
@JuanVuletich</pre>
</blockquote>
<br>
<br>
Hi Juan,<br>
<br>
thank you! I will try as soon as possible.<br>
<br>
I tried to read all what i could find about Squeak and Cuis, also a
little bit on Pharo. <br>
With that was able to get started, but then, just a little problem
like this could put me in the angle.<br>
As next step I will try to dig more into existing Squeak/Cuis FFI
examples. <br>
<br>
I red about the VM plugin option, that seems more challenging, so i
though i would be <br>
better to investigate first the FFI. Sooner or later I will need to
invest some time to understand <br>
also the plugins.<br>
<br>
Anyway, when will be able to master the technique i will make
docs/video<br>
so that it will be less difficult for future users.<br>
<br>
Bye<br>
Nicola<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</body>
</html>