Commit 01dbfa89235fd57298c801d94599da6d0c7de936

Authored by Göran Krampe
1 parent 032258fd

Test code with comments and cleanups

src/.gitignore 0 → 100644
  1 +nimcache
tests/.gitignore 0 → 100644
  1 +libTest1.so
  2 +Test
  3 +Test1.st
  4 +nimcache
tests/Test.nim 0 → 100644
  1 +import Test1
  2 +
  3 +# Just to try out the Nim Test1.foo proc from Nim
  4 +# nim c -r Test.nim
  5 +
  6 +when isMainModule:
  7 + var v1, v2: Vector3
  8 + v1 = Vector3(x:1, y:2, z:3)
  9 + v2 = Vector3(x:4, y:5, z:6)
  10 + echo foo(v1, v2, 14)
tests/Test.nim.cfg 0 → 100644
  1 +--path:"../src"
  2 +--cpu:i386
  3 +--passC:"-m32"
  4 +--passL:"-m32"
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
  1 +--path:"../src"
  2 +--app:lib
  3 +--cpu:i386
  4 +--passC:"-m32"
  5 +--passL:"-m32"
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")