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.pkgormoon.pkg.jsonfor 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/skills
moonbit-extract-spec-test
Extract formal spec and comprehensive test suites from existing MoonBit implementations. Use when asked to "extract spec from implementation", "generate tests from code", or "create spec-driven tests for existing package". Analyzes existing code to produce spec.mbt with `declare` keyword stubs and organized test files (valid/invalid).
9moonbit-orientation
Use this skill when the user needs help solving MoonBit language, code, compiler diagnostic, package, toolchain, backend, FFI, test, or "does MoonBit have X?" questions. Use it even when MoonBit is only implied by .mbt files, moon.mod.json, moon.pkg.json, moon commands, wasm/js/native targets, or mooncakes packages. This skill helps choose the right MoonBit source of truth, discover APIs with moon ide, avoid stale assumptions, and validate fixes.
2