summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--example-container/.gitignore2
-rw-r--r--example-container/Makefile3
-rw-r--r--example-container/Object.zig20
-rw-r--r--example-container/main.zig21
4 files changed, 46 insertions, 0 deletions
diff --git a/example-container/.gitignore b/example-container/.gitignore
new file mode 100644
index 0000000..a63bec8
--- /dev/null
+++ b/example-container/.gitignore
@@ -0,0 +1,2 @@
+main.o
+main
diff --git a/example-container/Makefile b/example-container/Makefile
new file mode 100644
index 0000000..89a77b1
--- /dev/null
+++ b/example-container/Makefile
@@ -0,0 +1,3 @@
+run:
+ zig build-exe main.zig
+ ./main
diff --git a/example-container/Object.zig b/example-container/Object.zig
new file mode 100644
index 0000000..22bc7a8
--- /dev/null
+++ b/example-container/Object.zig
@@ -0,0 +1,20 @@
+// File name starting with capital letters indicate a type definition.
+
+// Alias for this type.
+const Self = @This();
+
+// Struct fields.
+id: i32,
+op: u32 = 42,
+
+// Public static method, creating an Object.
+pub fn init(v: i32) Self {
+ return Self{ .id = v };
+}
+
+// Public member function.
+pub fn dump(self: Self) void {
+ const print = @import("std").debug.print;
+ print("Self = {s}\n", .{@typeName(Self)});
+ print("ID = {} OP = {}\n", .{ self.id, self.op });
+}
diff --git a/example-container/main.zig b/example-container/main.zig
new file mode 100644
index 0000000..9020adb
--- /dev/null
+++ b/example-container/main.zig
@@ -0,0 +1,21 @@
+const Object = @import("Object.zig");
+
+const Moose = struct {
+ foo: i32,
+
+ fn dump(self: Moose) void {
+ const print = @import("std").debug.print;
+ print("Self = {s}\n", .{@typeName(Moose)});
+ print("FOO = {}\n", .{self.foo});
+ }
+};
+
+pub fn main() void {
+ const o12 = Object.init(12);
+ const o13 = Object.init(13);
+ o12.dump();
+ o13.dump();
+
+ const m = Moose{ .foo = 42 };
+ m.dump();
+}