[squeak-dev] Passing array of float from Squeak to C

Joshua Gargus schwa at fastmail.us
Fri Feb 20 20:44:23 UTC 2009


Yoshiki Ohshima wrote:
> At Fri, 20 Feb 2009 03:11:20 -0800 (PST),
> Ang Beepeng wrote:
>   
>> I'm facing problem to pass a float array over to C, to create a plugin. 
>>
>> Previously, I use variableWordSubclass: to create a class to store floats,
>> in an array. It works fine, as floats are stored as words.
>> Now that I need to have an instance variable, I use variableSubclass: to
>> store floats. It seems like floats are being stored as object in the array
>> this time. The VM crashes when I try to use to same method to access to the
>> float array.
>>     
>
>   To get a Float object and use the value in C, use #floatValueOf:.
> Look at the senders of the method for examples.
>   

I'm not sure that this is the right thing, since each Float represents a
double-precision floating point number, and the contents of FloatArray
are single-precision.

I would look at the primitives in CroquetPlugin, which you can find in
an OpenCroquet or Cobalt image.  For example, #primitiveTransformVector3
transforms a 3-element vector by a 4x4 matrix.  Matrix4x4 and Vector3
are both subclasses of FloatArray.

This might still not be answering your question directly (since you are
talking about adding inst-vars to a 'variable-word' class).  My
suggestion would be add another inst-var to hold a separate FloatArray
object which contains your floating point data.

Josh


> -- Yoshiki
>
>   

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20090220/74f12bcf/attachment.htm


More information about the Squeak-dev mailing list