diff options
author | reduz <reduzio@gmail.com> | 2022-03-26 16:48:43 +0100 |
---|---|---|
committer | reduz <reduzio@gmail.com> | 2022-03-27 16:13:00 +0200 |
commit | 360dea5348652d8806d33598e111651afb3d193a (patch) | |
tree | 3726e871844722d9561943a85a447037342df7dc /servers/extensions | |
parent | a5eed70fa2edcf755d6abea2077232e38381449b (diff) |
Add GDExtension support to Script
* Ability to create script languages from GDExtension
* Some additions to gdnative_extension.h to make this happen
* Moved the GDExtension binder to core
This now allows creating scripting languages from GDExtension, with the same ease as if it was a module. It replaces the old PluginScript from Godot 3.x.
Warning: GodotCPP will need to be updated to support this (it may be a bit of work as ScriptInstance needs to be created over there again).
Diffstat (limited to 'servers/extensions')
-rw-r--r-- | servers/extensions/SCsub | 5 | ||||
-rw-r--r-- | servers/extensions/make_wrappers.py | 93 | ||||
-rw-r--r-- | servers/extensions/physics_server_3d_extension.h | 2 |
3 files changed, 1 insertions, 99 deletions
diff --git a/servers/extensions/SCsub b/servers/extensions/SCsub index eac66ea283..ba73353f2a 100644 --- a/servers/extensions/SCsub +++ b/servers/extensions/SCsub @@ -2,11 +2,6 @@ Import("env") -import make_wrappers -from platform_methods import run_in_subprocess - -env.CommandNoCache(["ext_wrappers.gen.inc"], "make_wrappers.py", run_in_subprocess(make_wrappers.run)) - env_object = env.Clone() env_object.add_source_files(env.servers_sources, "*.cpp") diff --git a/servers/extensions/make_wrappers.py b/servers/extensions/make_wrappers.py deleted file mode 100644 index 862d313fba..0000000000 --- a/servers/extensions/make_wrappers.py +++ /dev/null @@ -1,93 +0,0 @@ -proto = """ -#define EXBIND$VER($RETTYPE m_name$ARG) \\ -GDVIRTUAL$VER($RETTYPE_##m_name$ARG)\\ -virtual $RETVAL m_name($FUNCARGS) $CONST override { \\ - $RETPRE\\ - GDVIRTUAL_REQUIRED_CALL(_##m_name$CALLARGS$RETREF);\\ - $RETPOST\\ -} -""" - - -def generate_version(argcount, const=False, returns=False): - s = proto - sproto = str(argcount) - method_info = "" - if returns: - sproto += "R" - s = s.replace("$RETTYPE", "m_ret, ") - s = s.replace("$RETVAL", "m_ret") - s = s.replace("$RETPRE", "m_ret ret; ZeroInitializer<m_ret>::initialize(ret);\\\n") - s = s.replace("$RETPOST", "return ret;\\\n") - - else: - s = s.replace("$RETTYPE", "") - s = s.replace("$RETVAL", "void") - s = s.replace("$RETPRE", "") - s = s.replace("$RETPOST", "return;") - - 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 += ", " - - 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) - - if returns: - s = s.replace("$RETREF", ", ret") - else: - s = s.replace("$RETREF", "") - - return s - - -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 += "/* " + 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) - - txt += "#endif" - - with open(target[0], "w") as f: - f.write(txt) - - -if __name__ == "__main__": - from platform_methods import subprocess_main - - subprocess_main(globals()) diff --git a/servers/extensions/physics_server_3d_extension.h b/servers/extensions/physics_server_3d_extension.h index b40ab8a295..41a7746183 100644 --- a/servers/extensions/physics_server_3d_extension.h +++ b/servers/extensions/physics_server_3d_extension.h @@ -31,11 +31,11 @@ #ifndef PHYSICS_SERVER_3D_EXTENSION_H #define PHYSICS_SERVER_3D_EXTENSION_H +#include "core/extension/ext_wrappers.gen.inc" #include "core/object/script_language.h" #include "core/variant/native_ptr.h" #include "core/variant/type_info.h" #include "core/variant/typed_array.h" -#include "servers/extensions/ext_wrappers.gen.inc" #include "servers/physics_server_3d.h" class PhysicsDirectBodyState3DExtension : public PhysicsDirectBodyState3D { |