alef 0.36.2

Opinionated polyglot binding generator for Rust libraries
Documentation
{% if is_string_like -%}
                    // String-like return type ([*c]const u8): already a C string pointer.
                    // Use directly without JSON formatting (zig 0.16 stringify can't handle [*c]const u8).
                    if (out_result) |ptr| ptr.* = @constCast({{ ok_binding }});
                    return 0;
{% else -%}
                    // Complex return type: serialize the host value to JSON and hand back a
                    // NUL-terminated C string. The caller owns the returned pointer and must
                    // free it via the C API.
                    const _json_slice = std.fmt.allocPrint(std.heap.c_allocator, "{f}", .{ std.json.fmt({{ ok_binding }}, .{}) }) catch {
                        if (out_error) |ptr| ptr.* = null;
                        return 1;
                    };
                    defer std.heap.c_allocator.free(_json_slice);
                    const _json_cstr = std.heap.c_allocator.dupeZ(u8, _json_slice) catch {
                        if (out_error) |ptr| ptr.* = null;
                        return 1;
                    };
                    if (out_result) |ptr| ptr.* = @ptrCast(_json_cstr.ptr);
                    return 0;
{% endif -%}