<div dir="ltr">Ron, thanks so much for the links! I think they got me a bit farther, but I don't have a working example yet. I know this is a somewhat complex topic, but I'm surprised I haven't been able to find a basic working example. I'd love to see something like a C function that takes two numbers and returns their sum. And then see how to call that function from Cuis Smalltalk.<div><br></div><div>Here's something I tried to calculate the absolute value of a number using the abs function provided by C and running in macOS where the C library is provided in libSystem.dylib.</div><div><br></div><div>Define the following class:</div><div><br></div><div><font face="monospace">ExternalLibrary subclass: #FFIDemo<br>    instanceVariableNames: ''<br>    classVariableNames: ''<br>    poolDictionaries: ''<br>    category: 'Volkmann'</font><br></div><div><br></div><div>Define the following class method:</div><div><br></div><div><font face="monospace">moduleName</font><br><font face="monospace">    ^ 'libSystem.dylib'<br></font></div><div><br></div><div>Define the following instance methods:</div><div><br></div><div><font face="monospace">ffiAbs: anInteger<br>    "<calltype: returnType 'functionName' (parameter types list) module: 'libraryName'>"<br>    <cdecl: long 'abs' (long) module: 'libSystem.dylib'><br>    ^self externalCallFailed</font><br></div><div><br></div><div><font face="monospace">callIt: aNumber<br>    | meth |<br></font><span style="font-family:monospace">   <span> </span></span><font face="monospace">meth := ExternalLibraryFunction<br>   <span> </span>   <span> </span>name: 'ffiAbs'</font></div><div><span style="font-family:monospace">   <span> </span></span><span style="font-family:monospace">   </span><span style="font-family:monospace"> </span><span style="font-family:monospace">module: FFIDemo moduleName</span></div><div><span style="font-family:monospace">   <span> </span></span><span style="font-family:monospace">   </span><span style="font-family:monospace"> </span><span style="font-family:monospace">callType: 0</span><br></div><div><span style="font-family:monospace">   <span> </span></span><span style="font-family:monospace">   </span><span style="font-family:monospace"> </span><span style="font-family:monospace">returnType: ExternalType int32</span></div><div><span style="font-family:monospace">   <span> </span></span><span style="font-family:monospace">   </span><span style="font-family:monospace"> </span><span style="font-family:monospace">argumentTypes: #(ExternalType int32).</span></div><div><span style="font-family:monospace">   <span> ^</span></span><font face="monospace"> meth invokeWith: aNumber.<br></font></div><div><font face="monospace"><br></font></div><div>Test it like this:</div><div><br></div><div><font face="monospace">demo := FFIDemo new.<br>(demo callIt: -2) print. "expecting 2"</font><br></div><div><br></div><div>This gives "Error: Unable to find function address".</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Sep 29, 2024 at 5:00 PM Ron Teitelbaum <<a href="mailto:ron@3dicc.com" target="_blank">ron@3dicc.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-size:small">This looks helpful too</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small"><a href="http://forum.world.st/About-Squeak-s-FFI-package-ported-to-Cuis-td4663852.html" target="_blank">http://forum.world.st/About-Squeak-s-FFI-package-ported-to-Cuis-td4663852.html</a><br></div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">and this:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small"><a href="https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev/blob/master/Packages/System/Tests-FFI.pck.st" target="_blank">https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev/blob/master/Packages/System/Tests-FFI.pck.st</a><br></div><div class="gmail_default" style="font-size:small"><br></div><div><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><p style="font-size:12.8px"><span style="color:rgb(31,73,125)">All the best,</span></p><p><b><font color="#4f81bd" face="Corbel, sans-serif"><span style="font-size:14pt">Ron Teitelbaum</span><span style="font-size:18.6667px"><br></span></font></b><i style="font-size:12.8px"><span style="font-size:9pt;color:rgb(31,73,125)">Chief Executive Officer<br></span></i><font color="#1f497d"><span style="font-size:9pt"><b>3D Immersive Collaboration Corp</b></span><span style="font-weight:bold;font-size:12px"><br></span></font><span style="font-size:8pt"><a href="mailto:ron@3dicc.com" style="color:rgb(17,85,204);font-size:8pt" target="_blank">ron@3dicc.com</a></span><span style="font-size:8pt;color:blue"><br></span><span style="font-size:8pt;color:blue"><a href="http://www.3dicc.com/" style="font-size:8pt;color:rgb(17,85,204)" target="_blank">www.3dicc.com</a></span></p><p><a href="https://www.facebook.com/3DICC" target="_blank"><img src="https://www.3dicc.com/wp-content/uploads/2015/06/f-ogo_RGB_HEX-58-e1554385586279.png" alt=""></a> <a href="https://twitter.com/RonTeitelbaum" target="_blank"><img src="https://www.3dicc.com/wp-content/uploads/2015/06/Twitter_Logo_WhiteOnBlue-150x150-e1554385627982.png" alt=""></a> <a href="https://www.linkedin.com/in/ronteitelbaum" target="_blank"><img src="https://www.3dicc.com/wp-content/uploads/2015/06/In-2C-54px-R-e1554386073825.png"></a><br></p></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Sep 29, 2024 at 5:54 PM Ron Teitelbaum <<a href="mailto:ron@3dicc.com" target="_blank">ron@3dicc.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-size:small">This may help too:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small"><a href="https://wiki.squeak.org/squeak/1414" target="_blank">https://wiki.squeak.org/squeak/1414</a><br></div><div><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><p style="font-size:12.8px"><span style="color:rgb(31,73,125)">All the best,</span></p><p><b><font color="#4f81bd" face="Corbel, sans-serif"><span style="font-size:14pt">Ron Teitelbaum</span><span style="font-size:18.6667px"><br></span></font></b><i style="font-size:12.8px"><span style="font-size:9pt;color:rgb(31,73,125)">Chief Executive Officer<br></span></i><font color="#1f497d"><span style="font-size:9pt"><b>3D Immersive Collaboration Corp</b></span><span style="font-weight:bold;font-size:12px"><br></span></font><span style="font-size:8pt"><a href="mailto:ron@3dicc.com" style="color:rgb(17,85,204);font-size:8pt" target="_blank">ron@3dicc.com</a></span><span style="font-size:8pt;color:blue"><br></span><span style="font-size:8pt;color:blue"><a href="http://www.3dicc.com/" style="font-size:8pt;color:rgb(17,85,204)" target="_blank">www.3dicc.com</a></span></p><p><a href="https://www.facebook.com/3DICC" target="_blank"><img src="https://www.3dicc.com/wp-content/uploads/2015/06/f-ogo_RGB_HEX-58-e1554385586279.png" alt=""></a> <a href="https://twitter.com/RonTeitelbaum" target="_blank"><img src="https://www.3dicc.com/wp-content/uploads/2015/06/Twitter_Logo_WhiteOnBlue-150x150-e1554385627982.png" alt=""></a> <a href="https://www.linkedin.com/in/ronteitelbaum" target="_blank"><img src="https://www.3dicc.com/wp-content/uploads/2015/06/In-2C-54px-R-e1554386073825.png"></a><br></p></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Sep 29, 2024 at 5:50 PM Ron Teitelbaum <<a href="mailto:ron@3dicc.com" target="_blank">ron@3dicc.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-size:small">Maybe this:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small"><<a href="https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev/blob/master/Documentation/Technical/AQuickOrientationToFFIFromSmalltalk.md" target="_blank">https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev/blob/master/Documentation/Technical/AQuickOrientationToFFIFromSmalltalk.md</a>><br></div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">and</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small"><<a href="https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev/blob/master/Documentation/Technical/FFIorVMPluginsWhatToUse.md" target="_blank">https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev/blob/master/Documentation/Technical/FFIorVMPluginsWhatToUse.md</a>> <br></div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small"><br></div><div><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><p style="font-size:12.8px"><span style="color:rgb(31,73,125)">All the best,</span></p><p><b><font color="#4f81bd" face="Corbel, sans-serif"><span style="font-size:14pt">Ron Teitelbaum</span><span style="font-size:18.6667px"><br></span></font></b><i style="font-size:12.8px"><span style="font-size:9pt;color:rgb(31,73,125)">Chief Executive Officer<br></span></i><font color="#1f497d"><span style="font-size:9pt"><b>3D Immersive Collaboration Corp</b></span><span style="font-weight:bold;font-size:12px"><br></span></font><span style="font-size:8pt"><a href="mailto:ron@3dicc.com" style="color:rgb(17,85,204);font-size:8pt" target="_blank">ron@3dicc.com</a></span><span style="font-size:8pt;color:blue"><br></span><span style="font-size:8pt;color:blue"><a href="http://www.3dicc.com/" style="font-size:8pt;color:rgb(17,85,204)" target="_blank">www.3dicc.com</a></span></p><p><a href="https://www.facebook.com/3DICC" target="_blank"><img src="https://www.3dicc.com/wp-content/uploads/2015/06/f-ogo_RGB_HEX-58-e1554385586279.png" alt=""></a> <a href="https://twitter.com/RonTeitelbaum" target="_blank"><img src="https://www.3dicc.com/wp-content/uploads/2015/06/Twitter_Logo_WhiteOnBlue-150x150-e1554385627982.png" alt=""></a> <a href="https://www.linkedin.com/in/ronteitelbaum" target="_blank"><img src="https://www.3dicc.com/wp-content/uploads/2015/06/In-2C-54px-R-e1554386073825.png"></a><br></p></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Sep 29, 2024 at 5:47 PM Mark Volkmann via Cuis-dev <<a href="mailto:cuis-dev@lists.cuis.st" target="_blank">cuis-dev@lists.cuis.st</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">Which documentation are you referring to? I don't see a separate repository related to FFI at <a href="https://github.com/Cuis-Smalltalk" target="_blank">https://github.com/Cuis-Smalltalk</a>.<div>I do see this, but no documentation in it: <a href="https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev/blob/master/Packages/System/FFI.pck.st" target="_blank">https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev/blob/master/Packages/System/FFI.pck.st</a></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Sep 29, 2024 at 2:15 PM Andres Valloud via Cuis-dev <<a href="mailto:cuis-dev@lists.cuis.st" target="_blank">cuis-dev@lists.cuis.st</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Before you start, make sure you go through the FFI doc at github.<br>
<br>
On 9/29/24 6:58 AM, Mark Volkmann via Cuis-dev wrote:<br>
> Can someone point me to an example of using FFI to call a C function in <br>
> Cuis Smalltalk?<br>
> I've looked at the code in the FFI package, but I don't see any examples <br>
> or tests.<br>
> I've also spent time searching the web for examples and came up empty.<br>
> <br>
> -- <br>
> R. Mark Volkmann<br>
> Object Computing, Inc.<br>
> <br>
<br>
-- <br>
Cuis-dev mailing list<br>
<a href="mailto:Cuis-dev@lists.cuis.st" target="_blank">Cuis-dev@lists.cuis.st</a><br>
<a href="https://lists.cuis.st/mailman/listinfo/cuis-dev" rel="noreferrer" target="_blank">https://lists.cuis.st/mailman/listinfo/cuis-dev</a><br>
</blockquote></div><br clear="all"><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><font face="arial, helvetica, sans-serif">R. Mark Volkmann</font></div><div><span style="font-size:12.8px"><font face="arial, helvetica, sans-serif">Object Computing, Inc.</font></span></div></div></div></div></div></div></div></div>
-- <br>
Cuis-dev mailing list<br>
<a href="mailto:Cuis-dev@lists.cuis.st" target="_blank">Cuis-dev@lists.cuis.st</a><br>
<a href="https://lists.cuis.st/mailman/listinfo/cuis-dev" rel="noreferrer" target="_blank">https://lists.cuis.st/mailman/listinfo/cuis-dev</a><br>
</blockquote></div>
</blockquote></div>
</blockquote></div>
</blockquote></div><br clear="all"><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><font face="arial, helvetica, sans-serif">R. Mark Volkmann</font></div><div><span style="font-size:12.8px"><font face="arial, helvetica, sans-serif">Object Computing, Inc.</font></span></div></div></div></div></div></div></div></div>