@@ -4,6 +4,22 @@ Thanks to its conventions-based approach it bridges the gap seamlessly, with alm
44![ build-badge] ( https://img.shields.io/github/actions/workflow/status/typesafe/node-api-zig/ci.yml )
55![ test-badge] ( https://img.shields.io/endpoint?url=https%3A%2F%2Fgist.githubusercontent.com%2Ftypesafe%2F26882516c7ac38bf94a81784f966bd86%2Fraw%2Fnode-api-zig-test-badge.json )
66
7+ ## Features
8+
9+ - ** function mapping** , including async support (auto-conversion to Promises)
10+ - ** class mapping** , incl. support for fields, instance (async) methods, satic (async) methods.
11+ - ** auto-wrapping** of native objects instances, similar to defining classes but for instances created in native Zig code
12+ - ** memory management** with convention-based ` init ` , ` deinit ` support & ` allocator ` injection
13+ - ` errorunion ` support
14+ - mapping JS values
15+ - by value: through (de)serialization or various types
16+ - by reference
17+ - Zig-managed values: through pointers to (wrapped) native Zig values
18+ - JS-managed values: through wrappers types (` NodeValue ` et.al.) for read/write
19+ - typesafe callbacks: ` NodeFunction(fn (u32, u32) !u32) `
20+
21+ ## Example
22+
723``` zig
824const node_api = @import("node-api");
925const Options = @import("Options");
@@ -47,23 +63,55 @@ TODO:
4763 - [ ] ` ExternalArrayBuffer `
4864- [ ] Use ` Result(T, E) ` as alternative to ` errorunion ` s for improved error messages.
4965
50- # Features
66+ # Getting started
5167
52- - ** function mapping** , including async support (auto-conversion to Promises)
53- - ** class mapping** , incl. support for fields, instance methods, satic methods
54- - ** auto-wrapping** of native objects instances, similar to defining classes but for instances created in native Zig code
55- - ** memory management** with convention-based ` init ` , ` deinit ` support & ` allocator ` injection
56- - ` errorunion ` support
57- - mapping JS values
58- - by value: through (de)serialization or various types
59- - by reference
60- - Zig-managed values: through pointers to (wrapped) native Zig values
61- - JS-managed values: through wrappers types (` NodeValue ` et.al.) for read/write
62- - typesafe callbacks: ` NodeFunction(fn (u32, u32) !u32) `
68+ Install the ` node_api ` (note the underscore) dependency
6369
64- # Getting started
70+ ``` sh
71+ > zig fetch --save https://github.com/typesafe/node-api-zig/archive/refs/tags/v0.0.3-beta.tar.gz
72+ ```
73+
74+ Add the ` node-api ` (note the hyphen) module to your library.
75+
76+ ``` zig
77+ const std = @import("std");
78+
79+ pub fn build(b: *std.Build) void {
80+ const target = b.standardTargetOptions(.{});
81+ const optimize = b.standardOptimizeOption(.{});
82+
83+ const mod = b.addModule("root", .{
84+ .root_source_file = b.path("src/root.zig"),
85+ .target = target,
86+ .optimize = optimize,
87+ });
88+
89+ const node_api = b.dependency("node_api", .{});
90+ mod.addImport("node-api", node_api.module("node-api"));
6591
66- TODO
92+ const lib = b.addLibrary(.{
93+ // needed on Linux
94+ .use_llvm = true,
95+ .name = "my-native-node-library",
96+ .root_module = mod,
97+ });
98+
99+ b.installArtifact(lib);
100+ }
101+ ```
102+
103+ Initialize your Node-API extension:
104+
105+ ``` zig
106+ const std = @import("std");
107+ const node = @import("node-api");
108+
109+ comptime {
110+ node.@"export"(.{
111+ // functions, types (for classes), values
112+ });
113+ }
114+ ```
67115
68116# Features
69117
0 commit comments