Test1.nim 990 Bytes
# 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

  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, true)

# Generate declarations for Smalltalk code

# 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.} =
  # Just a silly test proc
  result = "x plus y plus c " & $(a.x + b.y + c.float)

# Write the Smalltalk code to file