Primitive: returning a String
Stephen Travis Pope
stp at create.ucsb.edu
Tue Nov 30 23:55:50 UTC 1999
To return anything that's not fixed-size from a primitive, the easiest way is to pre-allocate it in Smalltalk and pass a pointer to the empty space into the primitive. There are examples of this in the sound synthesis code and in the Siren primitives, you basically say:
"pre-allocate some space"
str := String new: 64
"Glue code adds 4 to pointer to skip object header;
primitive returns the length of the string"
length := myRcvr somePrim: str.
"Copy the real result."
answer := str copyFrom: ! to: length
stp
Giovanni Giorgi wrote:
>
> Excuse me,
> I am working with named-primitive and I need to return a char* (= a
> String) to Smalltalk.
> The String is not of fixed or known size when calling the primitive.
> I have searched in the documentation but I cannot find how to solve this
> problem.
> I must return an array of integer and then conver it?
> What is the best way to do this?
--
stp
Stephen Travis Pope -- http://www.create.ucsb.edu/~stp
stp at expertcity.com -- stp9 at cornell.edu
More information about the Squeak-dev
mailing list
|