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?
Thank you very very much!
-- // Giovanni Giorgi mailto:giovanni.giorgi@mlab.disco.unimib.it
// Master Thesis at http://mars.sal.disco.unimi.it/~giorgi // Student (& exTutor) at Depart. of Computer Science of Milan, Italy. -------------------------------------------------------------------------
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?
squeak-dev@lists.squeakfoundation.org