c

FFI Binding to C

moon add tonyfettes/c@0.7.8
Download zip
Version
0.7.8
License
Apache-2.0
Last updated
2 months ago
Downloads
10K

Dependencies

README

#tonyfettes/c

FFI Binding to C.

#Usage

  1. Add this library using moon add:

    moon add tonyfettes/c

  2. Import the library in your moon.pkg.json:

    { "import": [ "tonyfettes/c" ] }

  3. Insert the following code somewhere in your MoonBit code:

    fn init {
    ignore(@c.moonbit_ffi_make_closure)
    }

    This prevents the closure help function from being eliminated by the MoonBit compiler.

  4. Use the library in your code.

#
Load

pub(open) trait Load {
load(Pointer[Self], Int) -> Self
}

impl Load for Byte
impl Load for Int
impl Load for Int16
impl Load for Int64
impl Load for UInt
impl Load for UInt16
impl Load for UInt64
impl Load for Float
impl Load for Double

#
Store

trait Store

impl Store for Byte
impl Store for Int
impl Store for Int16
impl Store for Int64
impl Store for UInt
impl Store for UInt16
impl Store for UInt64
impl Store for Float
impl Store for Double

#
Null

#external
pub type Null

#
Nullable

#external
pub type Nullable[_]

#
Nullable::is_null

fn[T] Nullable::is_null(self : Nullable[T]) -> Bool

#
Nullable::none

fn[T] Nullable::none() -> Nullable[T]

#
Nullable::of

fn[T] Nullable::of(option : T?) -> Nullable[T]

#
Nullable::some

fn[T] Nullable::some(value : T) -> Nullable[T]

#
Nullable::to

fn[T] Nullable::to(self : Nullable[T]) -> T?

#
Pointer

#external
pub type Pointer[_]

impl Eq for Pointer[T]

#
Pointer::cast

fn[T, U] Pointer::cast(self : Pointer[T]) -> Pointer[U]

#
Pointer::is_null

fn[T] Pointer::is_null(self : Pointer[T]) -> Bool

#
Pointer::load

fn[T : Load] Pointer::load(self : Pointer[T], offset? : Int) -> T

#
Pointer::null

fn[T] Pointer::null() -> Pointer[T]

#
Pointer::op_equal

fn Pointer::op_equal(self : Pointer[Unit], other : Pointer[Unit]) -> Bool

#
Pointer::op_get

fn[T : Load] Pointer::op_get(self : Pointer[T], index : Int) -> T

#
Pointer::op_set

fn[T : Store] Pointer::op_set(self : Pointer[T], index : Int, value : T) -> Unit

#
Pointer::store

fn[T : Store] Pointer::store(self : Pointer[T], offset? : Int, value : T) -> Unit

#
none

fn[T] none() -> Nullable[T]

#
null

let null : Null

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io