Skip to content

Commit b226e57

Browse files
committed
added hello world
1 parent 1374dcb commit b226e57

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

hello-world.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from cffi import FFI
2+
3+
cffi = FFI()
4+
cffi.cdef(
5+
"""
6+
void print(char* x);
7+
"""
8+
)
9+
10+
import os
11+
12+
helloWorld = cffi.dlopen(os.path.abspath("hello-world.dll"))
13+
14+
# pass in null-terminated array
15+
helloWorld.print(b"Hello world\x00")

hello-world.zig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const std = @import("std");
2+
3+
// messageZ must be null-terminated
4+
export fn print(messageZ: [*]u8) void {
5+
// [*:0]u8 is not allowed by C ABI, cast to right type
6+
const message = @ptrCast([*:0]u8, messageZ);
7+
8+
std.debug.print("{s}", .{message});
9+
}

0 commit comments

Comments
 (0)