FFI external data
Bert Freudenberg
bert at impara.de
Sun Jan 11 13:21:16 UTC 2004
Am 11.01.2004 um 13:27 schrieb Alexander Lazarević:
> I'm calling a function in a shared library using FFI. One of the
> parameters
> needs to be a pointer to an array of floats. The code below works, but
> I
> think I missed to find something more handy to create/fill an array
> and get a
> pointer to it?
>
> | ctrlpoints addr data |
> ctrlpoints := { -4.0. -4.0. 0.0.
> -2.0. 4.0. 0.0.
> 2.0. -4.0. 0.0.
> 4.0. 4.0. 0.0 }.
> data := ByteArray new: ctrlpoints size * ExternalType float byteSize.
> 1 to: ctrlpoints size do: [:i|
> data
> floatAt: ((i-1)*ExternalType float byteSize + 1)
> put: (ctrlpoints at: i)].
> addr := ExternalData fromHandle: data type: ExternalType float.
> [...]
Looks as simple as it gets to me. You could try to use a FloatArray
directly with FFI, but IIRC the only array allowed for FFI callswas
ByteArray.
- Bert -
More information about the Squeak-dev
mailing list
|