Skip to content

Commit 649c045

Browse files
committed
Put builtins pyx stuff in src/godot/builtins_pyx/
1 parent 483788b commit 649c045

File tree

7 files changed

+85
-97
lines changed

7 files changed

+85
-97
lines changed

src/godot/builtins.pxd.j2

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
{% from 'builtins_pxd/class.pxd.j2' import render_class with context %}
1+
{% from 'builtins_pxd/class.pxd.j2' import render_class, render_class_resume with context %}
2+
{% for spec in api["builtins"] if not spec.is_scalar %}
3+
#
4+
#
5+
{{ render_class_resume(spec) }}
6+
{% endfor %}
7+
8+
29
cimport cython
310

411
cdef extern from "Python.h":

src/godot/builtins.pyx.j2

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
{%- from 'builtins_pyx/class.pxi.j2' import render_spec with context -%}
2-
# /!\ Autogenerated code, modifications will be lost /!\
3-
# see `scripts/generate_tmpl.py`
4-
1+
{%- from 'builtins_pyx/class.pyx.j2' import render_class with context -%}
52
cimport cython
63
from libc.math cimport INFINITY as inf # Needed by some constants
74

@@ -10,5 +7,5 @@ from .hazmat.gdapi cimport *
107

118

129
{% for spec in api["builtins"] if not spec.is_scalar -%}
13-
{{ render_spec(spec) }}
10+
{{ render_class(spec) }}
1411
{% endfor %}

src/godot/builtins_pxd/class.pxd.j2

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1-
{% from 'builtins_pxd/method.pxd.j2' import render_method with context %}
2-
{% from 'builtins_pxd/member.pxd.j2' import render_member with context %}
1+
{% from 'builtins_pxd/method.pxd.j2' import render_method, render_method_signature with context %}
2+
{% from 'builtins_pxd/member.pxd.j2' import
3+
render_member,
4+
render_member_getter_signature,
5+
render_member_setter_signature
6+
with context %}
7+
8+
{% macro render_class_resume(spec) %}
9+
# cdef class {{ spec.name }}:
10+
{% for m in spec.members %}
11+
# {{ render_member_getter_signature(spec, m) }}
12+
# {{ render_member_setter_signature(spec, m) }}
13+
{% endfor %}
14+
{% for m in spec.methods %}
15+
# {{ render_method_signature(spec, m) }}
16+
{% endfor %}
17+
{% endmacro %}
318

419

520
{% macro render_class(spec, m) %}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{%- from 'builtins_pyx/constructor.pyx.j2' import render_constructors with context -%}
2+
{%- from 'builtins_pyx/member.pyx.j2' import render_member with context -%}
3+
4+
5+
{% macro render_constant(spec, c) %}
6+
{% if c.type.is_scalar %}
7+
{{ c.name }} = {{ c.value }}
8+
{% else %}
9+
@property
10+
def {{ c.name }}(self):
11+
return {{ c.value }}
12+
{% endif %}
13+
{% endmacro %}
14+
15+
16+
{% macro render_class(spec) -%}
17+
18+
@cython.freelist(8)
19+
@cython.final
20+
cdef class {{ spec.name }}:
21+
# Constructors
22+
{{ render_constructors(spec) | indent }}
23+
24+
{% if spec.has_destructor %}
25+
# Destructor
26+
def __dealloc__({{ spec.name }} self):
27+
# /!\ if `__cinit__` is skipped, `_gd_data` must be initialized by
28+
# hand otherwise we will get a segfault here
29+
__{{ spec.name }}_destructor(&self._gd_data)
30+
{% endif %}
31+
32+
def __repr__(self):
33+
# TODO: finish me...
34+
# pythonscript_gdapi.variant_stringify(&self._gd_data)
35+
return "<{{ spec.name }}>"
36+
{% if spec.name == "GDString" %}
37+
def __str__(self):
38+
self.to_pystr()
39+
{% endif %}
40+
{% if spec.constants %}
41+
# Constants
42+
43+
{% endif %}
44+
{% for c in spec.constants %}
45+
{{ render_constant(spec, c) | indent }}
46+
{% endfor %}
47+
48+
{% if spec.members %}
49+
# Members
50+
51+
{% endif %}
52+
{% for m in spec.members %}
53+
{{ render_member(spec, m) | indent }}
54+
{% endfor %}
55+
{%- endmacro %}
Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,3 @@
1-
{%- from 'builtins_pyx/constructor.pxi.j2' import render_constructors with context -%}
2-
3-
4-
{#########################################################################
5-
# Render constant
6-
#########################################################################}
7-
8-
9-
{% macro render_constant(spec, c) %}
10-
{% if c.type.is_scalar %}
11-
{{ c.name }} = {{ c.value }}
12-
{% else %}
13-
@property
14-
def {{ c.name }}(self):
15-
return {{ c.value }}
16-
{% endif %}
17-
{% endmacro %}
18-
19-
20-
{#########################################################################
21-
# Render transparent builtin scalar property
22-
#########################################################################}
23-
24-
251
{% macro render_transparent_builtin_scalar_property(m, name_prefix, access_prefix) -%}
262
@property
273
def {{ name_prefix }}{{ m.name }}(self):
@@ -32,11 +8,6 @@ def {{ name_prefix }}{{ m.name }}(self, {{ m.type.cy_type }} val):
328
{% endmacro %}
339

3410

35-
{#########################################################################
36-
# Render transparent builtin subtype properties
37-
#########################################################################}
38-
39-
4011
{% macro render_transparent_builtin_subtype_properties(m, name_prefix, access_prefix) -%}
4112
{% for subm in m.type.builtin_spec.c_struct_members %}
4213
{% if subm.is_in_struct %}
@@ -50,11 +21,6 @@ def {{ name_prefix }}{{ m.name }}(self, {{ m.type.cy_type }} val):
5021
{% endmacro %}
5122

5223

53-
{#########################################################################
54-
# Render member
55-
#########################################################################}
56-
57-
5824
{% macro render_member(spec, m) %}
5925
{% if not m.is_in_struct %}
6026
{# Property unrelated to the builtin internal structure, must use Godot API method to access it #}
@@ -97,56 +63,3 @@ def set_{{ m.name }}(self, {{ m.type.cy_type }} val not None):
9763
{% endif %}
9864
{% endif %}
9965
{% endmacro %}
100-
101-
102-
{#########################################################################
103-
# Render full class spec
104-
#########################################################################}
105-
106-
{% macro render_spec(spec) -%}
107-
108-
@cython.freelist(8)
109-
@cython.final
110-
cdef class {{ spec.name }}:
111-
# Constructors
112-
{{ render_constructors(spec) | indent }}
113-
114-
{% if spec.has_destructor %}
115-
# Destructor
116-
def __dealloc__({{ spec.name }} self):
117-
# /!\ if `__cinit__` is skipped, `_gd_data` must be initialized by
118-
# hand otherwise we will get a segfault here
119-
__{{ spec.name }}_destructor(&self._gd_data)
120-
{% else %}
121-
# Destructor not needed
122-
{% endif %}
123-
124-
def __repr__(self):
125-
# TODO: finish me...
126-
# pythonscript_gdapi.variant_stringify(&self._gd_data)
127-
return "<{{ spec.name }}>"
128-
{% if spec.name == "GDString" %}
129-
def __str__(self):
130-
self.to_pystr()
131-
{% endif %}
132-
{% if spec.constants %}
133-
# Constants
134-
135-
{% endif %}
136-
{% for c in spec.constants %}
137-
{{ render_constant(spec, c) | indent }}
138-
{% endfor %}
139-
140-
{% if spec.members %}
141-
# Members
142-
143-
{% endif %}
144-
{% for m in spec.members %}
145-
{{ render_member(spec, m) | indent }}
146-
{% endfor %}
147-
148-
{% if spec.methods %}
149-
# Methods
150-
151-
{% endif %}
152-
{%- endmacro %}

src/godot/meson.build

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ pyxbuiltins = custom_target(
8888
generate_tmpl_base_input,
8989
files(
9090
'builtins.pyx.j2',
91-
'builtins_pyx/class.pxi.j2',
92-
'builtins_pyx/constructor.pxi.j2',
91+
'builtins_pyx/class.pyx.j2',
92+
'builtins_pyx/constructor.pyx.j2',
93+
'builtins_pyx/member.pyx.j2',
9394
),
9495
],
9596
command: generate_tmpl_cmd,

0 commit comments

Comments
 (0)