Skip to content

Commit

Permalink
Merge pull request #870 from bruvzg/ts_wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga authored Sep 28, 2022
2 parents e40aa11 + fb8253c commit e51df84
Show file tree
Hide file tree
Showing 2 changed files with 433 additions and 187 deletions.
72 changes: 72 additions & 0 deletions binding_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,83 @@
from pathlib import Path


def generate_mod_version(argcount, const=False, returns=False):
s = """
#define MODBIND$VER($RETTYPE m_name$ARG) \\
virtual $RETVAL _##m_name($FUNCARGS) $CONST override; \\
"""
sproto = str(argcount)
method_info = ""
if returns:
sproto += "R"
s = s.replace("$RETTYPE", "m_ret, ")
s = s.replace("$RETVAL", "m_ret")

else:
s = s.replace("$RETTYPE", "")
s = s.replace("$RETVAL", "void")

if const:
sproto += "C"
s = s.replace("$CONST", "const")
else:
s = s.replace("$CONST", "")

s = s.replace("$VER", sproto)
argtext = ""
funcargs = ""

for i in range(argcount):
if i > 0:
funcargs += ", "

argtext += ", m_type" + str(i + 1)
funcargs += "m_type" + str(i + 1) + " arg" + str(i + 1)

if argcount:
s = s.replace("$ARG", argtext)
s = s.replace("$FUNCARGS", funcargs)
else:
s = s.replace("$ARG", "")
s = s.replace("$FUNCARGS", funcargs)

return s


def generate_wrappers(target):
max_versions = 12

txt = """
#ifndef GDEXTENSION_WRAPPERS_GEN_H
#define GDEXTENSION_WRAPPERS_GEN_H
"""

for i in range(max_versions + 1):
txt += "\n/* Module Wrapper " + str(i) + " Arguments */\n"
txt += generate_mod_version(i, False, False)
txt += generate_mod_version(i, False, True)
txt += generate_mod_version(i, True, False)
txt += generate_mod_version(i, True, True)

txt += "\n#endif\n"

with open(target, "w") as f:
f.write(txt)


def get_file_list(api_filepath, output_dir, headers=False, sources=False):
api = {}
files = []
with open(api_filepath) as api_file:
api = json.load(api_file)

core_gen_folder = Path(output_dir) / "gen" / "include" / "godot_cpp" / "core"
include_gen_folder = Path(output_dir) / "gen" / "include" / "godot_cpp"
source_gen_folder = Path(output_dir) / "gen" / "src"

files.append(str((core_gen_folder / "ext_wrappers.gen.inc").as_posix()))

for builtin_class in api["builtin_classes"]:
if is_pod_type(builtin_class["name"]):
continue
Expand Down Expand Up @@ -121,12 +189,16 @@ def generate_bindings(api_filepath, use_template_get_node, bits="64", double="fl
def generate_builtin_bindings(api, output_dir, build_config):
global builtin_classes

core_gen_folder = Path(output_dir) / "include" / "godot_cpp" / "core"
include_gen_folder = Path(output_dir) / "include" / "godot_cpp" / "variant"
source_gen_folder = Path(output_dir) / "src" / "variant"

core_gen_folder.mkdir(parents=True, exist_ok=True)
include_gen_folder.mkdir(parents=True, exist_ok=True)
source_gen_folder.mkdir(parents=True, exist_ok=True)

generate_wrappers(core_gen_folder / "ext_wrappers.gen.inc")

# Store types beforehand.
for builtin_api in api["builtin_classes"]:
if is_pod_type(builtin_api["name"]):
Expand Down
Loading

0 comments on commit e51df84

Please sign in to comment.