summaryrefslogtreecommitdiff
path: root/modules/mono/editor
diff options
context:
space:
mode:
Diffstat (limited to 'modules/mono/editor')
-rw-r--r--modules/mono/editor/bindings_generator.cpp65
-rw-r--r--modules/mono/editor/bindings_generator.h5
2 files changed, 52 insertions, 18 deletions
diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp
index 272283432d..d8f5b814e4 100644
--- a/modules/mono/editor/bindings_generator.cpp
+++ b/modules/mono/editor/bindings_generator.cpp
@@ -100,6 +100,9 @@
#define BINDINGS_GENERATOR_VERSION UINT32_C(13)
+// Types that will be ignored by the generator and won't be available in C#.
+const Vector<String> ignored_types = { "PhysicsServer3DExtension" };
+
const char *BindingsGenerator::TypeInterface::DEFAULT_VARARG_C_IN("\t%0 %1_in = %1;\n");
static String fix_doc_description(const String &p_bbcode) {
@@ -799,10 +802,13 @@ void BindingsGenerator::_generate_method_icalls(const TypeInterface &p_itype) {
const TypeInterface *return_type = _get_type_or_placeholder(imethod.return_type);
- String im_sig = "IntPtr " CS_PARAM_METHODBIND ", ";
- String im_unique_sig = imethod.return_type.cname.operator String() + ",IntPtr,IntPtr";
+ String im_sig = "IntPtr " CS_PARAM_METHODBIND;
+ String im_unique_sig = imethod.return_type.cname.operator String() + ",IntPtr";
- im_sig += "IntPtr " CS_PARAM_INSTANCE;
+ if (!imethod.is_static) {
+ im_sig += ", IntPtr " CS_PARAM_INSTANCE;
+ im_unique_sig += ",IntPtr";
+ }
// Get arguments information
int i = 0;
@@ -1730,8 +1736,10 @@ Error BindingsGenerator::_generate_cs_method(const BindingsGenerator::TypeInterf
String arguments_sig;
String cs_in_statements;
- String icall_params = method_bind_field + ", ";
- icall_params += sformat(p_itype.cs_in, "this");
+ String icall_params = method_bind_field;
+ if (!p_imethod.is_static) {
+ icall_params += ", " + sformat(p_itype.cs_in, "this");
+ }
StringBuilder default_args_doc;
@@ -1889,7 +1897,7 @@ Error BindingsGenerator::_generate_cs_method(const BindingsGenerator::TypeInterf
p_output.append(MEMBER_BEGIN);
p_output.append(p_imethod.is_internal ? "internal " : "public ");
- if (p_itype.is_singleton) {
+ if (p_itype.is_singleton || p_imethod.is_static) {
p_output.append("static ");
} else if (p_imethod.is_virtual) {
p_output.append("virtual ");
@@ -2268,7 +2276,10 @@ Error BindingsGenerator::_generate_glue_method(const BindingsGenerator::TypeInte
String argc_str = itos(p_imethod.arguments.size());
- String c_func_sig = "MethodBind* " CS_PARAM_METHODBIND ", " + p_itype.c_type_in + " " CS_PARAM_INSTANCE;
+ String c_func_sig = "MethodBind* " CS_PARAM_METHODBIND;
+ if (!p_imethod.is_static) {
+ c_func_sig += ", " + p_itype.c_type_in + " " CS_PARAM_INSTANCE;
+ }
String c_in_statements;
String c_args_var_content;
@@ -2360,17 +2371,21 @@ Error BindingsGenerator::_generate_glue_method(const BindingsGenerator::TypeInte
String fail_ret = return_type->c_type_out.ends_with("*") && !return_type->ret_as_byref_arg ? "nullptr" : return_type->c_type_out + "()";
- if (return_type->ret_as_byref_arg) {
- p_output.append("\tif (" CS_PARAM_INSTANCE " == nullptr) { *arg_ret = ");
- p_output.append(fail_ret);
- p_output.append("; ERR_FAIL_MSG(\"Parameter ' " CS_PARAM_INSTANCE " ' is null.\"); }\n");
- } else {
- p_output.append("\tERR_FAIL_NULL_V(" CS_PARAM_INSTANCE ", ");
- p_output.append(fail_ret);
- p_output.append(");\n");
+ if (!p_imethod.is_static) {
+ if (return_type->ret_as_byref_arg) {
+ p_output.append("\tif (" CS_PARAM_INSTANCE " == nullptr) { *arg_ret = ");
+ p_output.append(fail_ret);
+ p_output.append("; ERR_FAIL_MSG(\"Parameter ' " CS_PARAM_INSTANCE " ' is null.\"); }\n");
+ } else {
+ p_output.append("\tERR_FAIL_NULL_V(" CS_PARAM_INSTANCE ", ");
+ p_output.append(fail_ret);
+ p_output.append(");\n");
+ }
}
} else {
- p_output.append("\tERR_FAIL_NULL(" CS_PARAM_INSTANCE ");\n");
+ if (!p_imethod.is_static) {
+ p_output.append("\tERR_FAIL_NULL(" CS_PARAM_INSTANCE ");\n");
+ }
}
if (p_imethod.arguments.size()) {
@@ -2414,7 +2429,9 @@ Error BindingsGenerator::_generate_glue_method(const BindingsGenerator::TypeInte
}
}
- p_output.append(CS_PARAM_METHODBIND "->call(" CS_PARAM_INSTANCE ", ");
+ p_output.append(CS_PARAM_METHODBIND "->call(");
+ p_output.append(p_imethod.is_static ? "nullptr" : CS_PARAM_INSTANCE);
+ p_output.append(", ");
p_output.append(p_imethod.arguments.size() ? C_LOCAL_PTRCALL_ARGS ".ptr()" : "nullptr");
p_output.append(", total_length, vcall_error);\n");
@@ -2425,7 +2442,9 @@ Error BindingsGenerator::_generate_glue_method(const BindingsGenerator::TypeInte
}
}
} else {
- p_output.append("\t" CS_PARAM_METHODBIND "->ptrcall(" CS_PARAM_INSTANCE ", ");
+ p_output.append("\t" CS_PARAM_METHODBIND "->ptrcall(");
+ p_output.append(p_imethod.is_static ? "nullptr" : CS_PARAM_INSTANCE);
+ p_output.append(", ");
p_output.append(p_imethod.arguments.size() ? C_LOCAL_PTRCALL_ARGS ", " : "nullptr, ");
p_output.append(!ret_void ? "&" C_LOCAL_RET ");\n" : "nullptr);\n");
}
@@ -2645,6 +2664,12 @@ bool BindingsGenerator::_populate_object_type_interfaces() {
continue;
}
+ if (ignored_types.has(type_cname)) {
+ _log("Ignoring type '%s' because it's in the list of ignored types\n", String(type_cname).utf8().get_data());
+ class_list.pop_front();
+ continue;
+ }
+
if (!ClassDB::is_class_exposed(type_cname)) {
_log("Ignoring type '%s' because it's not exposed\n", String(type_cname).utf8().get_data());
class_list.pop_front();
@@ -2763,6 +2788,10 @@ bool BindingsGenerator::_populate_object_type_interfaces() {
imethod.name = method_info.name;
imethod.cname = cname;
+ if (method_info.flags & METHOD_FLAG_STATIC) {
+ imethod.is_static = true;
+ }
+
if (method_info.flags & METHOD_FLAG_VIRTUAL) {
imethod.is_virtual = true;
}
diff --git a/modules/mono/editor/bindings_generator.h b/modules/mono/editor/bindings_generator.h
index f601ffde2b..dec4fae8cd 100644
--- a/modules/mono/editor/bindings_generator.h
+++ b/modules/mono/editor/bindings_generator.h
@@ -137,6 +137,11 @@ class BindingsGenerator {
bool is_vararg = false;
/**
+ * Determines if the method is static.
+ */
+ bool is_static = false;
+
+ /**
* Virtual methods ("virtual" as defined by the Godot API) are methods that by default do nothing,
* but can be overridden by the user to add custom functionality.
* e.g.: _ready, _process, etc.