bun-ffi
仓库创建 2025年11月8日最近提交 29 天前SkillHot 收录 22 天前
▸ 精选理由
适合需复用原生库或追求极限性能的高级用例。
▸ 风险提示
加载本地共享库并执行原生代码,存在安全与稳定性风险。
这个 Skill 做什么
通过 bun:ffi 在 Bun 中调用本地 C/C++ 库并与 JavaScript 交互。
在 Bun 里用 bun:ffi 从 JavaScript/TypeScript 调用本地 C/C++ 库(dlopen、shared library),可以在 JS 侧声明 C 函数签名并直接调用原生接口。适合需要把已有本地库或高性能 C/C++ 代码集成到 Bun 应用,或访问系统级原生 API 的场景。特点是示例直观,能在 Bun 环境里快速加载共享库并互操作原生类型。
▸ 展开 SKILL.md 英文原文
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.
180
Stars
28
Forks
40
仓库内 Skill
+0
7 日增星
安装 / 使用
给你的 Agent 一句话(通用)
帮我安装这个 skill:https://raw.githubusercontent.com/secondsky/claude-skills/main/plugins/bun/skills/bun-ffi/SKILL.md或 curl 直取 SKILL.md
curl -fsSL "https://raw.githubusercontent.com/secondsky/claude-skills/main/plugins/bun/skills/bun-ffi/SKILL.md"SKILL.MD 节选查看完整文件 ↗
# 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 = dlopevia SKILL·HOT · 数据来自 GitHub 公开信息 · 原文版权归作者所有