Skip to content
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

[GDExtension] Use function names with underscore for TextServer extension, add macros to generate wrappers for module functions. #66492

Merged
merged 1 commit into from
Sep 28, 2022
Merged
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
83 changes: 71 additions & 12 deletions core/extension/make_wrappers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,60 @@
proto = """
proto_mod = """
#define MODBIND$VER($RETTYPE m_name$ARG) \\
virtual $RETVAL _##m_name($FUNCARGS) $CONST; \\
_FORCE_INLINE_ virtual $RETVAL m_name($FUNCARGS) $CONST override { \\
$RETX _##m_name($CALLARGS);\\
}
"""


def generate_mod_version(argcount, const=False, returns=False):
s = proto_mod
sproto = str(argcount)
method_info = ""
if returns:
sproto += "R"
s = s.replace("$RETTYPE", "m_ret, ")
s = s.replace("$RETVAL", "m_ret")
s = s.replace("$RETX", "return")

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

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

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

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

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

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

return s


proto_ex = """
#define EXBIND$VER($RETTYPE m_name$ARG) \\
GDVIRTUAL$VER($RETTYPE_##m_name$ARG)\\
virtual $RETVAL m_name($FUNCARGS) $CONST override { \\
Expand All @@ -9,8 +65,8 @@
"""


def generate_version(argcount, const=False, returns=False):
s = proto
def generate_ex_version(argcount, const=False, returns=False):
s = proto_ex
sproto = str(argcount)
method_info = ""
if returns:
Expand Down Expand Up @@ -63,25 +119,28 @@ def generate_version(argcount, const=False, returns=False):


def run(target, source, env):

max_versions = 12

txt = """
#ifndef GDEXTENSION_WRAPPERS_GEN_H
#define GDEXTENSION_WRAPPERS_GEN_H


"""

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

txt += "/* " + str(i) + " Arguments */\n\n"
txt += generate_version(i, False, False)
txt += generate_version(i, False, True)
txt += generate_version(i, True, False)
txt += generate_version(i, True, True)
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 += "#endif"
txt += "\n#endif\n"

with open(target[0], "w") as f:
f.write(txt)
Expand Down
2 changes: 2 additions & 0 deletions doc/classes/TextServer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,8 @@
<constant name="FONT_LCD_SUBPIXEL_LAYOUT_VBGR" value="4" enum="FontLCDSubpixelLayout">
Vertical BGR sub-pixel layout.
</constant>
<constant name="FONT_LCD_SUBPIXEL_LAYOUT_MAX" value="5" enum="FontLCDSubpixelLayout">
</constant>
<constant name="DIRECTION_AUTO" value="0" enum="Direction">
Text direction is determined based on contents and current locale.
</constant>
Expand Down
Loading