diff --git a/build.zig.zon b/build.zig.zon index 8fa6418..a3e574a 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,6 +1,6 @@ .{ .name = "zap", - .version = "0.0.5", + .version = "0.0.6", .dependencies = .{ .@"facil.io" = .{ diff --git a/src/mustache.zig b/src/mustache.zig index 703ec66..49b9624 100644 --- a/src/mustache.zig +++ b/src/mustache.zig @@ -79,8 +79,12 @@ pub fn MustacheNew(data: []const u8) MustacheError!*Mustache { const MustacheBuildResult = struct { fiobj_result: fio.FIOBJ = 0, + /// holds the context converted into a fiobj, used in build + fiobj_context: fio.FIOBJ = 0, + pub fn deinit(m: *const MustacheBuildResult) void { fio.fiobj_free_wrapped(m.fiobj_result); + fio.fiobj_free_wrapped(m.fiobj_context); } pub fn str(m: *const MustacheBuildResult) ?[]const u8 { @@ -96,9 +100,11 @@ pub fn MustacheBuild(mustache: *Mustache, data: anytype) MustacheBuildResult { @compileError("No struct: '" ++ @typeName(T) ++ "'"); } - const fiobj_data = fiobjectify(data); + var result: MustacheBuildResult = .{}; - return .{ .fiobj_result = fiobj_mustache_build(mustache, fiobj_data) }; + result.fiobj_context = fiobjectify(data); + result.fiobj_result = fiobj_mustache_build(mustache, result.fiobj_context); + return result; } pub fn fiobjectify(