summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md1
-rw-r--r--zig-embed/Makefile5
-rw-r--r--zig-embed/main.zig14
-rw-r--r--zig-embed/max.txt7
4 files changed, 27 insertions, 0 deletions
diff --git a/README.md b/README.md
index b4a1632..fe1b931 100644
--- a/README.md
+++ b/README.md
@@ -33,6 +33,7 @@ running it.
| [zig-wad](./zig-wad) | zig-0.11.0 | Reads doom.wad and extracts the identification header. |
| [zig-os-props](./zig-os-props) | zig-0.11.0 | Detects properties of the target operating system. |
| [zig-tlv-encoding](./zig-tlv-encoding) | zig-0.13.0 | Naive implementation of TLV encoding in Zig. |
+| [zig-embed](./zig-embed) | zig-0.13.0 | Embedding external resources in compiled binary. |
## License
diff --git a/zig-embed/Makefile b/zig-embed/Makefile
new file mode 100644
index 0000000..d78c528
--- /dev/null
+++ b/zig-embed/Makefile
@@ -0,0 +1,5 @@
+default:
+ zig run main.zig
+
+build:
+ zig build-exe main.zig
diff --git a/zig-embed/main.zig b/zig-embed/main.zig
new file mode 100644
index 0000000..a1089b9
--- /dev/null
+++ b/zig-embed/main.zig
@@ -0,0 +1,14 @@
+const std = @import("std");
+
+pub fn main() !void {
+ const data: []const u8 = @embedFile("max.txt");
+
+ // Print the whole file out.
+ std.debug.print("{s}\n", .{data});
+
+ // Loop over each byte.
+ for (data) |c| {
+ std.debug.print("0x{X:0>2} ", .{c});
+ }
+ std.debug.print("\n", .{});
+}
diff --git a/zig-embed/max.txt b/zig-embed/max.txt
new file mode 100644
index 0000000..5eedd45
--- /dev/null
+++ b/zig-embed/max.txt
@@ -0,0 +1,7 @@
+"What you've just said is one of the most insanely idiotic things I
+have ever heard. At no point in your rambling, incoherent response
+were you even close to anything that could be considered a rational
+thought. Everyone in this room is now dumber for having listened to
+it."
+
+— Josh Mostel as Principal Max Anderson in Billy Madison (1995)