@@ -4,24 +4,22 @@ const context = @import("context.zig");
44const wrap_function = @import ("wrap_function.zig" );
55const wrap_class = @import ("wrap_class.zig" );
66
7- /// Simple module export — scans pub decls and registers them.
8- /// No lifecycle hooks or env refcounting.
7+ /// Scans pub decls of `Module` and registers them as JS exports.
98///
10- /// Usage: `comptime { js.exportModule(@This()); }`
11- pub fn exportModule (comptime Module : type ) void {
12- exportModuleWithOptions (Module , .{});
13- }
14-
15- /// Module export with optional lifecycle hooks and env refcounting.
16- ///
17- /// Options fields (all optional):
18- /// .init = fn (refcount: u32) !void — called during registration
19- /// .cleanup = fn (refcount: u32) void — called on env exit
9+ /// Optional second argument for lifecycle hooks:
10+ /// js.exportModule(@This(), .{
11+ /// .init = fn (refcount: u32) !void, — called during registration
12+ /// .cleanup = fn (refcount: u32) void, — called on env exit
13+ /// })
2014///
2115/// The DSL manages an atomic refcount internally:
2216/// - .init receives the refcount BEFORE increment (0 = first env)
2317/// - .cleanup receives the refcount AFTER decrement (0 = last env)
24- pub fn exportModuleWithOptions (comptime Module : type , comptime options : anytype ) void {
18+ ///
19+ /// Usage:
20+ /// comptime { js.exportModule(@This()); }
21+ /// comptime { js.exportModule(@This(), .{ .init = ..., .cleanup = ... }); }
22+ pub fn exportModule (comptime Module : type , comptime options : anytype ) void {
2523 const has_init = @hasField (@TypeOf (options ), "init" );
2624 const has_cleanup = @hasField (@TypeOf (options ), "cleanup" );
2725 const has_lifecycle = has_init or has_cleanup ;
0 commit comments