diff --git a/README.md b/README.md index b4a1632855b19552a4b731a424ed0b0d37bdc249..fe1b93103a56cdd0abf7fcbe63958af8229c7da5 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ | [zig-kv-store](./zig-kv-store) | zig-0.11.0 | Simple Key-value store that mimics memcached written in Zig. | | [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 0000000000000000000000000000000000000000..d78c528fb312a68c8476c4e4a15639662bb0bc9f --- /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 0000000000000000000000000000000000000000..a1089b95c168759a10afce509761f24a2b06c19d --- /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 0000000000000000000000000000000000000000..5eedd45a7ea9b36598ed4ad332a88d6d2e5d5520 --- /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)