Skip to content

Commit 5ec2af8

Browse files
committed
Put builtins pxd stuff in src/godot/builtins_pxd/
1 parent f5a545b commit 5ec2af8

File tree

5 files changed

+65
-69
lines changed

5 files changed

+65
-69
lines changed

src/godot/builtins.pxd.j2

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{%- from 'builtins.macros.pxd.j2' import render_method, render_member -%}
1+
{% from 'builtins_pxd/class.pxd.j2' import render_class with context %}
22
cimport cython
33

44
cdef extern from "Python.h":
@@ -30,26 +30,5 @@ cdef inline NodePath ensure_is_nodepath(object nodepath_or_pystr):
3030
raise TypeError(f"Invalid value {nodepath_or_pystr!r}, must be str or NodePath")
3131
{% for spec in api["builtins"] if not spec.is_scalar %}
3232

33-
34-
@cython.freelist(8)
35-
@cython.final
36-
cdef class {{ spec.name }}:
37-
cdef {{ spec.c_struct_name }} _gd_data
38-
39-
@staticmethod
40-
cdef inline {{ spec.name }} new():
41-
# Call to __new__ bypasses __init__ constructor
42-
cdef {{ spec.name }} ret = {{ spec.name }}.__new__({{ spec.name }})
43-
__{{ spec.name }}_constructor_0(&ret._gd_data, NULL)
44-
return ret
45-
{% if spec.name == "GDString" %}
46-
cdef inline gd_string_t to_pystr(self):
47-
return gdstring_to_pystr(&self._gd_data)
48-
{% endif %}
49-
{% for m in spec.members %}
50-
{{ render_member(spec, m) | indent }}
51-
{% endfor %}
52-
{% for m in spec.methods %}
53-
{{ render_method(spec, m) | indent }}
54-
{% endfor %}
33+
{{ render_class(spec) }}
5534
{% endfor %}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{% from 'builtins_pxd/method.pxd.j2' import render_method with context %}
2+
{% from 'builtins_pxd/member.pxd.j2' import render_member with context %}
3+
4+
5+
{% macro render_class(spec, m) %}
6+
@cython.freelist(8)
7+
@cython.final
8+
cdef class {{ spec.name }}:
9+
cdef {{ spec.c_struct_name }} _gd_data
10+
11+
@staticmethod
12+
cdef inline {{ spec.name }} new():
13+
# Call to __new__ bypasses __init__ constructor
14+
cdef {{ spec.name }} ret = {{ spec.name }}.__new__({{ spec.name }})
15+
__{{ spec.name }}_constructor_0(&ret._gd_data, NULL)
16+
return ret
17+
{% if spec.name == "GDString" %}
18+
cdef inline gd_string_t to_pystr(self):
19+
return gdstring_to_pystr(&self._gd_data)
20+
{% endif %}
21+
{% for m in spec.members %}
22+
{{ render_member(spec, m) | indent }}
23+
{% endfor %}
24+
{% for m in spec.methods %}
25+
{{ render_method(spec, m) | indent }}
26+
{% endfor %}
27+
{% endmacro %}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{% macro render_member_getter_signature(spec, m) -%}
2+
{{ m.type.cy_type }} get_{{ m.name }}(self)
3+
{%- endmacro %}
4+
5+
6+
{% macro render_member_setter_signature(spec, m) -%}
7+
void set_{{ m.name }}(self, {{ m.type.cy_type }} val)
8+
{%- endmacro %}
9+
10+
11+
{% macro render_member(spec, m) %}
12+
{% if not m.is_in_struct %}
13+
{# Property unrelated to the builtin internal structure, must use Godot API method to access it #}
14+
{% if m.type.is_scalar %}
15+
{# Scalar type accessed by property (unused in extension_api.json afaik) #}
16+
cdef inline {{ render_member_getter_signature(spec, m) }}:
17+
cdef {{ m.type.c_type }} ret
18+
__{{ spec.name }}_get_{{ m.name }}(&self._gd_data, &ret)
19+
return ret
20+
cdef inline {{ render_member_setter_signature(spec,m )}}:
21+
__{{ spec.name }}_set_{{ m.name }}(&self._gd_data, &val)
22+
{% else %}
23+
{# Builtin type in the C structure (i.e. `Rect2i.end`) #}
24+
cdef inline {{ render_member_getter_signature(spec, m) }}:
25+
# Call to __new__ bypasses __init__ constructor
26+
cdef {{ m.type.cy_type }} ret = {{ m.type.cy_type }}.__new__({{ m.type.cy_type }})
27+
__{{ spec.name }}_get_{{ m.name }}(&self._gd_data, &ret._gd_data)
28+
return ret
29+
cdef inline {{ render_member_setter_signature(spec,m )}}:
30+
__{{ spec.name }}_set_{{ m.name }}(&self._gd_data, &val._gd_data)
31+
{% endif %}
32+
{% endif %}
33+
{% endmacro %}

src/godot/builtins.macros.pxd.j2 renamed to src/godot/builtins_pxd/method.pxd.j2

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
#########################################################################
2-
# Render method
3-
#########################################################################
4-
5-
61
{% macro render_method_signature(spec, m) -%}
72
{{ "void" if m.return_type.is_nil else m.return_type.cy_type }} {{ m.name }}(self
83
{%- for arg in m.arguments -%}
@@ -58,43 +53,3 @@ cpdef inline {{ render_method_signature(spec, m) }}:
5853
{% endif %}
5954
{% endif %}
6055
{% endmacro %}
61-
62-
63-
#########################################################################
64-
# Render member
65-
#########################################################################
66-
67-
68-
{% macro render_member_getter_signature(spec, m) -%}
69-
{{ m.type.cy_type }} get_{{ m.name }}(self)
70-
{%- endmacro %}
71-
72-
73-
{% macro render_member_setter_signature(spec, m) -%}
74-
void set_{{ m.name }}(self, {{ m.type.cy_type }} val)
75-
{%- endmacro %}
76-
77-
78-
{% macro render_member(spec, m) %}
79-
{% if not m.is_in_struct %}
80-
{# Property unrelated to the builtin internal structure, must use Godot API method to access it #}
81-
{% if m.type.is_scalar %}
82-
{# Scalar type accessed by property (unused in extension_api.json afaik) #}
83-
cdef inline {{ render_member_getter_signature(spec, m) }}:
84-
cdef {{ m.type.c_type }} ret
85-
__{{ spec.name }}_get_{{ m.name }}(&self._gd_data, &ret)
86-
return ret
87-
cdef inline {{ render_member_setter_signature(spec,m )}}:
88-
__{{ spec.name }}_set_{{ m.name }}(&self._gd_data, &val)
89-
{% else %}
90-
{# Builtin type in the C structure (i.e. `Rect2i.end`) #}
91-
cdef inline {{ render_member_getter_signature(spec, m) }}:
92-
# Call to __new__ bypasses __init__ constructor
93-
cdef {{ m.type.cy_type }} ret = {{ m.type.cy_type }}.__new__({{ m.type.cy_type }})
94-
__{{ spec.name }}_get_{{ m.name }}(&self._gd_data, &ret._gd_data)
95-
return ret
96-
cdef inline {{ render_member_setter_signature(spec,m )}}:
97-
__{{ spec.name }}_set_{{ m.name }}(&self._gd_data, &val._gd_data)
98-
{% endif %}
99-
{% endif %}
100-
{% endmacro %}

src/meson.build

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ pxd_godot_builtins = custom_target(
9191
generate_tmpl_base_input,
9292
files(
9393
'godot/builtins.pxd.j2',
94-
'godot/builtins.macros.pxd.j2',
94+
'godot/builtins_pxd/class.pxd.j2',
95+
'godot/builtins_pxd/member.pxd.j2',
96+
'godot/builtins_pxd/method.pxd.j2',
9597
),
9698
],
9799
command: generate_tmpl_cmd,

0 commit comments

Comments
 (0)