# We exercise some trivial types and how they map. # # SqueakFFI Nim # ========= ====== # long => int # char* => cstring import math # A single proc, returns an int. Since we are on 32 bits # an int is 4 bytes (same size as pointer) and in Squeak FFI # this is a long. The exportc pragma ensures that the exported # name for this proc is exactly "hello" and not mangled. proc hello*(): int {.exportc.} = 42 # Trivial, a Nim string can be sent as a cstring because they are # automatically 0-terminated. proc foo*(): cstring {.exportc.} = "hey" # Not a problem taking int arguments, they are "long" in Squeak FFI. proc add*(x, y:int): int {.exportc.} = x + y # Just return the length of a cstring proc length*(x: cstring): int {.exportc.} = len(x) # Here we convert cstrings to Nim strings, concatenate and return. proc concat*(x, y: cstring): cstring {.exportc.} = $x & $y