1010namespace rnexecutorch ::meta {
1111using namespace facebook ;
1212
13- // =========================================================================
14- // 1. Function Traits (Extracts Arity, Return Type, Args)
15- // =========================================================================
16-
17- template <typename T> struct FunctionTraits ;
18-
19- // Specialization for Member Functions
20- template <typename R, typename C, typename ... Args>
21- struct FunctionTraits <R (C::*)(Args...)> {
22- static constexpr std::size_t arity = sizeof ...(Args);
23- using return_type = R;
24- using args_tuple = std::tuple<Args...>;
25- };
26-
27- // Specialization for const Member Functions
28- template <typename R, typename C, typename ... Args>
29- struct FunctionTraits <R (C::*)(Args...) const > {
30- static constexpr std::size_t arity = sizeof ...(Args);
31- using return_type = R;
32- using args_tuple = std::tuple<Args...>;
33- };
34-
35- // =========================================================================
36- // 2. Argument Counting Helpers
37- // =========================================================================
38-
3913template <typename Model, typename R, typename ... Types>
4014constexpr std::size_t getArgumentCount (R (Model::*f)(Types...)) {
4115 return sizeof ...(Types);
@@ -46,10 +20,6 @@ constexpr std::size_t getArgumentCount(R (Model::*f)(Types...) const) {
4620 return sizeof ...(Types);
4721}
4822
49- // =========================================================================
50- // 3. JSI -> Tuple Conversion Logic
51- // =========================================================================
52-
5323template <typename ... Types, std::size_t ... I>
5424std::tuple<Types...> fillTupleFromArgs (std::index_sequence<I...>,
5525 const jsi::Value *args,
@@ -62,6 +32,7 @@ std::tuple<Types...> fillTupleFromArgs(std::index_sequence<I...>,
6232 * arguments for method supplied with a pointer. The types in the tuple are
6333 * inferred from the method pointer.
6434 */
35+
6536template <typename Model, typename R, typename ... Types>
6637std::tuple<Types...> createArgsTupleFromJsi (R (Model::*f)(Types...),
6738 const jsi::Value *args,
@@ -78,7 +49,9 @@ std::tuple<Types...> createArgsTupleFromJsi(R (Model::*f)(Types...) const,
7849 runtime);
7950}
8051
81- // Overload for free functions (used by TailSignature dummy)
52+ // Free function overload used by visionHostFunction: accepts a dummy free
53+ // function pointer whose parameter types (Rest...) are extracted by
54+ // TailSignature and converted from JSI args.
8255template <typename ... Types>
8356std::tuple<Types...> createArgsTupleFromJsi (void (*f)(Types...),
8457 const jsi::Value *args,
@@ -87,27 +60,40 @@ std::tuple<Types...> createArgsTupleFromJsi(void (*f)(Types...),
8760 runtime);
8861}
8962
90- // =========================================================================
91- // 4. Tail Signature Helper (Crucial for Vision Functions)
92- // =========================================================================
63+ // Extracts arity, return type, and argument types from a member function
64+ // pointer at compile time. Used by visionHostFunction to determine the expected
65+ // JS argument count and invoke the correct return path.
66+ template <typename T> struct FunctionTraits ;
67+
68+ template <typename R, typename C, typename ... Args>
69+ struct FunctionTraits <R (C::*)(Args...)> {
70+ static constexpr std::size_t arity = sizeof ...(Args);
71+ using return_type = R;
72+ using args_tuple = std::tuple<Args...>;
73+ };
74+
75+ template <typename R, typename C, typename ... Args>
76+ struct FunctionTraits <R (C::*)(Args...) const > {
77+ static constexpr std::size_t arity = sizeof ...(Args);
78+ using return_type = R;
79+ using args_tuple = std::tuple<Args...>;
80+ };
9381
94- // Extracts the "Tail" arguments of a function signature, skipping the first
95- // two arguments (Runtime and FrameValue).
82+ // Strips the first two parameters (Runtime& and jsi::Value&) from a member
83+ // function pointer and exposes the remaining types as a dummy free function.
84+ // Used by visionHostFunction to parse only the tail JS args via
85+ // createArgsTupleFromJsi, while frameData at args[0] is passed manually.
9686template <typename T> struct TailSignature ;
9787
98- // Non-const member function specialization
9988template <typename R, typename C, typename Arg1, typename Arg2,
10089 typename ... Rest>
10190struct TailSignature <R (C::*)(Arg1, Arg2, Rest...)> {
102- // A dummy function that has the signature of just the "Rest" arguments.
10391 static void dummy (Rest...) {}
10492};
10593
106- // Const member function specialization
10794template <typename R, typename C, typename Arg1, typename Arg2,
10895 typename ... Rest>
10996struct TailSignature <R (C::*)(Arg1, Arg2, Rest...) const > {
11097 static void dummy (Rest...) {}
11198};
112-
11399} // namespace rnexecutorch::meta
0 commit comments