bun-ffi

Solid

This skill should be used when the user asks about "bun:ffi", "foreign function interface", "calling C from Bun", "native libraries", "dlopen", "shared libraries", "calling native code", or integrating C/C++ libraries with Bun.

Data & Documents 162 stars 25 forks Updated 2 weeks ago MIT

Install

View on GitHub

Quality Score: 88/100

Stars 20%
74
Recency 20%
90
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
80
License 10%
100
Description 5%
100

Skill Content

# Bun FFI Bun's FFI allows calling native C/C++ libraries from JavaScript. ## Quick Start ```typescript import { dlopen, suffix, FFIType } from "bun:ffi"; // Load library const lib = dlopen(`libc.${suffix}`, { printf: { args: [FFIType.cstring], returns: FFIType.int, }, }); // Call function lib.symbols.printf("Hello from C!\n"); ``` ## Loading Libraries ### Platform-Specific Paths ```typescript import { dlopen, suffix } from "bun:ffi"; // suffix is: "dylib" (macOS), "so" (Linux), "dll" (Windows) // System library const libc = dlopen(`libc.${suffix}`, { ... }); // Custom library const myLib = dlopen(`./libmylib.${suffix}`, { ... }); // Absolute path const sqlite = dlopen("/usr/lib/libsqlite3.so", { ... }); ``` ### Cross-Platform Loading ```typescript function getLibPath(name: string): string { const platform = process.platform; const paths = { darwin: `/usr/local/lib/lib${name}.dylib`, linux: `/usr/lib/lib${name}.so`, win32: `C:\\Windows\\System32\\${name}.dll`, }; return paths[platform] || paths.linux; } const lib = dlopen(getLibPath("mylib"), { ... }); ``` ## FFI Types ```typescript import { FFIType } from "bun:ffi"; const types = { // Integers i8: FFIType.i8, // int8_t i16: FFIType.i16, // int16_t i32: FFIType.i32, // int32_t / int i64: FFIType.i64, // int64_t / long long // Unsigned integers u8: FFIType.u8, // uint8_t u16: FFIType.u16, // uint16_t u32: FFIType.u32, //...

Details

Author
secondsky
Repository
secondsky/claude-skills
Created
6 months ago
Last Updated
2 weeks ago
Language
TypeScript
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category