Skip to content

Commit 97713c6

Browse files
committed
Wip load_class
1 parent 9a8429c commit 97713c6

File tree

2 files changed

+54
-21
lines changed

2 files changed

+54
-21
lines changed

src/godot/builtins_pxd/method.pxd.j2

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,44 +12,61 @@ cpdef inline {{ render_method_signature(spec, m) }}:
1212
raise NotImplementedError # TODO
1313
{% else %}
1414
{# Return type #}
15-
{% if m.return_type.is_nil %}
16-
{% elif m.return_type.is_scalar %}
15+
{% if m.return_type.is_nil %}
16+
{% elif m.return_type.is_scalar %}
1717
cdef {{ m.return_type.cy_type }} ret = 0
18-
{% elif m.return_type.is_builtin %}
18+
{% elif m.return_type.is_builtin %}
1919
# Call to __new__ bypasses __init__ constructor
2020
cdef {{ m.return_type.cy_type }} ret = {{ m.return_type.cy_type }}.__new__({{ m.return_type.cy_type }})
21-
{% endif %}
21+
{% elif m.return_type.is_object or m.return_type.is_variant %}
22+
cdef {{ m.return_type.c_type }} ret
23+
{% else %}
24+
<crash !!!!> # {{ m.return_type }} Unsupported type, crash the compilation !
25+
{% endif %}
2226
{# Arguments #}
23-
{% if (m.arguments | length) != 0 %}
27+
{% if (m.arguments | length) != 0 %}
2428
cdef GDNativeTypePtr[{{ m.arguments | length }}] args = [
25-
{% for arg in m.arguments %}
26-
{% if arg.type.is_scalar %}
29+
{% for arg in m.arguments %}
30+
{% if arg.type.is_scalar %}
2731
&{{ arg.name }},
28-
{% else %}
32+
{% elif arg.type.is_builtin %}
2933
&{{ arg.name }}._gd_data,
30-
{% endif %}
31-
{% endfor %}
34+
{% elif arg.type.is_object %}
35+
&{{ arg.name }}._gd_ptr,
36+
{% else %}
37+
<crash !!!!> # {{ arg.type }} Unsupported type, crash the compilation !
38+
{% endif %}
39+
{% endfor %}
3240
]
33-
{% endif %}
41+
{% endif %}
3442
{# Actual call ! #}
3543
__{{ spec.name }}_meth_{{ m.name }}(
3644
{# GDNativeTypePtr p_base #}
3745
&self._gd_data,
3846
{# const GDNativeTypePtr *p_args #}
3947
{{ "NULL" if (m.arguments | length) == 0 else "args" }},
4048
{# GDNativeTypePtr r_return #}
41-
{% if m.return_type.is_nil %}
49+
{% if m.return_type.is_nil %}
4250
NULL,
43-
{% elif m.return_type.is_scalar %}
51+
{% elif m.return_type.is_scalar %}
4452
&ret,
45-
{% elif m.return_type.is_builtin %}
53+
{% elif m.return_type.is_builtin %}
4654
&ret._gd_data,
47-
{% endif %}
55+
{% endif %}
4856
{# int p_argument_count #}
4957
{{ m.arguments | length }},
5058
)
51-
{% if not m.return_type.is_nil %}
59+
{% if not m.return_type.is_nil %}
60+
{% if m.return_type.is_object %}
61+
return GDObject.cast_from_variant(ret)
62+
{% elif m.return_type.is_variant %}
63+
try:
64+
return gdvariant_to_pyobject(&ret)
65+
finally:
66+
gd_variant_del(&ret)
67+
{% else %}
5268
return ret
53-
{% endif %}
69+
{% endif %}
70+
{% endif %}
5471
{% endif %}
5572
{% endmacro %}

src/godot/classes.pyx.j2

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,26 @@ cdef _load_singleton(name):
4545
cdef object _load_class(str name):
4646
# Load our good friend ClassDB
4747
cdef GDNativeObjectPtr classdb = pythonscript_gdapi.global_get_singleton("ClassDB")
48-
pythonscript_gdapi.print_error("AAAAAAAAAA", "_object_call", "", 0)
49-
cdef gd_variant_t meths = _object_call(classdb, "class_get_method_list", [name])
50-
pythonscript_gdapi.print_error("BBBB", "_object_call", "", 0)
51-
pythonscript_gdapi.print_error("GOOOOOOOOOOOOOOOD", "_object_call", "", 0)
48+
49+
if not _object_call(classdb, "class_exists", [name]):
50+
raise RuntimeError(f"Class `{name}` doesn't exist in Godot !")
51+
52+
parent = _object_call(classdb, "get_parent_class", [name])
53+
if parent:
54+
parent_cls = _load_class(parent)
55+
bases = (parent_cls, )
56+
else:
57+
bases = ()
58+
59+
meths = _object_call(classdb, "class_get_method_list", [name])
60+
properties = _object_call(classdb, "class_get_property_list", [name])
61+
signals = _object_call(classdb, "class_get_signal_list", [name])
62+
63+
# TODO
64+
65+
attrs = {}
66+
67+
return type(name, bases, attrs)
5268

5369

5470
cdef object _object_call(GDNativeObjectPtr obj, str meth, args):

0 commit comments

Comments
 (0)