Nim C Wrappersのロゴ

Nim C Wrappers

コミュニティ
planetis-m
nim-c-wrappers

低レベルのC FFIバインディングを、安全性の高い型、明確なモジュール境界、リソース管理、コールバック、列挙型、ビットフラグ、例外ベースのエラー処理を備えた、NimらしいAPIに変換します。Cライブラリをラップする高レベルのNim APIを構築する場合や、既存の低レベルバインディングの使いやすさを改善する場合に役立ちます。

Add to TypingMind

概要

公開者planetis-m
リポジトリskills
スキル名nim-c-wrappers
スター
66
フォーク
7
同梱ファイル
5
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 5個の同梱ファイル

    モデルが作業中に読み取れるスクリプト、テンプレート、参考資料です。ファイルは読み取り専用で、実行されることはありません。

  • オープンソース

    planetis-mがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキル「Nim C Wrappers」をTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/planetis-m/skills/tree/master/nim-c-wrappers
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/planetis-m/skills.git /tmp/skills
mkdir -p .claude/skills
cp -r /tmp/skills/nim-c-wrappers .claude/skills/nim-c-wrappers
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでNim C Wrappersを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあるとすぐに、モデルが自動的にNim C Wrappersを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Nim C Wrappersは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、スキルを使わない間は指示の読み込みにトークンを消費しません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

Nim C Wrappers

Rules

Architecture

  • Use a two-layer design: raw FFI layer (ABI-faithful) + ergonomic Nim layer (safe, idiomatic). Keep the raw layer thin and stable.
  • Split modules by library domain. Mirror the C header structure for large libraries.
  • Centralize shared types in a lib_raw_types module to avoid cyclic imports.
  • Export raw symbols only for advanced users; re-export selected symbols from ergonomic modules.

Raw FFI Layer

  • Use importc with cdecl (or stdcall if the library requires it). Prefer {.push callconv: cdecl, importc.} blocks for shared conventions.
  • header declares linker-resolved imports; dynlib loads symbols at runtime. Do not combine them on one proc. Guard library names with when defined(windows): etc.
  • Never reorder struct fields. Use object in C field order. Add packed only if C headers specify packing.
  • Use incompleteStruct and list only needed fields to reduce ABI risk.
  • For C enums, use distinct integer types + const values. Do not use Nim enum in raw bindings. Find actual enum values in C headers—do not guess.
  • For bitflags, use distinct integer types with bitwise helpers. Do not use set[Enum].
  • Map C macros: numeric → const; function-like → template; use inline proc when arguments should evaluate once.
  • Keep pointer types as C intends — do not convert them in the raw layer.

Type Mapping

C TypeNim TypeNotes
charccharPlatform-dependent signedness
signed charcscharAlways int8
unsigned charuint8Safer default spelling; avoid relying on cuchar status across Nim versions
shortcshortAlways int16
unsigned shortcushortAlways uint16
intcintAlways int32
unsigned intcuintAlways uint32
longclongABI-sized (4 on Win64, 8 on LP64)
unsigned longculongABI-sized
long longclonglongAlways int64
unsigned long longculonglongAlways uint64
size_tcsize_tAlias for uint
intptr_tintPointer-sized signed
uintptr_tuintPointer-sized unsigned
floatcfloatAlways float32
doublecdoubleAlways float64
long doubleclongdoubleLimited codegen support
void*pointerUntyped
T*ptr TNullable
T**ptr ptr T
char* / const char*cstringNUL-terminated
char**cstringArrayptr UncheckedArray[cstring]

Struct types: object in C order. Fixed arrays: array[N, T]. Pointer+length: ptr T + csize_t. Raw buffers: ptr UncheckedArray[T]. Opaque handles: pointer or ptr OpaqueObj (empty object).

Ergonomic Layer

  • In =destroy, explicitly call =destroy on owned nested GC-managed fields (string, seq) after releasing C resources.
  • Define ownership hooks in the same module as the type. Cross-module hook definitions are a compile error.
  • Raise exceptions (IOError, ValueError, etc.) for C errors — do not return result wrappers that only carry ok/kind/message.
  • Do not create custom exception types unless callers handle them differently.
  • Catch errors only at translation boundaries (C return code → Nim exception, or exception → domain result). Let exceptions propagate otherwise.

Naming

  • In raw bindings, match C identifier names directly.
  • importc without an explicit string resolves the C symbol from the Nim name.
  • Strip redundant C prefixes (LIB_, foo_) in the ergonomic layer.
  • Keep raw constant names in C style (e.g., CURLE_OK).
  • When a C identifier collides with a Nim keyword, rename the Nim identifier and use importc: to map to the original C name.

Callbacks

  • Declare callbacks as plain C-callable procs such as proc onEvent(code: cint; userData: pointer) {.cdecl.}.
  • Pass closure state through userdata via rawProc/rawEnv. See references/callback_pattern.md.

Verification

  • Add static: doAssert sizeof(T) == N and offsetOf checks in tests to verify struct layouts.
  • Test ABI with compile + link + smoke test + runtime checks.

Workflow

  1. Read the C API. Identify structs, enums, functions, callbacks, and ownership semantics.
  2. Map types. Use the type table. Verify sizes with static: doAssert sizeof.
  3. Write raw bindings. One module per C header or subsystem. Centralize shared raw types to avoid cycles. Use importc, correct calling convention, packed only when C specifies it. Use typed integer aliases for enums.
  4. Write ergonomic wrappers. Add destructors for owned resources (move-only or RC). Raise exceptions for C errors. Re-export only the intended public surface. Strip prefixes.
  5. Test. Compile check → link check → smoke test → ABI sizeof/offset asserts → runtime ownership tests.
  6. Iterate. Add missing APIs as needed. Keep raw layer stable.

Common Mistakes

MistakeWhy it's wrong
Passing Nim string directly to char* parameterType mismatch; use .cstring
Using seq where C expects stable pointeradd() can reallocate, invalidating the pointer
Reordering struct fieldsBreaks ABI layout, causes garbage values
Using Nim enum for C enum valuesABI incompatibility; use typed integer aliases
Adding enum or constant values without inspecting headersFind actual enum values in C headers, do not guess
Passing closures as C callbacksC expects plain function pointers, not GC closures
Storing cstring beyond the callcstring from string.cstring dangles after the source is freed
=dup body using result = src in RC patternMay trigger implicit =copy instead of =dup; use field-by-field assignment
Wrong calling conventionCauses crashes at call sites

References

  • references/move_only_resource.md — A move-only wrapper for one owner of a C handle.
  • references/rc_resource.md — A reference-counted wrapper for shared C resource ownership.
  • references/callback_pattern.md — C callbacks with userdata, captured Nim state, and lifetime management.
  • references/enum_and_bitflags.md — Distinct-integer wrappers for non-contiguous enums and bitwise flags.
  • references/module_layout.md — Separating raw FFI from an ergonomic API in two modules.

同梱ファイル

スキルが読み込まれている間、モデルは必要に応じてこれらを読み取ります。読み取り可能なファイルとして提供され、実行されることはありません。

よくある質問

AIスキル「Nim C Wrappers」では何ができますか?

低レベルのC FFIバインディングを、安全性の高い型、明確なモジュール境界、リソース管理、コールバック、列挙型、ビットフラグ、例外ベースのエラー処理を備えた、NimらしいAPIに変換します。Cライブラリをラップする高レベルのNim APIを構築する場合や、既存の低レベルバインディングの使いやすさを改善する場合に役立ちます。

TypingMindでNim C Wrappersを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Nim C Wrappersはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにNim C Wrappersをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/planetis-m/skills/tree/master/nim-c-wrappersを貼り付けてください。TypingMindがSKILL.mdを読み込み、関連ファイルをまとめて、チャットごとに有効にできるスキルとしてインストールします。

Nim C Wrappersを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストの内容がこのスキルの用途に合ったときに、このスキルを読み込めます。

Nim C Wrappersで使えるAIモデルの数に制限はありますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもNim C Wrappersを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Nim C Wrappers」は無料ですか?

planetis-mがGitHubで公開しています。ライセンス条件はリポジトリでご確認ください。ご利用のAIプロバイダーに支払うのは、使用したトークンの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇