Browse Source

meta: ctors and funcs also accept a meta_any * + size pair (close #528)

Michele Caini 5 years ago
parent
commit
5056972f79
1 changed files with 49 additions and 9 deletions
  1. 49 9
      src/entt/meta/meta.hpp

+ 49 - 9
src/entt/meta/meta.hpp

@@ -694,6 +694,19 @@ struct meta_ctor {
      * conversion to the required types is possible. Otherwise, an empty and
      * thus invalid wrapper is returned.
      *
+     * @param args Parameters to use to construct the instance.
+     * @param sz Number of parameters to use to construct the instance.
+     * @return A meta any containing the new instance, if any.
+     */
+    [[nodiscard]] meta_any invoke(meta_any * const args, const std::size_t sz) const {
+        return sz == size() ? node->invoke(args) : meta_any{};
+    }
+
+    /**
+     * @copybrief invoke
+     *
+     * @sa invoke
+     *
      * @tparam Args Types of arguments to use to construct the instance.
      * @param args Parameters to use to construct the instance.
      * @return A meta any containing the new instance, if any.
@@ -701,7 +714,7 @@ struct meta_ctor {
     template<typename... Args>
     [[nodiscard]] meta_any invoke([[maybe_unused]] Args &&... args) const {
         std::array<meta_any, sizeof...(Args)> arguments{std::forward<Args>(args)...};
-        return sizeof...(Args) == size() ? node->invoke(arguments.data()) : meta_any{};
+        return invoke(arguments.data(), sizeof...(Args));
     }
 
     /**
@@ -899,15 +912,29 @@ struct meta_func {
      * function. Otherwise, invoking the underlying function results in an
      * undefined behavior.
      *
-     * @tparam Args Types of arguments to use to invoke the function.
      * @param instance An opaque instance of the underlying type.
      * @param args Parameters to use to invoke the function.
+     * @param sz Number of parameters to use to invoke the function.
      * @return A meta any containing the returned value, if any.
      */
+    [[nodiscard]] meta_any invoke(meta_handle instance, meta_any * const args, const std::size_t sz) const {
+        return sz == size() ? node->invoke(instance, args) : meta_any{};
+    }
+
+    /**
+     * @copybrief invoke
+     *
+     * @sa invoke
+     *
+     * @tparam Args Types of arguments to use to invoke the function.
+     * @param instance An opaque instance of the underlying type.
+     * @param args Parameters to use to invoke the function.
+     * @return A meta any containing the new instance, if any.
+     */
     template<typename... Args>
     meta_any invoke(meta_handle instance, Args &&... args) const {
         std::array<meta_any, sizeof...(Args)> arguments{std::forward<Args>(args)...};
-        return sizeof...(Args) == size() ? node->invoke(instance, arguments.data()) : meta_any{};
+        return invoke(instance, arguments.data(), sizeof...(Args));
     }
 
     /*! @copydoc meta_ctor::prop */
@@ -1250,22 +1277,35 @@ public:
      * conversion to the required types is possible. Otherwise, an empty and
      * thus invalid wrapper is returned.
      *
-     * @tparam Args Types of arguments to use to construct the instance.
      * @param args Parameters to use to construct the instance.
+     * @param sz Number of parameters to use to construct the instance.
      * @return A meta any containing the new instance, if any.
      */
-    template<typename... Args>
-    [[nodiscard]] meta_any construct(Args &&... args) const {
-        std::array<meta_any, sizeof...(Args)> arguments{std::forward<Args>(args)...};
+    [[nodiscard]] meta_any construct(meta_any * const args, const std::size_t sz) const {
         meta_any any{};
 
-        internal::find_if<&node_type::ctor>([&arguments, &any](const auto *curr) {
-            return (curr->size == sizeof...(args)) && (any = curr->invoke(arguments.data()));
+        internal::find_if<&node_type::ctor>([args, sz, &any](const auto *curr) {
+            return (curr->size == sz) && (any = curr->invoke(args));
         }, node);
 
         return any;
     }
 
+    /**
+     * @copybrief construct
+     *
+     * @sa construct
+     *
+     * @tparam Args Types of arguments to use to construct the instance.
+     * @param args Parameters to use to construct the instance.
+     * @return A meta any containing the new instance, if any.
+     */
+    template<typename... Args>
+    [[nodiscard]] meta_any construct(Args &&... args) const {
+        std::array<meta_any, sizeof...(Args)> arguments{std::forward<Args>(args)...};
+        return construct(arguments.data(), sizeof...(Args));
+    }
+
     /**
      * @brief Returns a range to use to visit top-level meta properties.
      * @return An iterable range to use to visit top-level meta properties.