summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--shell.nix2
-rw-r--r--zig-c-interop/Makefile2
-rw-r--r--zig-c-interop/billy.c3
-rw-r--r--zig-c-interop/billy.h1
-rw-r--r--zig-c-interop/main.zig9
5 files changed, 17 insertions, 0 deletions
diff --git a/shell.nix b/shell.nix
index ae3a692..ba1a6ce 100644
--- a/shell.nix
+++ b/shell.nix
@@ -5,5 +5,7 @@
gnumake
nasm
tinycc
+ zig
+ zls
];
}
diff --git a/zig-c-interop/Makefile b/zig-c-interop/Makefile
new file mode 100644
index 0000000..b0e2753
--- /dev/null
+++ b/zig-c-interop/Makefile
@@ -0,0 +1,2 @@
+default:
+ zig run -I. main.zig
diff --git a/zig-c-interop/billy.c b/zig-c-interop/billy.c
new file mode 100644
index 0000000..9544156
--- /dev/null
+++ b/zig-c-interop/billy.c
@@ -0,0 +1,3 @@
+#include "billy.h"
+
+int sum(int a, int b) { return a + b; };
diff --git a/zig-c-interop/billy.h b/zig-c-interop/billy.h
new file mode 100644
index 0000000..6142d6c
--- /dev/null
+++ b/zig-c-interop/billy.h
@@ -0,0 +1 @@
+int sum(int a, int b);
diff --git a/zig-c-interop/main.zig b/zig-c-interop/main.zig
new file mode 100644
index 0000000..8d16cd1
--- /dev/null
+++ b/zig-c-interop/main.zig
@@ -0,0 +1,9 @@
+const print = @import("std").debug.print;
+
+const billy = @cImport({
+ @cInclude("billy.c");
+});
+
+pub fn main() void {
+ print("Billy says 2+4={d}\n", .{billy.sum(2, 4)});
+}