README.md
The file to generate given testlib.nim would be Testlib.st
. This is the class
old "chunk format" in which the content is separated by !
marks, in a rather
oddish way, but anyway.
Let's go through it:
'From Nim on 18 February 2015 at 11:15:50 pm'!
Above first chunk is just a String literal with a timestamp, that chunk can be omitted.
ExternalLibrary subclass: #Testlib
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Nim'!
Then follows the class declaration. Obviously we need to make sure it says
Testlib
and the category will equal the package in Squeak that this class
will end up in. For now, let's hard code it to Nim
.
Then we can see that there is a "whitespace only" chunk, since the next part
starts with !
.
!Testlib class methodsFor: 'primitives' stamp: 'gk 11/2/2014 13:05'!
This chunk says here follows methods for "Testlib class" (=class side) in method category "primitives" (we can hardcode it to that).
ffiAdd: a with: b
"self ffiAdd: 13 with: 29"
<cdecl: long 'add' (long long) module: 'testlib'>
^self externalCallFailed!
ffiConcat: a with: b
"self ffiConcat: 'a' with: 'b' "
<cdecl: char* 'concat' (char* char*) module: 'testlib'>
^self externalCallFailed!
ffiFoo
"self ffiFoo"
<cdecl: char* 'foo' () module: 'testlib'>
^self externalCallFailed!
ffiHello
"self ffiHello"
"long is int in Nim"
<cdecl: long 'hello' () module: 'testlib'>
^self externalCallFailed!
ffiLength: x
"self ffiLen: 'hey' "
<cdecl: long 'length' (char*) module: 'testlib'>
^self externalCallFailed! !
The above is one chunk per method, then an extra empty chunk on the last line to finish the method category "primitives".
!Testlib class methodsFor: 'accessing' stamp: 'gk 2/18/2015 23:13'!
moduleName
^'testlib'! !
Finally a chunk declaring another method category, and then a single method with the name of the shared library to load.