Added embedding of files into compiled binary with Zig
| Author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2024-09-19 06:53:00 +0200 |
| Committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2024-09-19 06:53:00 +0200 |
| Commit | 1be35411cf23c1b8cc909c2f2e1d1030e2f5015a (patch) |
|
-rw-r--r-- |
README.md | 1 | |
-rw-r--r-- |
zig-embed/Makefile | 5 | |
-rw-r--r-- |
zig-embed/main.zig | 14 | |
-rw-r--r-- |
zig-embed/max.txt | 7 |
4 files changed, 27 insertions, 0 deletions
| diff --git a/README.md b/README.md | |||
| ... | |||
| 33 | | [zig-wad](./zig-wad) | zig-0.11.0 | Reads doom.wad and extracts the identification header. | |
33 | | [zig-wad](./zig-wad) | zig-0.11.0 | Reads doom.wad and extracts the identification header. | |
| 34 | | [zig-os-props](./zig-os-props) | zig-0.11.0 | Detects properties of the target operating system. | |
34 | | [zig-os-props](./zig-os-props) | zig-0.11.0 | Detects properties of the target operating system. | |
| 35 | | [zig-tlv-encoding](./zig-tlv-encoding) | zig-0.13.0 | Naive implementation of TLV encoding in Zig. | |
35 | | [zig-tlv-encoding](./zig-tlv-encoding) | zig-0.13.0 | Naive implementation of TLV encoding in Zig. | |
| 36 | | [zig-embed](./zig-embed) | zig-0.13.0 | Embedding external resources in compiled binary. | |
||
| 36 | 37 | ||
| 37 | ## License |
38 | ## License |
| 38 | 39 | ||
| ... | |||
| diff --git a/zig-embed/Makefile b/zig-embed/Makefile | |||
| 1 | default: |
||
| 2 | zig run main.zig |
||
| 3 | |||
| 4 | build: |
||
| 5 | zig build-exe main.zig |
||
| diff --git a/zig-embed/main.zig b/zig-embed/main.zig | |||
| 1 | const std = @import("std"); |
||
| 2 | |||
| 3 | pub fn main() !void { |
||
| 4 | const data: []const u8 = @embedFile("max.txt"); |
||
| 5 | |||
| 6 | // Print the whole file out. |
||
| 7 | std.debug.print("{s}\n", .{data}); |
||
| 8 | |||
| 9 | // Loop over each byte. |
||
| 10 | for (data) |c| { |
||
| 11 | std.debug.print("0x{X:0>2} ", .{c}); |
||
| 12 | } |
||
| 13 | std.debug.print("\n", .{}); |
||
| 14 | } |
||
| diff --git a/zig-embed/max.txt b/zig-embed/max.txt | |||
| 1 | "What you've just said is one of the most insanely idiotic things I |
||
| 2 | have ever heard. At no point in your rambling, incoherent response |
||
| 3 | were you even close to anything that could be considered a rational |
||
| 4 | thought. Everyone in this room is now dumber for having listened to |
||
| 5 | it." |
||
| 6 | |||
| 7 | — Josh Mostel as Principal Max Anderson in Billy Madison (1995) |
||