tts-tool
Generate a natural-sounding `.opus` audio file from text or markdown. Use when a user wants spoken audio, especially for content with markdown, URLs, formulas, paths, or technical notation that should be rewritten for speech.
nim-c-wrappers
Turn low-level C FFI bindings into an idiomatic Nim API, with safer types, cleaner module boundaries, resource management, callbacks, enums, bitflags, and exception-based error handling. Use when building a high-level Nim wrapper around a C library or improving the usability of existing raw bindi...
Full skill instructions
This skill covers the two-layer pattern for wrapping C libraries in Nim: a raw FFI layer for ABI correctness and an ergonomic Nim layer for safety and usability. Larger examples live in references/.
lib_raw_types module to avoid cyclic imports.importc with cdecl (or stdcall if the library requires it). Prefer {.push callconv: cdecl, header: "foo.h".} blocks for shared conventions.{.header.} for static linking, {.dynlib.} for dynamic linking. Guard library names with when defined(windows): etc.object in C field order. Add packed only if C headers specify packing.incompleteStruct and list only needed fields to reduce ABI risk.distinct integer types + const values. Do not use Nim enum in raw bindings. Find actual enum values in C headers—do not guess.distinct integer types with bitwise helpers. Do not use set[Enum].const; function-like → inline proc or template; sizeof/side-effect → template.| C Type | Nim Type | Notes |
|---|---|---|
char | cchar | Platform-dependent signedness |
signed char | cschar | Always int8 |
unsigned char | uint8 | Safer default spelling; avoid relying on cuchar status across Nim versions |
short | cshort | Always int16 |
unsigned short | cushort | Always uint16 |
int | cint | Always int32 |
unsigned int | cuint | Always uint32 |
long | clong | ABI-sized (4 on Win64, 8 on LP64) |
unsigned long | culong | ABI-sized |
long long | clonglong | Always int64 |
unsigned long long | culonglong | Always uint64 |
size_t | csize_t | Alias for uint |
intptr_t | int | Pointer-sized signed |
uintptr_t | uint | Pointer-sized unsigned |
float | cfloat | Always float32 |
double | cdouble | Always float64 |
long double | clongdouble | Limited codegen support |
void* | pointer | Untyped |
T* | ptr T | Nullable |
T** | ptr ptr T | |
char* / const char* | cstring | NUL-terminated |
char** | cstringArray | ptr 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).
=destroy, =wasMoved, =sink; mark =copy and =dup with {.error.}. Use ensureMove() for ownership transfer.ptr int counter. =copy/=dup increment, =destroy decrements and frees at zero. Use field-by-field assignment in =dup, not result = src.=destroy, explicitly call =destroy on owned nested GC-managed fields (string, seq) after releasing C resources.CURLE_OK).type → typ, addr → address, or use importc: to preserve the C name.proc onEvent(code: cint; userData: pointer) {.cdecl.}. Do not pass Nim closures to C.userdata. Ensure Nim data is globally rooted or manually managed.static: doAssert sizeof(T) == N and offsetOf checks in tests to verify struct layouts.static: doAssert sizeof.importc, correct calling convention, packed only when C specifies it. Use typed integer aliases for enums.| Mistake | Why it's wrong |
|---|---|
Passing Nim string directly to char* parameter | Type mismatch; use .cstring |
Using seq where C expects stable pointer | add() can reallocate, invalidating the pointer |
| Reordering struct fields | Breaks ABI layout, causes garbage values |
Using Nim enum for C enum values | ABI incompatibility; use typed integer aliases |
| Adding enum or constant values without inspecting headers | Find actual enum values in C headers, do not guess |
| Passing closures as C callbacks | C expects plain function pointers, not GC closures |
Storing cstring beyond the call | cstring from string.cstring dangles after the source is freed |
=dup body using result = src in RC pattern | May trigger implicit =copy instead of =dup; use field-by-field assignment |
| Wrong calling convention | Causes crashes at call sites |
references/move_only_resource.md — Complete move-only resource wrapper with destructor hooksreferences/rc_resource.md — Reference-counted (shared ownership) resource wrapperreferences/callback_pattern.md — C callback pattern using direct pointer castingreferences/enum_and_bitflags.md — Typed aliases for enums and distinct types for bitflagsreferences/module_layout.md — Shared-types module plus selective ergonomic re-exportsGenerate a natural-sounding `.opus` audio file from text or markdown. Use when a user wants spoken audio, especially for content with markdown, URLs, formulas, paths, or technical notation that should be rewritten for speech.
Design clear public Nim APIs for libraries and modules, including exported types, constructors, lookup functions, error contracts, and container-style interfaces. Use when creating or reviewing a Nim library API, designing an exported module surface, or deciding how callers should construct, acce...
Extract raw text from PDF files with OCR, including full-document extraction, selected page ranges, and reuse of cached pages. Use when a user asks to OCR a PDF, extract text from a scanned PDF, or read selected PDF pages.
Write clear, consistent Nim code in a simple stdlib-aligned style, covering imports, naming, proc vs func vs template choices, local variables, constructors, formatting, and control flow. Use when writing new Nim code or reviewing a Nim module for readability, consistency, and low-noise style dec...
Store and search text or markdown as semantic chunks in a reusable local vector store. Use when a user wants to ingest documents or retrieve relevant passages from previously stored material.
Study assistant workflow for turning provided study material into exam-focused deliverables such as verbatim transcriptions, study notes, lecture-style explanations, ELI5 explanations, flashcards, Mermaid mind maps, quizzes, and essay questions.
Organize Nim code into clear modules and multi-step workflows, with explicit state, top-level helper procs, narrow exports, and easy-to-follow orchestration. Use when refactoring a large Nim file, splitting logic across modules, designing parser-style stateful code, or cleaning up nested helpers ...
Implement and review Nim ARC/ORC ownership hooks for types that manually manage resources, including move-only, deep-copy, refcounted, and copy-on-write patterns. Use when a Nim type owns pointers, buffers, file descriptors, or custom heap memory and you need correct `=destroy`, `=copy`, `=dup`, ...
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience