zig-expert
БесплатноБез исполняемых скриптовНе проверенExpert knowledge in Zig systems programming, comptime metaprogramming, manual memory management, and C interoperability. Use when the user mentions systems…
от personamanagmentlayer★ 46 звёзд на GitHubОб этом скилле
Zig Expert
You are an expert in Zig programming language, specializing in systems programming, compile-time metaprogramming, manual memory management, and C interoperability.
Core Concepts
Memory Management
- Allocators: Explicit allocation strategy with allocator pattern
- No Hidden Control Flow: All memory operations are explicit
- Defer/Errdefer: Guaranteed cleanup and error handling
- RAII Alternative: Manual resource management with defer
- Arena Allocators: Efficient bulk deallocation
- Stack vs Heap: Clear distinction and control
Comptime Metaprogramming
- Comptime Execution: Run arbitrary code at compile time
- Generic Functions: Type-generic programming without templates
- Type Reflection: Inspect and manipulate types at comptime
- Code Generation: Generate functions, structs, and data
- Inline Assembly: Low-level control when needed
Error Handling
- Error Unions: Explicit error handling with
!operator - Try/Catch: Propagate or handle errors explicitly
- Error Sets: Define possible error conditions
- Payload Capture: Extract values from error unions
- Switch on Errors: Pattern match on error types
C Interoperability
- C ABI Compatibility: Direct C function calls
- Translate-C: Automatic C header translation
- Export to C: Export Zig functions for C consumption
- Packed Structs: Match C memory layouts
- Opaque Types: Work with C types safely
Code Examples
Installation and Setup
# Install Zig
# Download from https://ziglang.org/download/
# Verify installation
zig version
# Create new project
mkdir my-project && cd my-project
zig init-exe
# Build and run
zig build run
# Test
zig build test
# Release build (optimized)
zig build -Doptimize=ReleaseFast
Basic Memory Management
const std = @import("std");
const Allocator = std.mem.Allocator;
pub fn main() !void {
// Get general purpose allocator
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
// Single allocation
const value = try allocator.create(i32);
defer allocator.destroy(value);
value.* = 42;
// Slice allocation
const items = try allocator.alloc(u8, 100);
defer allocator.free(items);
// Dynamic array (ArrayList)
var list = std.ArrayList(i32).init(allocator);
defer list.deinit();
try list.append(1);
try list.append(2);
// Arena allocator for bulk operations
var arena = std.heap.ArenaAllocator.init(allocator);
defer arena.deinit();
const arena_allocator = arena.allocator();
// All allocations freed at once on deinit
_ = try arena_allocator.alloc(u8, 1000);
_ = try arena_allocator.alloc(i32, 50);
}
Comptime Metaprogramming
const std = @import("std");
// Generic function with comptime
fn max(comptime T: type, a: T, b: T) T {
return if (a > b) a else b;
}
// Comptime type inspection
fn printTypeInfo(comptime T: type) void {
const info = @typeInfo(T);
std.debug.print("Type: {s}\n", .{@typeName(T)});
switch (info) {
.Struct => |s| std.debug.print("Struct with {} fields\n", .{s.fields.len}),
.Int => |i| std.debug.print("Int: signed={}, bits={}\n", .{i.signedness == .signed, i.bits}),
else => {},
}
}
// Generic data structure
fn Stack(comptime T: type, comptime capacity: usize) type {
return struct {
items: [capacity]T = undefined,
len: usize = 0,
const Self = @This();
pub fn push(self: *Self, item: T) !void {
if (self.len >= capacity) return error.StackOverflow;
self.items[self.len] = item;
self.len += 1;
}
pub fn pop(self: *Self) ?T {
if (self.len == 0) return null;
self.len -= 1;
return self.items[self.len];
}
};
}
// Comptime code generation
fn generateGetters(comptime T: type) type {
const fields = @typeInfo(T).Struct.fields;
var struct_fields: [fields.len]std.builtin.Type.StructField = undefined;
inline for (fields, 0..) |field, i| {
struct_fields[i] = .{
.name = "get_" ++ field.name,
.type = fn(T) field.type,
.default_value = null,
.is_comptime = false,
.alignment = 0,
};
}
return @Type(.{ .Struct = .{
.layout = .Auto,
.fields = &struct_fields,
.decls = &.{},
.is_tuple = false,
}});
}
pub fn main() !void {
// Use generic function
const a = max(i32, 10, 20);
const b = max(f64, 3.14, 2.71);
// Use comptime-generated stack
var stack = Stack(i32, 10){};
try stack.push(42);
if (stack.pop()) |value| {
std.debug.print("Popped: {}\n", .{value});
}
// Comptime type inspection
printTypeInfo(i32);
printTypeInfo(struct { x: f32, y: f32 });
}
Error Handling
Установить zig-expert в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadWriteEditBashGlobGrepFAQ
Что делает скилл zig-expert?
Expert knowledge in Zig systems programming, comptime metaprogramming, manual memory management, and C interoperability. Use when the user mentions systems programming, comptime, memory management, c interop, low level, or performance, or when the task involves Comptime Metaprogramming, C Interoperability, Installation and Setup, or Basic Memory Management.
Как установить скилл zig-expert?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл zig-expert запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic