Skip to content

Adding support for parsing classes from extension_api.json #356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: godot4-meson
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions scripts/generate_builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ def correct_name(name: str) -> str:
return name


def patch_name(name: str) -> str:
return "GD" + name[0].upper() + name[1:]


# `extension_api.json` is pretty big, hence it's much easier to have it
# format reproduced here as typed classes, especially given we want to cook
# it a bit before using it in the templates
Expand Down Expand Up @@ -131,8 +135,13 @@ class BuiltinType:
@classmethod
def parse(cls, name: str) -> "BuiltinType":
godot_name, cython_name = BUILTINS_NAMES.get(name, (name, name))
# Avoid overwritting default Python types
if name in ("bool", "int", "float", "String"):
patched_name = patch_name(name=name)
else:
patched_name = name
return cls(
name=name,
name=patched_name,
original_name=name,
cython_name=cython_name,
godot_name=godot_name,
Expand Down Expand Up @@ -323,7 +332,7 @@ def parse(cls, item: dict) -> "BuiltinSpec":

# Avoid overwritting default Python types
if item["name"] in ("bool", "int", "float", "String"):
patched_name = "GD" + item["name"][0].upper() + item["name"][1:]
patched_name = patch_name(name=item["name"])
else:
patched_name = item["name"]

Expand Down
3 changes: 3 additions & 0 deletions src/godot/_builtins.tmpl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# see `generation/generate_builtins.py`

{# TODO: GDString ~ String #}
class Object:
...

{% for item in specs %}

class {{item.name}}:
Expand Down