01dbfa89
Göran Krampe
Test code with co...
|
1
2
3
4
5
|
# This import adds macros to generate FFI Smalltalk code
import squeaknim
# Just compile with "nim c Test1.nim", copy resulting lib and Test1.st
# to a Squeak directory, file in Test1.st and then it should be fine
|
e95712ca
Andreas Rumpf
bugfixes and clea...
|
6
|
# to call foo, see class side of Test1
|
01dbfa89
Göran Krampe
Test code with co...
|
7
8
9
10
11
12
13
14
15
16
17
18
|
type
MyFloat = float32
Vector3* = object
x*, y*, z*: MyFloat
# This sets the name of the FFI module (and class) and a Smalltalk prefix
# to avoid collisions for generated classes, like Vector3 which turns into
# URVector3 in Smalltalk
setModulename "Test1", "UR"
# Generate the Smalltalk class URVector3 representing Vector3
|
71252402
Göran Krampe
Added SUnit test ...
|
19
|
wrapObject(Vector3, true)
|
01dbfa89
Göran Krampe
Test code with co...
|
20
|
|
e95712ca
Andreas Rumpf
bugfixes and clea...
|
21
|
# Generate declarations for Smalltalk code
|
01dbfa89
Göran Krampe
Test code with co...
|
22
23
24
25
26
|
writeExternalLibrary()
# Here follows Nim procedures that will be callable via FFI
# Note that exportSt pragma to export.
|
e95712ca
Andreas Rumpf
bugfixes and clea...
|
27
|
proc foo*(a, b: Vector3, c: int): cstring {.exportSt.} =
|
01dbfa89
Göran Krampe
Test code with co...
|
28
29
30
31
|
# Just a silly test proc
result = "x plus y plus c " & $(a.x + b.y + c.float)
# Write the Smalltalk code to file
|
e454a5e9
Göran Krampe
SmallTalk changed...
|
32
|
writeSmalltalkCode("Test1.st")
|