Return to index

ffi functions

cpointer = c_alloc(size)

top

Allocates a zero-initialized byte buffer of the given size.


cpointer = c_alloc_struct(struct_type_name)

top

Allocates memory for a C struct of the given Za struct type. The struct must be defined with the 'struct' keyword.


int = c_fclose(file_ptr)

top

Closes a FILE* pointer. Returns 0 on success.


cpointer = c_fopen(path,mode)

top

Opens a file and returns a FILE* pointer. Mode is like C fopen ("r", "w", "rb", "wb", etc).


c_free(ptr)

top

Frees a C pointer allocated by c_alloc.


c_free_struct(struct_ptr)

top

Frees a C struct pointer allocated by c_alloc_struct.


int = c_get_byte(ptr,offset)

top

Reads a byte at the given offset in a buffer.


int = c_get_byte_at_addr(address,offset)

top

Reads a byte at the given int64 address + offset. For opaque pointers returned from FFI calls.


float = c_get_double(ptr,offset)

top

Reads a double (64-bit) at the given offset in a buffer.


float = c_get_double_at_addr(address,offset)

top

Reads a double (64-bit) at the given int64 address + offset. For opaque pointers returned from FFI calls.


float = c_get_float(ptr,offset)

top

Reads a float (32-bit) at the given offset in a buffer.


float = c_get_float_at_addr(address,offset)

top

Reads a float (32-bit) at the given int64 address + offset. For opaque pointers returned from FFI calls.


int = c_get_int16(ptr,offset)

top

Reads an int16 at the given offset in a buffer.


int = c_get_int16_at_addr(address,offset)

top

Reads an int16 at the given int64 address + offset. For opaque pointers returned from FFI calls.


int = c_get_int32(ptr,offset)

top

Reads an int32 at the given offset in a buffer.


int = c_get_int32_at_addr(address,offset)

top

Reads an int32 at the given int64 address + offset. For opaque pointers returned from FFI calls.


int = c_get_int64(ptr,offset)

top

Reads an int64 at the given offset in a buffer.


int = c_get_int64_at_addr(address,offset)

top

Reads an int64 at the given int64 address + offset. For opaque pointers returned from FFI calls.


any = c_get_symbol(library_alias,symbol_name)

top

Reads a data symbol (constant/variable) from a loaded C library. Note: C preprocessor #defines are NOT symbols and cannot be read this way.


int = c_get_uint16(ptr,offset)

top

Reads a uint16 at the given offset in a buffer.


int = c_get_uint16_at_addr(address,offset)

top

Reads a uint16 at the given int64 address + offset. For opaque pointers returned from FFI calls.


int = c_get_uint32(ptr,offset)

top

Reads a uint32 at the given offset in a buffer.


int = c_get_uint32_at_addr(address,offset)

top

Reads a uint32 at the given int64 address + offset. For opaque pointers returned from FFI calls.


uint = c_get_uint64(ptr,offset)

top

Reads a uint64 at the given offset in a buffer.


uint = c_get_uint64_at_addr(address,offset)

top

Reads a uint64 at the given int64 address + offset. For opaque pointers returned from FFI calls.


cpointer = c_new_string(str)

top

Allocates a C string (char*) from a Za string. The caller is responsible for freeing it with c_free().


cpointer = c_null()

top

Returns a null C pointer for use in FFI calls.


bool = c_ptr_is_null(ptr)

top

Returns true if the C pointer is null.


int = c_ptr_to_int(ptr)

top

Converts a C pointer to an integer. Useful for size_t, uintptr_t, and other integer-valued returns. Tip: Can also use ptr.ToInt() method for convenience.


string = c_ptr_to_string(ptr)

top

Converts a C string pointer (char*) to a Za string. The pointer should reference valid C string memory.


c_set_byte(ptr,offset,value)

top

Sets a byte at the given offset in a buffer.


c_set_byte_at_addr(address,offset,value)

top

Sets a byte at the given int64 address + offset. For opaque pointers returned from FFI calls.


c_set_double(ptr,offset,value)

top

Writes a double (64-bit) at the given offset in a buffer.


c_set_double_at_addr(address,offset,value)

top

Writes a double (64-bit) at the given int64 address + offset. For opaque pointers returned from FFI calls.


c_set_float(ptr,offset,value)

top

Writes a float (32-bit) at the given offset in a buffer.


c_set_float_at_addr(address,offset,value)

top

Writes a float (32-bit) at the given int64 address + offset. For opaque pointers returned from FFI calls.


c_set_int16(ptr,offset,value)

top

Sets an int16 at the given offset in a buffer.


c_set_int16_at_addr(address,offset,value)

top

Sets an int16 at the given int64 address + offset. For opaque pointers returned from FFI calls.


c_set_int32(ptr,offset,value)

top

Sets an int32 at the given offset in a buffer.


c_set_int32_at_addr(address,offset,value)

top

Sets an int32 at the given int64 address + offset. For opaque pointers returned from FFI calls.


c_set_int64(ptr,offset,value)

top

Sets an int64 at the given offset in a buffer.


c_set_int64_at_addr(address,offset,value)

top

Sets an int64 at the given int64 address + offset. For opaque pointers returned from FFI calls.


c_set_string(ptr,str)

top

Copies a Za string to a C buffer at the given pointer. The buffer must be large enough.


c_set_uint16(ptr,offset,value)

top

Sets a uint16 at the given offset in a buffer.


c_set_uint16_at_addr(address,offset,value)

top

Sets a uint16 at the given int64 address + offset. For opaque pointers returned from FFI calls.


c_set_uint32(ptr,offset,value)

top

Sets a uint32 at the given offset in a buffer.


c_set_uint32_at_addr(address,offset,value)

top

Sets a uint32 at the given int64 address + offset. For opaque pointers returned from FFI calls.


c_set_uint64(ptr,offset,value)

top

Sets a uint64 at the given offset in a buffer.


c_set_uint64_at_addr(address,offset,value)

top

Sets a uint64 at the given int64 address + offset. For opaque pointers returned from FFI calls.


struct = c_unmarshal_struct(struct_ptr,struct_type_name)

top

Reads C struct data from memory and converts it to a Za struct. Use this for 'out' parameters that C functions fill with data.