diff --git a/src/entt/meta/factory.hpp b/src/entt/meta/factory.hpp index 095ef9019..758fb4588 100644 --- a/src/entt/meta/factory.hpp +++ b/src/entt/meta/factory.hpp @@ -76,14 +76,14 @@ template template -[[nodiscard]] bool setter([[maybe_unused]] meta_any instance, [[maybe_unused]] meta_any value) { +[[nodiscard]] bool setter([[maybe_unused]] meta_handle instance, [[maybe_unused]] meta_any value) { bool accepted = false; if constexpr(std::is_function_v>> || std::is_member_function_pointer_v) { using helper_type = meta_function_helper_t; using data_type = std::tuple_element_t, typename helper_type::args_type>; - if(auto * const clazz = instance.try_cast(); clazz) { + if(auto * const clazz = (*instance).try_cast(); clazz) { if(auto * const direct = value.try_cast(); direct || value.convert()) { std::invoke(Data, *clazz, direct ? *direct : value.cast()); accepted = true; @@ -93,7 +93,7 @@ template using data_type = std::remove_cv_t().*Data)>>; if constexpr(!std::is_array_v) { - if(auto * const clazz = instance.try_cast(); clazz) { + if(auto * const clazz = (*instance).try_cast(); clazz) { if(auto * const direct = value.try_cast(); direct || value.convert()) { std::invoke(Data, clazz) = (direct ? *direct : value.cast()); accepted = true; @@ -116,7 +116,7 @@ template template -[[nodiscard]] meta_any getter([[maybe_unused]] meta_any instance) { +[[nodiscard]] meta_any getter([[maybe_unused]] meta_handle instance) { auto dispatch = [](auto &&value) { if constexpr(std::is_same_v) { return meta_any{std::in_place_type, std::forward(value)}; @@ -129,13 +129,13 @@ template }; if constexpr(std::is_function_v>> || std::is_member_function_pointer_v) { - auto * const clazz = instance.try_cast(); + auto * const clazz = (*instance).try_cast(); return clazz ? dispatch(std::invoke(Data, *clazz)) : meta_any{}; } else if constexpr(std::is_member_object_pointer_v) { if constexpr(std::is_array_v().*Data)>>>) { return meta_any{}; } else { - auto * const clazz = instance.try_cast(); + auto * const clazz = (*instance).try_cast(); return clazz ? dispatch(std::invoke(Data, clazz)) : meta_any{}; } } else if constexpr(std::is_pointer_v>) { @@ -151,7 +151,7 @@ template template -[[nodiscard]] meta_any invoke([[maybe_unused]] meta_any instance, meta_any *args, std::index_sequence) { +[[nodiscard]] meta_any invoke([[maybe_unused]] meta_handle instance, meta_any *args, std::index_sequence) { using helper_type = meta_function_helper_t; auto dispatch = [](auto *... params) { @@ -179,7 +179,7 @@ template if constexpr(std::is_function_v>>) { return (std::get(direct) && ...) ? dispatch(std::get(direct)...) : meta_any{}; } else { - auto * const clazz = instance.try_cast(); + auto * const clazz = (*instance).try_cast(); return (clazz && (std::get(direct) && ...)) ? dispatch(clazz, std::get(direct)...) : meta_any{}; } } @@ -682,7 +682,7 @@ public: !std::is_member_function_pointer_v, &internal::meta_info, void, typename helper_type::return_type>>::resolve, &helper_type::arg, - [](meta_any instance, meta_any *args) { + [](meta_handle instance, meta_any *args) { return internal::invoke(std::move(instance), args, std::make_index_sequence>{}); } }; diff --git a/src/entt/meta/internal.hpp b/src/entt/meta/internal.hpp index 5682b8aad..978ba84c7 100644 --- a/src/entt/meta/internal.hpp +++ b/src/entt/meta/internal.hpp @@ -17,6 +17,7 @@ namespace entt { class meta_any; +struct meta_handle; /** @@ -78,8 +79,8 @@ struct meta_data_node { meta_prop_node * prop; const bool is_static; meta_type_node *(* const type)() ENTT_NOEXCEPT; - bool(* const set)(meta_any, meta_any); - meta_any(* const get)(meta_any); + bool(* const set)(meta_handle, meta_any); + meta_any(* const get)(meta_handle); }; @@ -94,7 +95,7 @@ struct meta_func_node { const bool is_static; meta_type_node *(* const ret)() ENTT_NOEXCEPT; meta_type_node *(* const arg)(size_type) ENTT_NOEXCEPT; - meta_any(* const invoke)(meta_any, meta_any *); + meta_any(* const invoke)(meta_handle, meta_any *); }; diff --git a/src/entt/meta/meta.hpp b/src/entt/meta/meta.hpp index fb3c93f4b..47ee85227 100644 --- a/src/entt/meta/meta.hpp +++ b/src/entt/meta/meta.hpp @@ -333,7 +333,7 @@ public: * @brief Indirection operator for aliasing construction. * @return A meta any that shares a reference to an unmanaged object. */ - [[nodiscard]] meta_any operator *() const ENTT_NOEXCEPT { + [[nodiscard]] meta_any operator*() const ENTT_NOEXCEPT { return ref(); } @@ -432,8 +432,8 @@ struct meta_handle { } /*! @copydoc meta_any::operator* */ - [[nodiscard]] meta_any operator *() const { - return *any; + [[nodiscard]] meta_any operator*() const { + return any; } private: @@ -711,7 +711,7 @@ struct meta_data { */ template bool set(meta_handle instance, Type &&value) const { - return node->set && node->set(*instance, std::forward(value)); + return node->set && node->set(std::move(instance), std::forward(value)); } /** @@ -724,7 +724,7 @@ struct meta_data { * @return A meta any containing the value of the underlying variable. */ [[nodiscard]] meta_any get(meta_handle instance) const { - return node->get(*instance); + return node->get(std::move(instance)); } /*! @copydoc meta_ctor::prop */ @@ -843,8 +843,18 @@ struct meta_func { */ template meta_any invoke(meta_handle instance, Args &&... args) const { - meta_any arguments[]{*instance, std::forward(args)...}; - return sizeof...(Args) == size() ? node->invoke(arguments[0], &arguments[sizeof...(Args) != 0]) : meta_any{}; + meta_any any{}; + + if(sizeof...(Args) == size()) { + if constexpr(sizeof...(Args) == 0) { + any = node->invoke(std::move(instance), nullptr); + } else { + meta_any arguments[]{std::forward(args)...}; + any = node->invoke(std::move(instance), arguments); + } + } + + return any; } /*! @copydoc meta_ctor::prop */