1+ {%- from ' _builtins_pyx/constructor.tmpl.pxi' import render_constructor -% }
2+ {%- from ' _builtins_pyx/gdapi.tmpl.pxi' import render_gdapi -% }
3+
14{% macro render_spec(spec) -% }
25
3- {% for c in spec.constructors % }
4- cdef GDNativePtrConstructor __{{ spec.name }}_constructor_{{ c.index }} = gdapi.variant_get_ptr_constructor(
5- {{ spec.variant_type_name }}, {{ c.index }}
6- )
7- {% endfor % }
8- {% if spec.has_destructor % }
9- cdef GDNativePtrDestructor __{{ spec.name }}_destructor = gdapi.variant_get_ptr_destructor(
10- {{ spec.variant_type_name }}
11- )
12- {% endif % }
6+ {{ render_gdapi(spec) }}
137
8+ @ cython.freelist (8 )
149@cython.final
1510cdef class {{ spec.name }}:
1611{# TODO: I guess only Nil has no size, so remove it and only use None ? #}
1712{% if spec.size % }
18- cdef char _gd_data[{{ spec.size }}]
19-
2013 # Constructors
21- def __init__ ({{ spec.name }} self ):
22- __{{ spec.name }}_constructor_0(self ._gd_data, NULL )
14+ {{ render_constructor(spec) | indent }}
2315
2416 @staticmethod
2517 cdef inline {{ spec.name }} new():
@@ -32,7 +24,7 @@ cdef class {{ spec.name }}:
3224{% if spec.has_destructor % }
3325 # Destructor
3426 def __dealloc__ ({{ spec.name }} self ):
35- # /!\ if `__init__ ` is skipped, `_gd_data` must be initialized by
27+ # /!\ if `__cinit__ ` is skipped, `_gd_data` must be initialized by
3628 # hand otherwise we will get a segfault here
3729 __{{ spec.name }}_destructor(self ._gd_data)
3830{% else % }
@@ -49,12 +41,41 @@ cdef class {{ spec.name }}:
4941
5042{% endif % }
5143{% for c in spec.constants % }
52- {{ c.name }} = {{ c.value }}
44+ # {{ c.name }} = {{ c.value }}
45+ {% endfor % }
46+
47+ {% if spec.members % }
48+ # Members
49+ {% endif % }
50+ {% for m in spec.members % }
51+ @property
52+ def {{ m.name }}(self ) - > {{ m.type.py_type }}:
53+ {% if m.offset is not none % }
54+ {% if m.type.is_scalar % }
55+ return (< {{ m.type.c_type }}* > self ._gd_data)[{{ m.offset }}]
56+ {# TODO: ensure m.type doesn't need a destructor #}
57+ {% else % }
58+ {# TODO: Find a way to avoid this copy ? #}
59+ cdef {{ m.type.py_type }} ret = {{ m.type.py_type }}.__new__() # Skips __init__()
60+ ret._gd_data = self ._gd_data
61+ return ret
62+ {% endif % }
63+ @{{ m.name }}.setter
64+ def {{ m.name }}(self , {{ m.type.py_type }} value) - > None :
65+ {% if m.type.is_scalar % }
66+ (< {{ m.type.c_type }}* > self ._gd_data)[{{ m.offset }}] = value
67+ {# TODO: ensure m.type doesn't need a destructor #}
68+ {% else % }
69+ self ._gd_data = value._gd_data
70+ {% endif % }
71+ {% else % }
72+ # TODO: support properties !
73+ raise NotImplementedError
74+ {% endif % }
5375{% endfor % }
5476
5577{% if spec.methods % }
5678 # Methods
57-
5879{% endif % }
5980{% for m in spec.methods % }
6081 def {{ m.name }}(
@@ -75,7 +96,7 @@ cdef class {{ spec.name }}:
7596{% if m.arguments | length == 0 % }
7697# {% if m.return_type %}
7798# # TODO
78- # # cdef {{ m.return_type.cython_name }} ret = {{ m.return_type.cython_name }}.__new__()
99+ # # cdef {{ m.return_type.cy_type }} ret = {{ m.return_type.cy_type }}.__new__()
79100# {% set retval_as_arg = "NULL" %}
80101# {% else %}
81102# {% set retval_as_arg = "NULL" %}
0 commit comments