The Do-It Yourself Guide to Squeak Primitives


4. Write the Smalltalk Prim-Calling Method

This is the high-level method that will call the direct primitive method. It is generally part of one of your "application" classes. In class PrimMIDIPort, instance side, "primitives" protocol, I have the following,

get: packet
"Read the data from the receiver into the argument (a MIDIPacket)."

| len |
"reads packet header and data, answers amt. of data read"
len := self primReadPacket: packet data: packet data.
len >= 0
ifFalse: [...What to do on bad return value rather than failure...].
^len

In Siren, this is called by a read loop that's triggered by a semaphore coming up from the VM, but that's outside of the scope here.

The actual primitive methods generally have names that start with "prim" as shown above.