Use StringName in the whole GDExtension API instead of const char *

This commit is contained in:
Emmanuel Leblond
2022-10-22 19:42:48 +02:00
parent 0e81f89dd3
commit e24b6b0e51
14 changed files with 318 additions and 314 deletions

View File

@@ -264,8 +264,8 @@ struct GetTypeInfo<Ref<T>, typename EnableIf<TypeInherits<RefCounted, T>::value>
static const GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_OBJECT;
static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE;
static inline GDNativePropertyInfo get_class_info() {
return make_property_info(GDNATIVE_VARIANT_TYPE_OBJECT, T::get_class_static());
static inline PropertyInfo get_class_info() {
return make_property_info(Variant::Type::OBJECT, T::get_class_static());
}
};
@@ -274,8 +274,8 @@ struct GetTypeInfo<const Ref<T> &, typename EnableIf<TypeInherits<RefCounted, T>
static const GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_OBJECT;
static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE;
static inline GDNativePropertyInfo get_class_info() {
return make_property_info(GDNATIVE_VARIANT_TYPE_OBJECT, T::get_class_static());
static inline PropertyInfo get_class_info() {
return make_property_info(Variant::Type::OBJECT, T::get_class_static());
}
};

View File

@@ -49,7 +49,7 @@ class Wrapped {
friend void postinitialize_handler(Wrapped *);
protected:
virtual const StringName *_get_extension_class() const; // This is needed to retrieve the class name before the godot object has its _extension and _extension_instance members assigned.
virtual const StringName *_get_extension_class_name() const; // This is needed to retrieve the class name before the godot object has its _extension and _extension_instance members assigned.
virtual const GDNativeInstanceBindingCallbacks *_get_bindings_callbacks() const = 0;
void _notification(int p_what){};
@@ -106,7 +106,7 @@ private:
friend class ::godot::ClassDB; \
\
protected: \
virtual const StringName *_get_extension_class() const override { \
virtual const StringName *_get_extension_class_name() const override { \
static StringName string_name = get_class_static(); \
return &string_name; \
} \
@@ -171,7 +171,7 @@ public:
return string_name; \
} \
\
static StringName *get_parent_class_static() { \
static StringName get_parent_class_static() { \
return m_inherits::get_class_static(); \
} \
\
@@ -223,10 +223,10 @@ public:
cls->plist_size = 0; \
for (const ::godot::PropertyInfo &E : list) { \
cls->plist[cls->plist_size].type = static_cast<GDNativeVariantType>(E.type); \
cls->plist[cls->plist_size].name = _alloc_and_copy_cstr(E.name.utf8().get_data()); \
cls->plist[cls->plist_size].name = E.name._native_ptr(); \
cls->plist[cls->plist_size].hint = E.hint; \
cls->plist[cls->plist_size].hint_string = _alloc_and_copy_cstr(E.hint_string.utf8().get_data()); \
cls->plist[cls->plist_size].class_name = _alloc_and_copy_cstr(E.class_name.utf8().get_data()); \
cls->plist[cls->plist_size].hint_string = E.hint_string._native_ptr(); \
cls->plist[cls->plist_size].class_name = E.class_name._native_ptr(); \
cls->plist[cls->plist_size].usage = E.usage; \
cls->plist_size++; \
} \
@@ -243,11 +243,6 @@ public:
if (p_instance) { \
m_class *cls = reinterpret_cast<m_class *>(p_instance); \
ERR_FAIL_COND_MSG(cls->plist == nullptr, "Internal error, property list double free!"); \
for (size_t i = 0; i < cls->plist_size; i++) { \
memfree(const_cast<char *>(cls->plist[i].name)); \
memfree(const_cast<char *>(cls->plist[i].class_name)); \
memfree(const_cast<char *>(cls->plist[i].hint_string)); \
} \
memfree(cls->plist); \
cls->plist = nullptr; \
cls->plist_size = 0; \

View File

@@ -423,7 +423,7 @@ GDNativeVariantType call_get_argument_type(int p_arg) {
}
template <class Q>
void call_get_argument_type_info_helper(int p_arg, int &index, GDNativePropertyInfo &info) {
void call_get_argument_type_info_helper(int p_arg, int &index, PropertyInfo &info) {
if (p_arg == index) {
info = GetTypeInfo<Q>::get_class_info();
}
@@ -431,7 +431,7 @@ void call_get_argument_type_info_helper(int p_arg, int &index, GDNativePropertyI
}
template <class... P>
void call_get_argument_type_info(int p_arg, GDNativePropertyInfo &info) {
void call_get_argument_type_info(int p_arg, PropertyInfo &info) {
int index = 0;
// I think rocket science is simpler than modern C++.
using expand_type = int[];

View File

@@ -44,22 +44,30 @@
#include <unordered_map>
#include <vector>
// Needed to use StringName as key in `std::unordered_map`
template <>
struct std::hash<godot::StringName> {
std::size_t operator()(godot::StringName const &s) const noexcept {
return s.hash();
}
};
namespace godot {
#define DEFVAL(m_defval) (m_defval)
struct MethodDefinition {
const char *name = nullptr;
std::list<std::string> args;
StringName name;
std::list<StringName> args;
MethodDefinition() {}
MethodDefinition(const char *p_name) :
MethodDefinition(StringName p_name) :
name(p_name) {}
};
MethodDefinition D_METHOD(const char *p_name);
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1);
MethodDefinition D_METHOD(StringName p_name);
MethodDefinition D_METHOD(StringName p_name, StringName p_arg1);
template <typename... Args>
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, Args... args) {
MethodDefinition D_METHOD(StringName p_name, StringName p_arg1, Args... args) {
MethodDefinition md = D_METHOD(p_name, args...);
md.args.push_front(p_arg1);
return md;
@@ -73,33 +81,33 @@ class ClassDB {
public:
struct PropertySetGet {
int index;
const char *setter;
const char *getter;
StringName setter;
StringName getter;
MethodBind *_setptr;
MethodBind *_getptr;
Variant::Type type;
};
struct ClassInfo {
const char *name = nullptr;
const char *parent_name = nullptr;
StringName name;
StringName parent_name;
GDNativeInitializationLevel level = GDNATIVE_INITIALIZATION_SCENE;
std::unordered_map<std::string, MethodBind *> method_map;
std::set<std::string> signal_names;
std::unordered_map<std::string, GDNativeExtensionClassCallVirtual> virtual_methods;
std::set<std::string> property_names;
std::set<std::string> constant_names;
std::unordered_map<StringName, MethodBind *> method_map;
std::set<StringName> signal_names;
std::unordered_map<StringName, GDNativeExtensionClassCallVirtual> virtual_methods;
std::set<StringName> property_names;
std::set<StringName> constant_names;
// Pointer to the parent custom class, if any. Will be null if the parent class is a Godot class.
ClassInfo *parent_ptr = nullptr;
};
private:
// This may only contain custom classes, not Godot classes
static std::unordered_map<std::string, ClassInfo> classes;
static std::unordered_map<StringName, ClassInfo> classes;
static MethodBind *bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const MethodDefinition &method_name, const void **p_defs, int p_defcount);
static void initialize_class(const ClassInfo &cl);
static void bind_method_godot(const char *p_class_name, MethodBind *p_method);
static void bind_method_godot(const StringName &p_class_name, MethodBind *p_method);
static _FORCE_INLINE_ char *_alloc_and_copy_cstr(const char *p_str) {
size_t size = strlen(p_str) + 1;
@@ -121,21 +129,21 @@ public:
static MethodBind *bind_method(N p_method_name, M p_method, VarArgs... p_args);
template <class N, class M, typename... VarArgs>
static MethodBind *bind_static_method(const char *p_class, N p_method_name, M p_method, VarArgs... p_args);
static MethodBind *bind_static_method(StringName p_class, N p_method_name, M p_method, VarArgs... p_args);
template <class M>
static MethodBind *bind_vararg_method(uint32_t p_flags, const char *p_name, M p_method, const MethodInfo &p_info = MethodInfo(), const std::vector<Variant> &p_default_args = std::vector<Variant>{}, bool p_return_nil_is_variant = true);
static MethodBind *bind_vararg_method(uint32_t p_flags, StringName p_name, M p_method, const MethodInfo &p_info = MethodInfo(), const std::vector<Variant> &p_default_args = std::vector<Variant>{}, bool p_return_nil_is_variant = true);
static void add_property_group(const char *p_class, const char *p_name, const char *p_prefix);
static void add_property_subgroup(const char *p_class, const char *p_name, const char *p_prefix);
static void add_property(const char *p_class, const PropertyInfo &p_pinfo, const char *p_setter, const char *p_getter, int p_index = -1);
static void add_signal(const char *p_class, const MethodInfo &p_signal);
static void bind_integer_constant(const char *p_class_name, const char *p_enum_name, const char *p_constant_name, GDNativeInt p_constant_value, bool p_is_bitfield = false);
static void bind_virtual_method(const char *p_class, const char *p_method, GDNativeExtensionClassCallVirtual p_call);
static void add_property_group(const StringName &p_class, const String &p_name, const String &p_prefix);
static void add_property_subgroup(const StringName &p_class, const String &p_name, const String &p_prefix);
static void add_property(const StringName &p_class, const PropertyInfo &p_pinfo, const StringName &p_setter, const StringName &p_getter, int p_index = -1);
static void add_signal(const StringName &p_class, const MethodInfo &p_signal);
static void bind_integer_constant(const StringName &p_class_name, const StringName &p_enum_name, const StringName &p_constant_name, GDNativeInt p_constant_value, bool p_is_bitfield = false);
static void bind_virtual_method(const StringName &p_class, const StringName &p_method, GDNativeExtensionClassCallVirtual p_call);
static MethodBind *get_method(const char *p_class, const char *p_method);
static MethodBind *get_method(const StringName &p_class, const StringName &p_method);
static GDNativeExtensionClassCallVirtual get_virtual_func(void *p_userdata, const char *p_name);
static GDNativeExtensionClassCallVirtual get_virtual_func(void *p_userdata, const GDNativeStringNamePtr p_name);
static void initialize(GDNativeInitializationLevel p_level);
static void deinitialize(GDNativeInitializationLevel p_level);
@@ -165,7 +173,7 @@ void ClassDB::_register_class(bool p_virtual) {
cl.name = T::get_class_static();
cl.parent_name = T::get_parent_class_static();
cl.level = current_level;
std::unordered_map<std::string, ClassInfo>::iterator parent_it = classes.find(cl.parent_name);
std::unordered_map<StringName, ClassInfo>::iterator parent_it = classes.find(cl.parent_name);
if (parent_it != classes.end()) {
// Assign parent if it is also a custom class
cl.parent_ptr = &parent_it->second;
@@ -190,10 +198,10 @@ void ClassDB::_register_class(bool p_virtual) {
T::free, // GDNativeExtensionClassFreeInstance free_instance_func; /* this one is mandatory */
&ClassDB::get_virtual_func, // GDNativeExtensionClassGetVirtual get_virtual_func;
nullptr, // GDNativeExtensionClassGetRID get_rid;
(void *)cl.name, // void *class_userdata;
(void *)&cl.name, // void *class_userdata;
};
internal::gdn_interface->classdb_register_extension_class(internal::library, cl.name, cl.parent_name, &class_info);
internal::gdn_interface->classdb_register_extension_class(internal::library, cl.name._native_ptr(), cl.parent_name._native_ptr(), &class_info);
// call bind_methods etc. to register all members of the class
T::initialize_class();
@@ -224,7 +232,7 @@ MethodBind *ClassDB::bind_method(N p_method_name, M p_method, VarArgs... p_args)
}
template <class N, class M, typename... VarArgs>
MethodBind *ClassDB::bind_static_method(const char *p_class, N p_method_name, M p_method, VarArgs... p_args) {
MethodBind *ClassDB::bind_static_method(StringName p_class, N p_method_name, M p_method, VarArgs... p_args) {
Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
const Variant *argptrs[sizeof...(p_args) + 1];
for (uint32_t i = 0; i < sizeof...(p_args); i++) {
@@ -236,16 +244,16 @@ MethodBind *ClassDB::bind_static_method(const char *p_class, N p_method_name, M
}
template <class M>
MethodBind *ClassDB::bind_vararg_method(uint32_t p_flags, const char *p_name, M p_method, const MethodInfo &p_info, const std::vector<Variant> &p_default_args, bool p_return_nil_is_variant) {
MethodBind *ClassDB::bind_vararg_method(uint32_t p_flags, StringName p_name, M p_method, const MethodInfo &p_info, const std::vector<Variant> &p_default_args, bool p_return_nil_is_variant) {
MethodBind *bind = create_vararg_method_bind(p_method, p_info, p_return_nil_is_variant);
ERR_FAIL_COND_V(!bind, nullptr);
bind->set_name(p_name);
bind->set_default_arguments(p_default_args);
const char *instance_type = bind->get_instance_class();
StringName instance_type = bind->get_instance_class();
std::unordered_map<std::string, ClassInfo>::iterator type_it = classes.find(instance_type);
std::unordered_map<StringName, ClassInfo>::iterator type_it = classes.find(instance_type);
if (type_it == classes.end()) {
memdelete(bind);
ERR_FAIL_V_MSG(nullptr, String("Class '{0}' doesn't exist.").format(instance_type));

View File

@@ -48,8 +48,8 @@
namespace godot {
class MethodBind {
const char *name = nullptr;
const char *instance_class = nullptr;
StringName name;
StringName instance_class;
int argument_count = 0;
uint32_t hint_flags = METHOD_FLAGS_DEFAULT;
@@ -58,13 +58,13 @@ class MethodBind {
bool _has_return = false;
bool _vararg = false;
std::vector<std::string> argument_names;
std::vector<StringName> argument_names;
GDNativeVariantType *argument_types = nullptr;
std::vector<Variant> default_arguments;
protected:
virtual GDNativeVariantType gen_argument_type(int p_arg) const = 0;
virtual GDNativePropertyInfo gen_argument_type_info(int p_arg) const = 0;
virtual PropertyInfo gen_argument_type_info(int p_arg) const = 0;
void generate_argument_types(int p_count);
void set_const(bool p_const);
void set_return(bool p_return);
@@ -73,8 +73,8 @@ protected:
void set_argument_count(int p_count);
public:
const char *get_name() const;
void set_name(const char *p_name);
StringName get_name() const;
void set_name(const StringName &p_name);
_FORCE_INLINE_ int get_default_argument_count() const { return (int)default_arguments.size(); }
_FORCE_INLINE_ const std::vector<Variant> &get_default_arguments() const { return default_arguments; }
_FORCE_INLINE_ Variant has_default_argument(int p_arg) const {
@@ -95,8 +95,8 @@ public:
return default_arguments[idx];
}
}
_FORCE_INLINE_ const char *get_instance_class() const { return instance_class; }
_FORCE_INLINE_ void set_instance_class(const char *p_class) { instance_class = p_class; }
_FORCE_INLINE_ StringName get_instance_class() const { return instance_class; }
_FORCE_INLINE_ void set_instance_class(StringName p_class) { instance_class = p_class; }
_FORCE_INLINE_ int get_argument_count() const { return argument_count; };
_FORCE_INLINE_ bool is_const() const { return _is_const; }
@@ -105,8 +105,8 @@ public:
_FORCE_INLINE_ bool has_return() const { return _has_return; }
_FORCE_INLINE_ uint32_t get_hint_flags() const { return hint_flags | (is_const() ? GDNATIVE_EXTENSION_METHOD_FLAG_CONST : 0) | (is_vararg() ? GDNATIVE_EXTENSION_METHOD_FLAG_VARARG : 0) | (is_static() ? GDNATIVE_EXTENSION_METHOD_FLAG_STATIC : 0); }
_FORCE_INLINE_ void set_hint_flags(uint32_t p_hint_flags) { hint_flags = p_hint_flags; }
void set_argument_names(const std::vector<std::string> &p_names);
std::vector<std::string> get_argument_names() const;
void set_argument_names(const std::vector<StringName> &p_names);
std::vector<StringName> get_argument_names() const;
void set_default_arguments(const std::vector<Variant> &p_default_arguments) { default_arguments = p_default_arguments; }
_FORCE_INLINE_ GDNativeVariantType get_argument_type(int p_argument) const {
@@ -114,17 +114,31 @@ public:
return argument_types[p_argument + 1];
}
GDNativePropertyInfo get_argument_info(int p_argument) const;
PropertyInfo get_argument_info(int p_argument) const;
virtual GDNativeExtensionClassMethodArgumentMetadata get_argument_metadata(int p_argument) const = 0;
std::vector<PropertyInfo> get_arguments_info_list() const {
std::vector<PropertyInfo> vec;
// First element is return value
vec.reserve(argument_count + 1);
for (int i = 0; i < argument_count; i++) {
vec.push_back(get_argument_info(i - 1));
}
return vec;
}
std::vector<GDNativeExtensionClassMethodArgumentMetadata> get_arguments_metadata_list() const {
std::vector<GDNativeExtensionClassMethodArgumentMetadata> vec;
// First element is return value
vec.reserve(argument_count + 1);
for (int i = 0; i < argument_count; i++) {
vec.push_back(get_argument_metadata(i - 1));
}
return vec;
}
virtual Variant call(GDExtensionClassInstancePtr p_instance, const GDNativeVariantPtr *p_args, const GDNativeInt p_argument_count, GDNativeCallError &r_error) const = 0;
virtual void ptrcall(GDExtensionClassInstancePtr p_instance, const GDNativeTypePtr *p_args, GDNativeTypePtr r_return) const = 0;
// Extension info.
static GDNativeVariantType bind_get_argument_type(void *p_method_userdata, int32_t p_argument);
static void bind_get_argument_info(void *p_method_userdata, int32_t p_argument, GDNativePropertyInfo *r_info);
static GDNativeExtensionClassMethodArgumentMetadata bind_get_argument_metadata(void *p_method_userdata, int32_t p_argument);
static void bind_call(void *p_method_userdata, GDExtensionClassInstancePtr p_instance, const GDNativeVariantPtr *p_args, const GDNativeInt p_argument_count, GDNativeVariantPtr r_return, GDNativeCallError *r_error);
static void bind_ptrcall(void *p_method_userdata, GDExtensionClassInstancePtr p_instance, const GDNativeTypePtr *p_args, GDNativeTypePtr r_return);
@@ -136,16 +150,16 @@ class MethodBindVarArgBase : public MethodBind {
protected:
R(T::*method)
(const Variant **, GDNativeInt, GDNativeCallError &);
std::vector<GDNativePropertyInfo> arguments;
std::vector<PropertyInfo> arguments;
public:
virtual GDNativePropertyInfo gen_argument_type_info(int p_arg) const {
virtual PropertyInfo gen_argument_type_info(int p_arg) const {
if (p_arg < 0) {
return _gen_return_type_info();
} else if (p_arg < arguments.size()) {
return arguments[p_arg];
} else {
return make_property_info(GDNATIVE_VARIANT_TYPE_NIL, "vararg", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT);
return make_property_info(Variant::Type::NIL, "vararg", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT);
}
}
@@ -177,20 +191,13 @@ public:
set_const(true);
set_argument_count(p_method_info.arguments.size());
if (p_method_info.arguments.size()) {
std::vector<std::string> names;
arguments = p_method_info.arguments;
std::vector<StringName> names;
names.reserve(p_method_info.arguments.size());
for (int i = 0; i < p_method_info.arguments.size(); i++) {
names.push_back(p_method_info.arguments[i].name.utf8().get_data());
arguments.push_back(GDNativePropertyInfo{
static_cast<GDNativeVariantType>(p_method_info.arguments[i].type), // GDNativeVariantType type;
_alloc_and_copy_cstr(p_method_info.arguments[i].name.utf8().get_data()), // const char *name;
_alloc_and_copy_cstr(p_method_info.arguments[i].class_name.utf8().get_data()), // const char *class_name;
p_method_info.arguments[i].hint, // NONE //uint32_t hint;
_alloc_and_copy_cstr(p_method_info.arguments[i].hint_string.utf8().get_data()), // const char *hint_string;
p_method_info.arguments[i].usage, // DEFAULT //uint32_t usage;
});
names.push_back(p_method_info.arguments[i].name);
}
set_argument_names(names);
}
@@ -198,16 +205,10 @@ public:
set_return(should_returns);
}
~MethodBindVarArgBase() {
for (GDNativePropertyInfo &arg : arguments) {
memfree(const_cast<char *>(arg.name));
memfree(const_cast<char *>(arg.class_name));
memfree(const_cast<char *>(arg.hint_string));
}
}
~MethodBindVarArgBase() {}
private:
GDNativePropertyInfo _gen_return_type_info() const {
PropertyInfo _gen_return_type_info() const {
return reinterpret_cast<const Derived *>(this)->_gen_return_type_info_impl();
}
};
@@ -230,7 +231,7 @@ public:
}
private:
GDNativePropertyInfo _gen_return_type_info_impl() const {
PropertyInfo _gen_return_type_info_impl() const {
return {};
}
};
@@ -259,7 +260,7 @@ public:
}
private:
GDNativePropertyInfo _gen_return_type_info_impl() const {
PropertyInfo _gen_return_type_info_impl() const {
return GetTypeInfo<R>::get_class_info();
}
};
@@ -302,12 +303,12 @@ protected:
}
}
virtual GDNativePropertyInfo gen_argument_type_info(int p_arg) const {
GDNativePropertyInfo pi;
virtual PropertyInfo gen_argument_type_info(int p_arg) const {
PropertyInfo pi;
if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
call_get_argument_type_info<P...>(p_arg, pi);
} else {
pi = GDNativePropertyInfo();
pi = PropertyInfo();
}
return pi;
}
@@ -378,12 +379,12 @@ protected:
}
}
virtual GDNativePropertyInfo gen_argument_type_info(int p_arg) const {
GDNativePropertyInfo pi;
virtual PropertyInfo gen_argument_type_info(int p_arg) const {
PropertyInfo pi;
if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
call_get_argument_type_info<P...>(p_arg, pi);
} else {
pi = GDNativePropertyInfo();
pi = PropertyInfo();
}
return pi;
}
@@ -455,9 +456,9 @@ protected:
}
}
virtual GDNativePropertyInfo gen_argument_type_info(int p_arg) const {
virtual PropertyInfo gen_argument_type_info(int p_arg) const {
if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
GDNativePropertyInfo pi;
PropertyInfo pi;
call_get_argument_type_info<P...>(p_arg, pi);
return pi;
} else {
@@ -538,9 +539,9 @@ protected:
}
}
virtual GDNativePropertyInfo gen_argument_type_info(int p_arg) const {
virtual PropertyInfo gen_argument_type_info(int p_arg) const {
if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
GDNativePropertyInfo pi;
PropertyInfo pi;
call_get_argument_type_info<P...>(p_arg, pi);
return pi;
} else {
@@ -618,12 +619,12 @@ protected:
}
}
virtual GDNativePropertyInfo gen_argument_type_info(int p_arg) const {
GDNativePropertyInfo pi;
virtual PropertyInfo gen_argument_type_info(int p_arg) const {
PropertyInfo pi;
if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
call_get_argument_type_info<P...>(p_arg, pi);
} else {
pi = GDNativePropertyInfo();
pi = PropertyInfo();
}
return pi;
}
@@ -683,9 +684,9 @@ protected:
}
}
virtual GDNativePropertyInfo gen_argument_type_info(int p_arg) const {
virtual PropertyInfo gen_argument_type_info(int p_arg) const {
if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
GDNativePropertyInfo pi;
PropertyInfo pi;
call_get_argument_type_info<P...>(p_arg, pi);
return pi;
} else {

View File

@@ -53,7 +53,7 @@
namespace godot {
struct MethodInfo {
const char *name;
StringName name;
PropertyInfo return_val;
uint32_t flags;
int id = 0;
@@ -68,33 +68,33 @@ struct MethodInfo {
static MethodInfo from_dict(const Dictionary &p_dict);
MethodInfo();
MethodInfo(const char *p_name);
MethodInfo(StringName p_name);
template <class... Args>
MethodInfo(const char *p_name, const Args &...args);
MethodInfo(StringName p_name, const Args &...args);
MethodInfo(Variant::Type ret);
MethodInfo(Variant::Type ret, const char *p_name);
MethodInfo(Variant::Type ret, StringName p_name);
template <class... Args>
MethodInfo(Variant::Type ret, const char *p_name, const Args &...args);
MethodInfo(const PropertyInfo &p_ret, const char *p_name);
MethodInfo(Variant::Type ret, StringName p_name, const Args &...args);
MethodInfo(const PropertyInfo &p_ret, StringName p_name);
template <class... Args>
MethodInfo(const PropertyInfo &p_ret, const char *p_name, const Args &...);
MethodInfo(const PropertyInfo &p_ret, StringName p_name, const Args &...);
};
template <class... Args>
MethodInfo::MethodInfo(const char *p_name, const Args &...args) :
MethodInfo::MethodInfo(StringName p_name, const Args &...args) :
name(p_name), flags(GDNATIVE_EXTENSION_METHOD_FLAG_NORMAL) {
arguments = { args... };
}
template <class... Args>
MethodInfo::MethodInfo(Variant::Type ret, const char *p_name, const Args &...args) :
MethodInfo::MethodInfo(Variant::Type ret, StringName p_name, const Args &...args) :
name(p_name), flags(GDNATIVE_EXTENSION_METHOD_FLAG_NORMAL) {
return_val.type = ret;
arguments = { args... };
}
template <class... Args>
MethodInfo::MethodInfo(const PropertyInfo &p_ret, const char *p_name, const Args &...args) :
MethodInfo::MethodInfo(const PropertyInfo &p_ret, StringName p_name, const Args &...args) :
name(p_name), return_val(p_ret), flags(GDNATIVE_EXTENSION_METHOD_FLAG_NORMAL) {
arguments = { args... };
}
@@ -137,7 +137,8 @@ T *Object::cast_to(Object *p_object) {
if (p_object == nullptr) {
return nullptr;
}
GDNativeObjectPtr casted = internal::gdn_interface->object_cast_to(p_object->_owner, internal::gdn_interface->classdb_get_class_tag(T::get_class_static()));
StringName class_name = T::get_class_static();
GDNativeObjectPtr casted = internal::gdn_interface->object_cast_to(p_object->_owner, internal::gdn_interface->classdb_get_class_tag(class_name._native_ptr()));
if (casted == nullptr) {
return nullptr;
}
@@ -149,7 +150,8 @@ const T *Object::cast_to(const Object *p_object) {
if (p_object == nullptr) {
return nullptr;
}
GDNativeObjectPtr casted = internal::gdn_interface->object_cast_to(p_object->_owner, internal::gdn_interface->classdb_get_class_tag(T::get_class_static()));
StringName class_name = T::get_class_static();
GDNativeObjectPtr casted = internal::gdn_interface->object_cast_to(p_object->_owner, internal::gdn_interface->classdb_get_class_tag(class_name._native_ptr()));
if (casted == nullptr) {
return nullptr;
}

View File

@@ -45,15 +45,15 @@ namespace godot {
struct PropertyInfo {
Variant::Type type = Variant::NIL;
String name;
String class_name;
StringName name;
StringName class_name;
uint32_t hint = 0;
String hint_string;
uint32_t usage = 7;
PropertyInfo() = default;
PropertyInfo(Variant::Type p_type, const String &p_name, PropertyHint p_hint = PROPERTY_HINT_NONE, const String &p_hint_string = "", uint32_t p_usage = PROPERTY_USAGE_DEFAULT, const String &p_class_name = "") :
PropertyInfo(Variant::Type p_type, const StringName &p_name, PropertyHint p_hint = PROPERTY_HINT_NONE, const String &p_hint_string = "", uint32_t p_usage = PROPERTY_USAGE_DEFAULT, const StringName &p_class_name = "") :
type(p_type),
name(p_name),
hint(p_hint),
@@ -66,7 +66,7 @@ struct PropertyInfo {
}
}
PropertyInfo(GDNativeVariantType p_type, const String &p_name, PropertyHint p_hint = PROPERTY_HINT_NONE, const String &p_hint_string = "", uint32_t p_usage = PROPERTY_USAGE_DEFAULT, const String &p_class_name = "") :
PropertyInfo(GDNativeVariantType p_type, const StringName &p_name, PropertyHint p_hint = PROPERTY_HINT_NONE, const String &p_hint_string = "", uint32_t p_usage = PROPERTY_USAGE_DEFAULT, const StringName &p_class_name = "") :
PropertyInfo((Variant::Type)p_type, p_name, p_hint, p_hint_string, p_usage, p_class_name) {}
};

View File

@@ -69,8 +69,8 @@ struct TypeInherits {
!TypesAreSame<B volatile const, void volatile const>::value;
};
static GDNativePropertyInfo make_property_info(GDNativeVariantType p_type, const char *p_name, uint32_t p_hint = PROPERTY_HINT_NONE, const char *p_hint_string = "", uint32_t p_usage = PROPERTY_USAGE_DEFAULT, const char *p_class_name = "") {
GDNativePropertyInfo info;
static PropertyInfo make_property_info(Variant::Type p_type, const StringName &p_name, uint32_t p_hint = PROPERTY_HINT_NONE, const String &p_hint_string = "", uint32_t p_usage = PROPERTY_USAGE_DEFAULT, const StringName &p_class_name = "") {
PropertyInfo info;
info.type = p_type;
info.name = p_name;
info.hint = p_hint;
@@ -98,16 +98,16 @@ struct GetTypeInfo;
struct GetTypeInfo<m_type> { \
static constexpr GDNativeVariantType VARIANT_TYPE = m_var_type; \
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
static inline GDNativePropertyInfo get_class_info() { \
return make_property_info(VARIANT_TYPE, ""); \
static inline PropertyInfo get_class_info() { \
return make_property_info((Variant::Type)VARIANT_TYPE, ""); \
} \
}; \
template <> \
struct GetTypeInfo<const m_type &> { \
static constexpr GDNativeVariantType VARIANT_TYPE = m_var_type; \
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
static inline GDNativePropertyInfo get_class_info() { \
return make_property_info(VARIANT_TYPE, ""); \
static inline PropertyInfo get_class_info() { \
return make_property_info((Variant::Type)VARIANT_TYPE, ""); \
} \
};
@@ -116,16 +116,16 @@ struct GetTypeInfo;
struct GetTypeInfo<m_type> { \
static constexpr GDNativeVariantType VARIANT_TYPE = m_var_type; \
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = m_metadata; \
static inline GDNativePropertyInfo get_class_info() { \
return make_property_info(VARIANT_TYPE, ""); \
static inline PropertyInfo get_class_info() { \
return make_property_info((Variant::Type)VARIANT_TYPE, ""); \
} \
}; \
template <> \
struct GetTypeInfo<const m_type &> { \
static constexpr GDNativeVariantType VARIANT_TYPE = m_var_type; \
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = m_metadata; \
static inline GDNativePropertyInfo get_class_info() { \
return make_property_info(VARIANT_TYPE, ""); \
static inline PropertyInfo get_class_info() { \
return make_property_info((Variant::Type)VARIANT_TYPE, ""); \
} \
};
@@ -182,8 +182,8 @@ template <>
struct GetTypeInfo<Variant> {
static constexpr GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_NIL;
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE;
static inline GDNativePropertyInfo get_class_info() {
return make_property_info(GDNATIVE_VARIANT_TYPE_NIL, "", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT);
static inline PropertyInfo get_class_info() {
return make_property_info(Variant::Type::NIL, "", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT);
}
};
@@ -191,8 +191,8 @@ template <>
struct GetTypeInfo<const Variant &> {
static constexpr GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_NIL;
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE;
static inline GDNativePropertyInfo get_class_info() {
return make_property_info(GDNATIVE_VARIANT_TYPE_NIL, "", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT);
static inline PropertyInfo get_class_info() {
return make_property_info(Variant::Type::NIL, "", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT);
}
};
@@ -200,8 +200,8 @@ template <typename T>
struct GetTypeInfo<T *, typename EnableIf<TypeInherits<Object, T>::value>::type> {
static const GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_OBJECT;
static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE;
static inline GDNativePropertyInfo get_class_info() {
return make_property_info(GDNATIVE_VARIANT_TYPE_OBJECT, T::get_class_static());
static inline PropertyInfo get_class_info() {
return make_property_info(Variant::Type::OBJECT, T::get_class_static());
}
};
@@ -209,19 +209,19 @@ template <typename T>
struct GetTypeInfo<const T *, typename EnableIf<TypeInherits<Object, T>::value>::type> {
static const GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_OBJECT;
static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE;
static inline GDNativePropertyInfo get_class_info() {
return make_property_info(GDNATIVE_VARIANT_TYPE_OBJECT, T::get_class_static());
static inline PropertyInfo get_class_info() {
return make_property_info(Variant::Type::OBJECT, T::get_class_static());
}
};
#define TEMPL_MAKE_ENUM_TYPE_INFO(m_class, m_enum, m_impl) \
template <> \
struct GetTypeInfo<m_impl> { \
static const Variant::Type VARIANT_TYPE = Variant::INT; \
static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
static inline GDNativePropertyInfo get_class_info() { \
return make_property_info(GDNATIVE_VARIANT_TYPE_INT, "", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_CLASS_IS_ENUM, #m_class "." #m_enum); \
} \
#define TEMPL_MAKE_ENUM_TYPE_INFO(m_class, m_enum, m_impl) \
template <> \
struct GetTypeInfo<m_impl> { \
static const Variant::Type VARIANT_TYPE = Variant::INT; \
static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
static inline PropertyInfo get_class_info() { \
return make_property_info(Variant::Type::INT, "", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_CLASS_IS_ENUM, #m_class "." #m_enum); \
} \
};
#define MAKE_ENUM_TYPE_INFO(m_class, m_enum) \
@@ -231,7 +231,7 @@ struct GetTypeInfo<const T *, typename EnableIf<TypeInherits<Object, T>::value>:
TEMPL_MAKE_ENUM_TYPE_INFO(m_class, m_enum, const m_class::m_enum &)
template <typename T>
inline const char *__constant_get_enum_name(T param, const char *p_constant) {
inline StringName __constant_get_enum_name(T param, StringName p_constant) {
if (GetTypeInfo<T>::VARIANT_TYPE == Variant::NIL) {
ERR_PRINT(("Missing VARIANT_ENUM_CAST for constant's enum: " + String(p_constant)).utf8().get_data());
}
@@ -251,24 +251,24 @@ public:
_FORCE_INLINE_ operator Variant() const { return value; }
};
#define TEMPL_MAKE_BITFIELD_TYPE_INFO(m_class, m_enum, m_impl) \
template <> \
struct GetTypeInfo<m_impl> { \
static const Variant::Type VARIANT_TYPE = Variant::INT; \
static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
static inline GDNativePropertyInfo get_class_info() { \
return make_property_info(GDNATIVE_VARIANT_TYPE_INT, "", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_CLASS_IS_BITFIELD, \
#m_class "." #m_enum); \
} \
}; \
template <> \
struct GetTypeInfo<BitField<m_impl>> { \
static const Variant::Type VARIANT_TYPE = Variant::INT; \
static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
static inline GDNativePropertyInfo get_class_info() { \
return make_property_info(GDNATIVE_VARIANT_TYPE_INT, "", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_CLASS_IS_BITFIELD, \
#m_class "." #m_enum); \
} \
#define TEMPL_MAKE_BITFIELD_TYPE_INFO(m_class, m_enum, m_impl) \
template <> \
struct GetTypeInfo<m_impl> { \
static const Variant::Type VARIANT_TYPE = Variant::INT; \
static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
static inline PropertyInfo get_class_info() { \
return make_property_info(Variant::Type::INT, "", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_CLASS_IS_BITFIELD, \
#m_class "." #m_enum); \
} \
}; \
template <> \
struct GetTypeInfo<BitField<m_impl>> { \
static const Variant::Type VARIANT_TYPE = Variant::INT; \
static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
static inline PropertyInfo get_class_info() { \
return make_property_info(Variant::Type::INT, "", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_CLASS_IS_BITFIELD, \
#m_class "." #m_enum); \
} \
};
#define MAKE_BITFIELD_TYPE_INFO(m_class, m_enum) \
@@ -309,8 +309,8 @@ template <typename T>
struct GetTypeInfo<TypedArray<T>> {
static constexpr GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_ARRAY;
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE;
static inline GDNativePropertyInfo get_class_info() {
return make_property_info(GDNATIVE_VARIANT_TYPE_ARRAY, "", PROPERTY_HINT_ARRAY_TYPE, T::get_class_static());
static inline PropertyInfo get_class_info() {
return make_property_info(Variant::Type::ARRAY, "", PROPERTY_HINT_ARRAY_TYPE, T::get_class_static());
}
};
@@ -318,27 +318,27 @@ template <typename T>
struct GetTypeInfo<const TypedArray<T> &> {
static constexpr GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_ARRAY;
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE;
static inline GDNativePropertyInfo get_class_info() {
return make_property_info(GDNATIVE_VARIANT_TYPE_ARRAY, "", PROPERTY_HINT_ARRAY_TYPE, T::get_class_static());
static inline PropertyInfo get_class_info() {
return make_property_info(Variant::Type::ARRAY, "", PROPERTY_HINT_ARRAY_TYPE, T::get_class_static());
}
};
#define MAKE_TYPED_ARRAY_INFO(m_type, m_variant_type) \
template <> \
struct GetTypeInfo<TypedArray<m_type>> { \
static constexpr GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_ARRAY; \
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
static inline GDNativePropertyInfo get_class_info() { \
return make_property_info(GDNATIVE_VARIANT_TYPE_ARRAY, "", PROPERTY_HINT_ARRAY_TYPE, Variant::get_type_name(m_variant_type).utf8().get_data()); \
} \
}; \
template <> \
struct GetTypeInfo<const TypedArray<m_type> &> { \
static constexpr GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_ARRAY; \
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
static inline GDNativePropertyInfo get_class_info() { \
return make_property_info(GDNATIVE_VARIANT_TYPE_ARRAY, "", PROPERTY_HINT_ARRAY_TYPE, Variant::get_type_name(m_variant_type).utf8().get_data()); \
} \
#define MAKE_TYPED_ARRAY_INFO(m_type, m_variant_type) \
template <> \
struct GetTypeInfo<TypedArray<m_type>> { \
static constexpr GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_ARRAY; \
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
static inline PropertyInfo get_class_info() { \
return make_property_info(Variant::Type::ARRAY, "", PROPERTY_HINT_ARRAY_TYPE, Variant::get_type_name(m_variant_type).utf8().get_data()); \
} \
}; \
template <> \
struct GetTypeInfo<const TypedArray<m_type> &> { \
static constexpr GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_ARRAY; \
static constexpr GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; \
static inline PropertyInfo get_class_info() { \
return make_property_info(Variant::Type::ARRAY, "", PROPERTY_HINT_ARRAY_TYPE, Variant::get_type_name(m_variant_type).utf8().get_data()); \
} \
};
MAKE_TYPED_ARRAY_INFO(bool, Variant::BOOL)