Commit 01dbfa89235fd57298c801d94599da6d0c7de936
1 parent
032258fd
Test code with comments and cleanups
Showing
7 changed files
with
56 additions
and
18 deletions
src/.gitignore
0 → 100644
1 | +nimcache |
tests/.gitignore
0 → 100644
tests/Test.nim
0 → 100644
tests/Test.nim.cfg
0 → 100644
tests/Test1.nim
0 → 100644
1 | +# This import adds macros to generate FFI Smalltalk code | ||
2 | +import squeaknim | ||
3 | + | ||
4 | +# Just compile with "nim c Test1.nim", copy resulting lib and Test1.st | ||
5 | +# to a Squeak directory, file in Test1.st and then it should be fine | ||
6 | +# to call foo, see class side of Test1 | ||
7 | + | ||
8 | +type | ||
9 | + MyFloat = float32 | ||
10 | + Vector3* = object | ||
11 | + x*, y*, z*: MyFloat | ||
12 | + | ||
13 | +# This sets the name of the FFI module (and class) and a Smalltalk prefix | ||
14 | +# to avoid collisions for generated classes, like Vector3 which turns into | ||
15 | +# URVector3 in Smalltalk | ||
16 | +setModulename "Test1", "UR" | ||
17 | + | ||
18 | +# Generate the Smalltalk class URVector3 representing Vector3 | ||
19 | +wrapObject(Vector3) | ||
20 | + | ||
21 | +# Generate declarations for Smalltalk code | ||
22 | +writeExternalLibrary() | ||
23 | + | ||
24 | +# Here follows Nim procedures that will be callable via FFI | ||
25 | +# Note that exportSt pragma to export. | ||
26 | + | ||
27 | +proc foo*(a, b: Vector3, c: int): cstring {.exportSt: "bar".} = | ||
28 | + # Just a silly test proc | ||
29 | + result = "x plus y plus c " & $(a.x + b.y + c.float) | ||
30 | + | ||
31 | +# Write the Smalltalk code to file | ||
32 | +writeSmallTalkCode("Test1.st") |
tests/Test1.nim.cfg
0 → 100644
tests/test1.nim deleted
1 | - | ||
2 | -import squeaknim | ||
3 | - | ||
4 | -type | ||
5 | - MyFloat = float32 | ||
6 | - Vector3 = object | ||
7 | - x, y, z: MyFloat | ||
8 | - | ||
9 | -setModulename "urhonimo", "UR" | ||
10 | - | ||
11 | -wrapObject(Vector3) | ||
12 | - | ||
13 | -writeExternalLibrary() | ||
14 | - | ||
15 | -proc foo(a, b: Vector3): cstring {.exportSt: "bar".} = | ||
16 | - result = "some string here" | ||
17 | - | ||
18 | -writeSmallTalkCode("test1.st") |