moonbit-c-binding
MoonBit C Binding Guide
Step-by-step workflow for binding any C library to MoonBit using native FFI.
When To Use
Use this skill when:
- Adding
extern "c" fndeclarations for a C library - Writing C stub files (
moonbit.h,MOONBIT_FFI_EXPORT) - Configuring
moon.pkgfor native builds (native-stub,link.native) - Choosing
#borrowvs ownership transfer for FFI parameters - Wrapping C handles with external objects and finalizers
- Implementing callback trampolines (closures or
FuncRef) - Converting strings between MoonBit (UTF-16) and C (UTF-8)
- Running AddressSanitizer to catch memory bugs in bindings
Plan Mode Instructions
More from moonbitlang/moonbit-agent-guide
moonbit-agent-guide
Guide for writing, refactoring, and testing MoonBit projects. Use when working in MoonBit modules or packages, organizing MoonBit files, using moon tooling (build/check/run/test/doc/ide etc.), or following MoonBit-specific layout, documentation, and testing conventions.
44moonbit-refactoring
Refactor MoonBit code to be idiomatic: shrink public APIs, convert functions to methods, use pattern matching with views, add loop invariants, and ensure test coverage without regressions. Use when updating MoonBit packages or refactoring MoonBit APIs, modules, or tests.
18moonbit-proof
Use when writing or refactoring proof-carrying code in MoonBit, especially for Why3-backed specifications, abstraction functions, representation invariants, proof assertions, recursive verified data structures, or reducing trusted proof bridges.
4