Raw pointers (Ptr) and the foreign-function interface (Ffi): the FFI surface for C interop.
ns
ptr/ffiare de-registered; low-level/hot callers fetch-and-cache the prims. int->ptr is nsint(Ptr from-int).
Ptr(Ptr from-int n)Construct a pointer from an integer address (the int->ptr cast).
Parameters:
INT — Integer addressReturns: PTR — A pointer to that address
(Ptr ptr? x)Test whether a value is a raw pointer.
Parameters:
ANY — Value to testReturns: BOOL — True if x is a pointer
(Ptr ->int p)The integer (address) representation of a pointer.
Parameters:
PTR — A pointerReturns: INT — Integer address
(Ptr ->str p)Copy the NUL-terminated C string at P into a fresh x-lang string.
Parameters:
PTR — A C string pointerReturns: STRING — A new string (survives the C buffer)
(Ptr ref p off width)Read a WIDTH-byte little-endian value at P+OFF.
Parameters:
PTR — Base pointerINT — Byte offsetINT — Read width in bytes (1,2,4,8)Returns: INT — The value read
(Ptr set! p off v width)Write a WIDTH-byte little-endian value V at P+OFF.
Parameters:
PTR — Base pointerINT — Byte offsetINT — Value to storeINT — Write width in bytesReturns: ANY — nil
(Ptr ref-word p off)Read one machine word (sizeof(long)) at P+OFF.
Parameters:
PTR — Base pointerINT — Byte offsetReturns: INT — The word value
(Ptr set-word! p off v)Write one machine word V at P+OFF.
Parameters:
PTR — Base pointerINT — Byte offsetINT — Word value to storeReturns: ANY — nil
(Ptr call p . args)Call a C function pointer with string arguments.
Parameters:
PTR — C function pointerSTRING — String arguments (variadic)Returns: INT — The C return value
Ffi(Ffi dlopen path mode)Load a shared library.
Parameters:
STRING — Library file path (() for the main program)INT — dlopen mode flags (e.g. 1 = RTLD_LAZY)Returns: PTR — Library handle, or () on failure
(Ffi dlsym lib name)Look up a symbol in a loaded library.
Parameters:
PTR — Library handle from dlopenSTRING — Symbol nameReturns: PTR — Function or data pointer
(Ffi call sig lib . args)Invoke a C function through the typed-signature FFI bridge.
Parameters:
STRING — Calling signature (e.g. “d+d”, “s0->d”)ANY — Library handle, or () for a built-in signatureANY — Call arguments (variadic)Returns: ANY — The converted C return value