Skip to content

Instantly share code, notes, and snippets.

View FedericoStra's full-sized avatar

Federico Stra FedericoStra

  • Politecnico di Torino
  • Torino, Italy
View GitHub Profile
@adrusi
adrusi / closure.zig
Created June 15, 2020 19:04
Userland implementation of closures in Zig
const std = @import("std");
const assert = std.debug.assert;
pub fn closure(bindings: var) ClosureInternal(@TypeOf(bindings)) {
return ClosureInternal(@TypeOf(bindings)) { .ctx = bindings };
}
fn ClosureInternal(comptime Spec: type) type {
comptime {
const spec_tinfo = @typeInfo(Spec);