-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass.zig
More file actions
37 lines (29 loc) · 950 Bytes
/
class.zig
File metadata and controls
37 lines (29 loc) · 950 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const std = @import("std");
const napi = @import("napi");
const Test = struct {
name: []u8,
age: i32,
};
const TestWithInit = struct {
name: []u8,
age: i32,
pub const hello = "Hello";
pub fn init(age: i32, name: []u8) TestWithInit {
return TestWithInit{ .name = name, .age = age };
}
};
const TestFactory = struct {
name: []u8,
age: i32,
const Self = @This();
pub fn initWithFactory(age: i32, name: []u8) Self {
return TestFactory{ .name = name, .age = age };
}
pub fn format(self: *Self) []u8 {
return std.fmt.allocPrint(std.heap.page_allocator, "TestFactory {{ name = {s}, age = {d} }}", .{ self.name, self.age }) catch @panic("OOM");
}
};
pub const TestClass = napi.Class(Test);
pub const TestWithInitClass = napi.Class(TestWithInit);
pub const TestWithoutInitClass = napi.ClassWithoutInit(TestWithInit);
pub const TestFactoryClass = napi.Class(TestFactory);