x-lang

← Index

x/type/ptr

Raw pointers (Ptr) and the foreign-function interface (Ffi): the FFI surface for C interop.

ns ptr/ffi are de-registered; low-level/hot callers fetch-and-cache the prims. int->ptr is ns int (Ptr from-int).

Class Ptr

(Ptr from-int n)

Construct a pointer from an integer address (the int->ptr cast).

Parameters:

Returns: PTR — A pointer to that address

(Ptr ptr? x)

Test whether a value is a raw pointer.

Parameters:

Returns: BOOL — True if x is a pointer

(Ptr ->int p)

The integer (address) representation of a pointer.

Parameters:

Returns: INT — Integer address

(Ptr ->str p)

Copy the NUL-terminated C string at P into a fresh x-lang string.

Parameters:

Returns: STRING — A new string (survives the C buffer)

(Ptr ref p off width)

Read a WIDTH-byte little-endian value at P+OFF.

Parameters:

Returns: INT — The value read

(Ptr set! p off v width)

Write a WIDTH-byte little-endian value V at P+OFF.

Parameters:

Returns: ANY — nil

(Ptr ref-word p off)

Read one machine word (sizeof(long)) at P+OFF.

Parameters:

Returns: INT — The word value

(Ptr set-word! p off v)

Write one machine word V at P+OFF.

Parameters:

Returns: ANY — nil

(Ptr call p . args)

Call a C function pointer with string arguments.

Parameters:

Returns: INT — The C return value

Class Ffi

(Ffi dlopen path mode)

Load a shared library.

Parameters:

Returns: PTR — Library handle, or () on failure

(Ffi dlsym lib name)

Look up a symbol in a loaded library.

Parameters:

Returns: PTR — Function or data pointer

(Ffi call sig lib . args)

Invoke a C function through the typed-signature FFI bridge.

Parameters:

Returns: ANY — The converted C return value