diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 0000000..739a54a --- /dev/null +++ b/src/.gitignore @@ -0,0 +1 @@ +nimcache diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..182f0f7 --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1,4 @@ +libTest1.so +Test +Test1.st +nimcache diff --git a/tests/Test.nim b/tests/Test.nim new file mode 100644 index 0000000..8c1143d --- /dev/null +++ b/tests/Test.nim @@ -0,0 +1,10 @@ +import Test1 + +# Just to try out the Nim Test1.foo proc from Nim +# nim c -r Test.nim + +when isMainModule: + var v1, v2: Vector3 + v1 = Vector3(x:1, y:2, z:3) + v2 = Vector3(x:4, y:5, z:6) + echo foo(v1, v2, 14) diff --git a/tests/Test.nim.cfg b/tests/Test.nim.cfg new file mode 100644 index 0000000..6bdf350 --- /dev/null +++ b/tests/Test.nim.cfg @@ -0,0 +1,4 @@ +--path:"../src" +--cpu:i386 +--passC:"-m32" +--passL:"-m32" diff --git a/tests/Test1.nim b/tests/Test1.nim new file mode 100644 index 0000000..aa04380 --- /dev/null +++ b/tests/Test1.nim @@ -0,0 +1,32 @@ +# 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 +# to call foo, see class side of Test1 + +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 +wrapObject(Vector3) + +# Generate declarations for Smalltalk code +writeExternalLibrary() + +# Here follows Nim procedures that will be callable via FFI +# Note that exportSt pragma to export. + +proc foo*(a, b: Vector3, c: int): cstring {.exportSt: "bar".} = + # Just a silly test proc + result = "x plus y plus c " & $(a.x + b.y + c.float) + +# Write the Smalltalk code to file +writeSmallTalkCode("Test1.st") diff --git a/tests/Test1.nim.cfg b/tests/Test1.nim.cfg new file mode 100644 index 0000000..9033368 --- /dev/null +++ b/tests/Test1.nim.cfg @@ -0,0 +1,5 @@ +--path:"../src" +--app:lib +--cpu:i386 +--passC:"-m32" +--passL:"-m32" diff --git a/tests/test1.nim b/tests/test1.nim deleted file mode 100644 index 992d136..0000000 --- a/tests/test1.nim +++ /dev/null @@ -1,18 +0,0 @@ - -import squeaknim - -type - MyFloat = float32 - Vector3 = object - x, y, z: MyFloat - -setModulename "urhonimo", "UR" - -wrapObject(Vector3) - -writeExternalLibrary() - -proc foo(a, b: Vector3): cstring {.exportSt: "bar".} = - result = "some string here" - -writeSmallTalkCode("test1.st")