@@ -42,6 +42,14 @@ For each builtin python type `py.zig` defines an equivalent `extern struct` that
4242single field ` impl ` with the underlying python type. For examle a tuple is defined as:
4343
4444``` zig
45+ // c-import Python.h
46+ pub const c = @cImport({
47+ @cDefine("PY_SSIZE_T_CLEAN", "1");
48+ @cInclude("Python.h");
49+ });
50+
51+ // ...
52+
4553pub const Tuple = extern struct {
4654 pub const BaseType = c.PyTupleObject;
4755
@@ -58,21 +66,32 @@ pub const Tuple = extern struct {
5866};
5967```
6068
61- Since these types have the same datastructure as the c-equivalent you can safetly use ` @ptrCast `
62- to any C-API functions that take a tuple object.
69+ Since these types have the same memory representation as the c-equivalent you can safetly use ` @ptrCast `
70+ and pass them to any functions (C/C++, or whatever) that take a tuple object.
6371
6472You can also access any members of the python type using ` impl ` , directly. For example the ` Type `
65- impl can get the name like this:
73+ can get the name like this:
6674
6775``` zig
68- // Return the name of this type as a [:0]const u8
76+ pub const Type = extern struct {
77+ pub const BaseType = c.PyTypeObject;
78+
79+ // The underlying python structure
80+ impl: BaseType,
81+
82+ // ...
83+
84+ // Return the name of this type
6985 pub inline fn className(self: *Type) [:0]const u8 {
7086 return std.mem.span(self.impl.tp_name);
7187 }
88+ };
7289```
7390
74- However it is generally recommended to use public C-API functions.
91+ However it is generally recommended to use public C-API functions as is done with the wrappers in ` py.zig ` .
92+
7593
7694## Status
7795
78- This is very alpha and largely untested.
96+ This is currently very alpha status and is undergoing breaking changes to functions but the
97+ basic design concept is unlikely to change.
0 commit comments