Hello All,
Pharo newbie here. I'm playing around with uFFI and I'm having trouble figuring out how to provide a buffer to C. It looks like maybe ByteArray would be the type, but it's not working. Would some one be so kind as to show me an example with the C function gethostname?
Thanks,
Gerry
hi,
it should be ByteArray.
if you explain more in detail your problem, I can try to help you better :)
Esteban
On Nov 28 2021, at 9:20 am, Gerry Weaver gerryw@compvia.com wrote:
Hello All,
Pharo newbie here. I'm playing around with uFFI and I'm having trouble figuring out how to provide a buffer to C. It looks like maybe ByteArray would be the type, but it's not working. Would some one be so kind as to show me an example with the C function gethostname?
Thanks,
Gerry
Hi,
I'm just trying to work out how to do it. Please find my latest attempt below. The docs aren't much help with this.
FFITutorial>>getHostName
| nameBuffer |
nameBuffer := ByteArray new: 256.
self ffiCall: #( int gethostname(ByteArray *nameBuffer, int 256) ) library: 'libc.so.6'.
^nameBuffer asString
Thanks,
Gerry
From: Esteban Lorenzano estebanlm@netc.eu
Sent: Sunday, November 28, 2021 3:09 AM
To: Any question about pharo is welcome pharo-users@lists.pharo.org
Cc: pharo-users@lists.pharo.org pharo-users@lists.pharo.org
Subject: [Pharo-users] Re: uFFI provide buffer to C
hi,
it should be ByteArray.
if you explain more in detail your problem, I can try to help you better :)
Esteban
On Nov 28 2021, at 9:20 am, Gerry Weaver gerryw@compvia.com wrote:
Hello All,
Pharo newbie here. I'm playing around with uFFI and I'm having trouble figuring out how to provide a buffer to C. It looks like maybe ByteArray would be the type, but it's not working. Would some one be so kind as to show me an example with the C function gethostname?
Thanks,
Gerry