binder_common.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942
  1. /**************************************************************************/
  2. /* binder_common.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #pragma once
  31. #include "core/input/input_enums.h"
  32. #include "core/object/object.h"
  33. #include "core/os/keyboard.h"
  34. #include "core/templates/simple_type.h"
  35. #include "core/typedefs.h"
  36. #include "core/variant/method_ptrcall.h"
  37. #include "core/variant/type_info.h"
  38. #include "core/variant/variant.h"
  39. #include "core/variant/variant_internal.h"
  40. #include <cstdio>
  41. // Variant cannot define an implicit cast operator for every Object subclass, so the
  42. // casting is done here, to allow binding methods with parameters more specific than Object *
  43. template <typename T>
  44. struct VariantCaster {
  45. static _FORCE_INLINE_ T cast(const Variant &p_variant) {
  46. using TStripped = std::remove_pointer_t<T>;
  47. if constexpr (std::is_base_of_v<Object, TStripped>) {
  48. return Object::cast_to<TStripped>(p_variant);
  49. } else {
  50. return p_variant;
  51. }
  52. }
  53. };
  54. template <typename T>
  55. struct VariantCaster<T &> {
  56. static _FORCE_INLINE_ T cast(const Variant &p_variant) {
  57. using TStripped = std::remove_pointer_t<T>;
  58. if constexpr (std::is_base_of_v<Object, TStripped>) {
  59. return Object::cast_to<TStripped>(p_variant);
  60. } else {
  61. return p_variant;
  62. }
  63. }
  64. };
  65. template <typename T>
  66. struct VariantCaster<const T &> {
  67. static _FORCE_INLINE_ T cast(const Variant &p_variant) {
  68. using TStripped = std::remove_pointer_t<T>;
  69. if constexpr (std::is_base_of_v<Object, TStripped>) {
  70. return Object::cast_to<TStripped>(p_variant);
  71. } else {
  72. return p_variant;
  73. }
  74. }
  75. };
  76. #define VARIANT_ENUM_CAST(m_enum) MAKE_ENUM_TYPE_INFO(m_enum)
  77. #define VARIANT_BITFIELD_CAST(m_enum) MAKE_BITFIELD_TYPE_INFO(m_enum)
  78. // Object enum casts must go here
  79. VARIANT_ENUM_CAST(Object::ConnectFlags);
  80. VARIANT_ENUM_CAST(Vector2::Axis);
  81. VARIANT_ENUM_CAST(Vector2i::Axis);
  82. VARIANT_ENUM_CAST(Vector3::Axis);
  83. VARIANT_ENUM_CAST(Vector3i::Axis);
  84. VARIANT_ENUM_CAST(Vector4::Axis);
  85. VARIANT_ENUM_CAST(Vector4i::Axis);
  86. VARIANT_ENUM_CAST(EulerOrder);
  87. VARIANT_ENUM_CAST(Projection::Planes);
  88. VARIANT_ENUM_CAST(Error);
  89. VARIANT_ENUM_CAST(Side);
  90. VARIANT_ENUM_CAST(ClockDirection);
  91. VARIANT_ENUM_CAST(Corner);
  92. VARIANT_ENUM_CAST(HatDir);
  93. VARIANT_BITFIELD_CAST(HatMask);
  94. VARIANT_ENUM_CAST(JoyAxis);
  95. VARIANT_ENUM_CAST(JoyButton);
  96. VARIANT_ENUM_CAST(MIDIMessage);
  97. VARIANT_ENUM_CAST(MouseButton);
  98. VARIANT_BITFIELD_CAST(MouseButtonMask);
  99. VARIANT_ENUM_CAST(Orientation);
  100. VARIANT_ENUM_CAST(HorizontalAlignment);
  101. VARIANT_ENUM_CAST(VerticalAlignment);
  102. VARIANT_ENUM_CAST(InlineAlignment);
  103. VARIANT_ENUM_CAST(PropertyHint);
  104. VARIANT_BITFIELD_CAST(PropertyUsageFlags);
  105. VARIANT_ENUM_CAST(Variant::Type);
  106. VARIANT_ENUM_CAST(Variant::Operator);
  107. // Key
  108. VARIANT_ENUM_CAST(Key);
  109. VARIANT_BITFIELD_CAST(KeyModifierMask);
  110. VARIANT_ENUM_CAST(KeyLocation);
  111. template <>
  112. struct VariantCaster<char32_t> {
  113. static _FORCE_INLINE_ char32_t cast(const Variant &p_variant) {
  114. return (char32_t)p_variant.operator int();
  115. }
  116. };
  117. template <>
  118. struct PtrToArg<char32_t> {
  119. _FORCE_INLINE_ static char32_t convert(const void *p_ptr) {
  120. return char32_t(*reinterpret_cast<const int64_t *>(p_ptr));
  121. }
  122. typedef int64_t EncodeT;
  123. _FORCE_INLINE_ static void encode(char32_t p_val, const void *p_ptr) {
  124. *(int64_t *)p_ptr = p_val;
  125. }
  126. };
  127. template <typename T>
  128. struct VariantObjectClassChecker {
  129. static _FORCE_INLINE_ bool check(const Variant &p_variant) {
  130. using TStripped = std::remove_pointer_t<T>;
  131. if constexpr (std::is_base_of_v<Object, TStripped>) {
  132. Object *obj = p_variant;
  133. return Object::cast_to<TStripped>(p_variant) || !obj;
  134. } else {
  135. return true;
  136. }
  137. }
  138. };
  139. template <typename T>
  140. class Ref;
  141. template <typename T>
  142. struct VariantObjectClassChecker<const Ref<T> &> {
  143. static _FORCE_INLINE_ bool check(const Variant &p_variant) {
  144. Object *obj = p_variant;
  145. const Ref<T> node = p_variant;
  146. return node.ptr() || !obj;
  147. }
  148. };
  149. #ifdef DEBUG_METHODS_ENABLED
  150. template <typename T>
  151. struct VariantCasterAndValidate {
  152. static _FORCE_INLINE_ T cast(const Variant **p_args, uint32_t p_arg_idx, Callable::CallError &r_error) {
  153. Variant::Type argtype = GetTypeInfo<T>::VARIANT_TYPE;
  154. if (!Variant::can_convert_strict(p_args[p_arg_idx]->get_type(), argtype) ||
  155. !VariantObjectClassChecker<T>::check(*p_args[p_arg_idx])) {
  156. r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
  157. r_error.argument = p_arg_idx;
  158. r_error.expected = argtype;
  159. }
  160. return VariantCaster<T>::cast(*p_args[p_arg_idx]);
  161. }
  162. };
  163. template <typename T>
  164. struct VariantCasterAndValidate<T &> {
  165. static _FORCE_INLINE_ T cast(const Variant **p_args, uint32_t p_arg_idx, Callable::CallError &r_error) {
  166. Variant::Type argtype = GetTypeInfo<T>::VARIANT_TYPE;
  167. if (!Variant::can_convert_strict(p_args[p_arg_idx]->get_type(), argtype) ||
  168. !VariantObjectClassChecker<T>::check(*p_args[p_arg_idx])) {
  169. r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
  170. r_error.argument = p_arg_idx;
  171. r_error.expected = argtype;
  172. }
  173. return VariantCaster<T>::cast(*p_args[p_arg_idx]);
  174. }
  175. };
  176. template <typename T>
  177. struct VariantCasterAndValidate<const T &> {
  178. static _FORCE_INLINE_ T cast(const Variant **p_args, uint32_t p_arg_idx, Callable::CallError &r_error) {
  179. Variant::Type argtype = GetTypeInfo<T>::VARIANT_TYPE;
  180. if (!Variant::can_convert_strict(p_args[p_arg_idx]->get_type(), argtype) ||
  181. !VariantObjectClassChecker<T>::check(*p_args[p_arg_idx])) {
  182. r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
  183. r_error.argument = p_arg_idx;
  184. r_error.expected = argtype;
  185. }
  186. return VariantCaster<T>::cast(*p_args[p_arg_idx]);
  187. }
  188. };
  189. #endif // DEBUG_METHODS_ENABLED
  190. template <typename T, typename... P, size_t... Is>
  191. void call_with_variant_args_helper(T *p_instance, void (T::*p_method)(P...), const Variant **p_args, Callable::CallError &r_error, IndexSequence<Is...>) {
  192. r_error.error = Callable::CallError::CALL_OK;
  193. #ifdef DEBUG_METHODS_ENABLED
  194. (p_instance->*p_method)(VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...);
  195. #else
  196. (p_instance->*p_method)(VariantCaster<P>::cast(*p_args[Is])...);
  197. #endif
  198. (void)(p_args); //avoid warning
  199. }
  200. template <typename T, typename... P, size_t... Is>
  201. void call_with_variant_argsc_helper(T *p_instance, void (T::*p_method)(P...) const, const Variant **p_args, Callable::CallError &r_error, IndexSequence<Is...>) {
  202. r_error.error = Callable::CallError::CALL_OK;
  203. #ifdef DEBUG_METHODS_ENABLED
  204. (p_instance->*p_method)(VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...);
  205. #else
  206. (p_instance->*p_method)(VariantCaster<P>::cast(*p_args[Is])...);
  207. #endif
  208. (void)(p_args); //avoid warning
  209. }
  210. template <typename T, typename... P, size_t... Is>
  211. void call_with_ptr_args_helper(T *p_instance, void (T::*p_method)(P...), const void **p_args, IndexSequence<Is...>) {
  212. (p_instance->*p_method)(PtrToArg<P>::convert(p_args[Is])...);
  213. }
  214. template <typename T, typename... P, size_t... Is>
  215. void call_with_ptr_argsc_helper(T *p_instance, void (T::*p_method)(P...) const, const void **p_args, IndexSequence<Is...>) {
  216. (p_instance->*p_method)(PtrToArg<P>::convert(p_args[Is])...);
  217. }
  218. template <typename T, typename R, typename... P, size_t... Is>
  219. void call_with_ptr_args_ret_helper(T *p_instance, R (T::*p_method)(P...), const void **p_args, void *r_ret, IndexSequence<Is...>) {
  220. PtrToArg<R>::encode((p_instance->*p_method)(PtrToArg<P>::convert(p_args[Is])...), r_ret);
  221. }
  222. template <typename T, typename R, typename... P, size_t... Is>
  223. void call_with_ptr_args_retc_helper(T *p_instance, R (T::*p_method)(P...) const, const void **p_args, void *r_ret, IndexSequence<Is...>) {
  224. PtrToArg<R>::encode((p_instance->*p_method)(PtrToArg<P>::convert(p_args[Is])...), r_ret);
  225. }
  226. template <typename T, typename... P, size_t... Is>
  227. void call_with_ptr_args_static_helper(T *p_instance, void (*p_method)(T *, P...), const void **p_args, IndexSequence<Is...>) {
  228. p_method(p_instance, PtrToArg<P>::convert(p_args[Is])...);
  229. }
  230. template <typename T, typename R, typename... P, size_t... Is>
  231. void call_with_ptr_args_static_retc_helper(T *p_instance, R (*p_method)(T *, P...), const void **p_args, void *r_ret, IndexSequence<Is...>) {
  232. PtrToArg<R>::encode(p_method(p_instance, PtrToArg<P>::convert(p_args[Is])...), r_ret);
  233. }
  234. template <typename R, typename... P, size_t... Is>
  235. void call_with_ptr_args_static_method_ret_helper(R (*p_method)(P...), const void **p_args, void *r_ret, IndexSequence<Is...>) {
  236. PtrToArg<R>::encode(p_method(PtrToArg<P>::convert(p_args[Is])...), r_ret);
  237. }
  238. template <typename... P, size_t... Is>
  239. void call_with_ptr_args_static_method_helper(void (*p_method)(P...), const void **p_args, IndexSequence<Is...>) {
  240. p_method(PtrToArg<P>::convert(p_args[Is])...);
  241. }
  242. template <typename T, typename... P, size_t... Is>
  243. void call_with_validated_variant_args_helper(T *p_instance, void (T::*p_method)(P...), const Variant **p_args, IndexSequence<Is...>) {
  244. (p_instance->*p_method)((VariantInternalAccessor<GetSimpleTypeT<P>>::get(p_args[Is]))...);
  245. }
  246. template <typename T, typename... P, size_t... Is>
  247. void call_with_validated_variant_argsc_helper(T *p_instance, void (T::*p_method)(P...) const, const Variant **p_args, IndexSequence<Is...>) {
  248. (p_instance->*p_method)((VariantInternalAccessor<GetSimpleTypeT<P>>::get(p_args[Is]))...);
  249. }
  250. template <typename T, typename R, typename... P, size_t... Is>
  251. void call_with_validated_variant_args_ret_helper(T *p_instance, R (T::*p_method)(P...), const Variant **p_args, Variant *r_ret, IndexSequence<Is...>) {
  252. VariantInternalAccessor<GetSimpleTypeT<R>>::set(r_ret, (p_instance->*p_method)((VariantInternalAccessor<GetSimpleTypeT<P>>::get(p_args[Is]))...));
  253. }
  254. template <typename T, typename R, typename... P, size_t... Is>
  255. void call_with_validated_variant_args_retc_helper(T *p_instance, R (T::*p_method)(P...) const, const Variant **p_args, Variant *r_ret, IndexSequence<Is...>) {
  256. VariantInternalAccessor<GetSimpleTypeT<R>>::set(r_ret, (p_instance->*p_method)((VariantInternalAccessor<GetSimpleTypeT<P>>::get(p_args[Is]))...));
  257. }
  258. template <typename T, typename R, typename... P, size_t... Is>
  259. void call_with_validated_variant_args_static_retc_helper(T *p_instance, R (*p_method)(T *, P...), const Variant **p_args, Variant *r_ret, IndexSequence<Is...>) {
  260. VariantInternalAccessor<GetSimpleTypeT<R>>::set(r_ret, p_method(p_instance, (VariantInternalAccessor<GetSimpleTypeT<P>>::get(p_args[Is]))...));
  261. }
  262. template <typename T, typename... P, size_t... Is>
  263. void call_with_validated_variant_args_static_helper(T *p_instance, void (*p_method)(T *, P...), const Variant **p_args, IndexSequence<Is...>) {
  264. p_method(p_instance, (VariantInternalAccessor<GetSimpleTypeT<P>>::get(p_args[Is]))...);
  265. }
  266. template <typename R, typename... P, size_t... Is>
  267. void call_with_validated_variant_args_static_method_ret_helper(R (*p_method)(P...), const Variant **p_args, Variant *r_ret, IndexSequence<Is...>) {
  268. VariantInternalAccessor<GetSimpleTypeT<R>>::set(r_ret, p_method((VariantInternalAccessor<GetSimpleTypeT<P>>::get(p_args[Is]))...));
  269. }
  270. template <typename... P, size_t... Is>
  271. void call_with_validated_variant_args_static_method_helper(void (*p_method)(P...), const Variant **p_args, IndexSequence<Is...>) {
  272. p_method((VariantInternalAccessor<GetSimpleTypeT<P>>::get(p_args[Is]))...);
  273. }
  274. template <typename T, typename... P>
  275. void call_with_variant_args(T *p_instance, void (T::*p_method)(P...), const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
  276. #ifdef DEBUG_METHODS_ENABLED
  277. if ((size_t)p_argcount > sizeof...(P)) {
  278. r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
  279. r_error.expected = sizeof...(P);
  280. return;
  281. }
  282. if ((size_t)p_argcount < sizeof...(P)) {
  283. r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  284. r_error.expected = sizeof...(P);
  285. return;
  286. }
  287. #endif
  288. call_with_variant_args_helper<T, P...>(p_instance, p_method, p_args, r_error, BuildIndexSequence<sizeof...(P)>{});
  289. }
  290. template <typename T, typename... P>
  291. void call_with_variant_args_dv(T *p_instance, void (T::*p_method)(P...), const Variant **p_args, int p_argcount, Callable::CallError &r_error, const Vector<Variant> &default_values) {
  292. #ifdef DEBUG_ENABLED
  293. if ((size_t)p_argcount > sizeof...(P)) {
  294. r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
  295. r_error.expected = sizeof...(P);
  296. return;
  297. }
  298. #endif
  299. int32_t missing = (int32_t)sizeof...(P) - (int32_t)p_argcount;
  300. int32_t dvs = default_values.size();
  301. #ifdef DEBUG_ENABLED
  302. if (missing > dvs) {
  303. r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  304. r_error.expected = sizeof...(P);
  305. return;
  306. }
  307. #endif
  308. const Variant *args[sizeof...(P) == 0 ? 1 : sizeof...(P)]; //avoid zero sized array
  309. for (int32_t i = 0; i < (int32_t)sizeof...(P); i++) {
  310. if (i < p_argcount) {
  311. args[i] = p_args[i];
  312. } else {
  313. args[i] = &default_values[i - p_argcount + (dvs - missing)];
  314. }
  315. }
  316. call_with_variant_args_helper(p_instance, p_method, args, r_error, BuildIndexSequence<sizeof...(P)>{});
  317. }
  318. template <typename T, typename... P>
  319. void call_with_variant_argsc(T *p_instance, void (T::*p_method)(P...) const, const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
  320. #ifdef DEBUG_METHODS_ENABLED
  321. if ((size_t)p_argcount > sizeof...(P)) {
  322. r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
  323. r_error.expected = sizeof...(P);
  324. return;
  325. }
  326. if ((size_t)p_argcount < sizeof...(P)) {
  327. r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  328. r_error.expected = sizeof...(P);
  329. return;
  330. }
  331. #endif
  332. call_with_variant_argsc_helper<T, P...>(p_instance, p_method, p_args, r_error, BuildIndexSequence<sizeof...(P)>{});
  333. }
  334. template <typename T, typename... P>
  335. void call_with_variant_argsc_dv(T *p_instance, void (T::*p_method)(P...) const, const Variant **p_args, int p_argcount, Callable::CallError &r_error, const Vector<Variant> &default_values) {
  336. #ifdef DEBUG_ENABLED
  337. if ((size_t)p_argcount > sizeof...(P)) {
  338. r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
  339. r_error.expected = sizeof...(P);
  340. return;
  341. }
  342. #endif
  343. int32_t missing = (int32_t)sizeof...(P) - (int32_t)p_argcount;
  344. int32_t dvs = default_values.size();
  345. #ifdef DEBUG_ENABLED
  346. if (missing > dvs) {
  347. r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  348. r_error.expected = sizeof...(P);
  349. return;
  350. }
  351. #endif
  352. const Variant *args[sizeof...(P) == 0 ? 1 : sizeof...(P)]; //avoid zero sized array
  353. for (int32_t i = 0; i < (int32_t)sizeof...(P); i++) {
  354. if (i < p_argcount) {
  355. args[i] = p_args[i];
  356. } else {
  357. args[i] = &default_values[i - p_argcount + (dvs - missing)];
  358. }
  359. }
  360. call_with_variant_argsc_helper(p_instance, p_method, args, r_error, BuildIndexSequence<sizeof...(P)>{});
  361. }
  362. template <typename T, typename R, typename... P>
  363. void call_with_variant_args_ret_dv(T *p_instance, R (T::*p_method)(P...), const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error, const Vector<Variant> &default_values) {
  364. #ifdef DEBUG_ENABLED
  365. if ((size_t)p_argcount > sizeof...(P)) {
  366. r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
  367. r_error.expected = sizeof...(P);
  368. return;
  369. }
  370. #endif
  371. int32_t missing = (int32_t)sizeof...(P) - (int32_t)p_argcount;
  372. int32_t dvs = default_values.size();
  373. #ifdef DEBUG_ENABLED
  374. if (missing > dvs) {
  375. r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  376. r_error.expected = sizeof...(P);
  377. return;
  378. }
  379. #endif
  380. const Variant *args[sizeof...(P) == 0 ? 1 : sizeof...(P)]; //avoid zero sized array
  381. for (int32_t i = 0; i < (int32_t)sizeof...(P); i++) {
  382. if (i < p_argcount) {
  383. args[i] = p_args[i];
  384. } else {
  385. args[i] = &default_values[i - p_argcount + (dvs - missing)];
  386. }
  387. }
  388. call_with_variant_args_ret_helper(p_instance, p_method, args, r_ret, r_error, BuildIndexSequence<sizeof...(P)>{});
  389. }
  390. template <typename T, typename R, typename... P>
  391. void call_with_variant_args_retc_dv(T *p_instance, R (T::*p_method)(P...) const, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error, const Vector<Variant> &default_values) {
  392. #ifdef DEBUG_ENABLED
  393. if ((size_t)p_argcount > sizeof...(P)) {
  394. r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
  395. r_error.expected = sizeof...(P);
  396. return;
  397. }
  398. #endif
  399. int32_t missing = (int32_t)sizeof...(P) - (int32_t)p_argcount;
  400. int32_t dvs = default_values.size();
  401. #ifdef DEBUG_ENABLED
  402. if (missing > dvs) {
  403. r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  404. r_error.expected = sizeof...(P);
  405. return;
  406. }
  407. #endif
  408. const Variant *args[sizeof...(P) == 0 ? 1 : sizeof...(P)]; //avoid zero sized array
  409. for (int32_t i = 0; i < (int32_t)sizeof...(P); i++) {
  410. if (i < p_argcount) {
  411. args[i] = p_args[i];
  412. } else {
  413. args[i] = &default_values[i - p_argcount + (dvs - missing)];
  414. }
  415. }
  416. call_with_variant_args_retc_helper(p_instance, p_method, args, r_ret, r_error, BuildIndexSequence<sizeof...(P)>{});
  417. }
  418. template <typename T, typename... P>
  419. void call_with_ptr_args(T *p_instance, void (T::*p_method)(P...), const void **p_args) {
  420. call_with_ptr_args_helper<T, P...>(p_instance, p_method, p_args, BuildIndexSequence<sizeof...(P)>{});
  421. }
  422. template <typename T, typename... P>
  423. void call_with_ptr_argsc(T *p_instance, void (T::*p_method)(P...) const, const void **p_args) {
  424. call_with_ptr_argsc_helper<T, P...>(p_instance, p_method, p_args, BuildIndexSequence<sizeof...(P)>{});
  425. }
  426. template <typename T, typename R, typename... P>
  427. void call_with_ptr_args_ret(T *p_instance, R (T::*p_method)(P...), const void **p_args, void *r_ret) {
  428. call_with_ptr_args_ret_helper<T, R, P...>(p_instance, p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{});
  429. }
  430. template <typename T, typename R, typename... P>
  431. void call_with_ptr_args_retc(T *p_instance, R (T::*p_method)(P...) const, const void **p_args, void *r_ret) {
  432. call_with_ptr_args_retc_helper<T, R, P...>(p_instance, p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{});
  433. }
  434. template <typename T, typename... P>
  435. void call_with_ptr_args_static(T *p_instance, void (*p_method)(T *, P...), const void **p_args) {
  436. call_with_ptr_args_static_helper<T, P...>(p_instance, p_method, p_args, BuildIndexSequence<sizeof...(P)>{});
  437. }
  438. template <typename T, typename R, typename... P>
  439. void call_with_ptr_args_static_retc(T *p_instance, R (*p_method)(T *, P...), const void **p_args, void *r_ret) {
  440. call_with_ptr_args_static_retc_helper<T, R, P...>(p_instance, p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{});
  441. }
  442. template <typename R, typename... P>
  443. void call_with_ptr_args_static_method_ret(R (*p_method)(P...), const void **p_args, void *r_ret) {
  444. call_with_ptr_args_static_method_ret_helper<R, P...>(p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{});
  445. }
  446. template <typename... P>
  447. void call_with_ptr_args_static_method(void (*p_method)(P...), const void **p_args) {
  448. call_with_ptr_args_static_method_helper<P...>(p_method, p_args, BuildIndexSequence<sizeof...(P)>{});
  449. }
  450. // Validated
  451. template <typename T, typename... P>
  452. void call_with_validated_variant_args(Variant *base, void (T::*p_method)(P...), const Variant **p_args) {
  453. call_with_validated_variant_args_helper<T, P...>(VariantGetInternalPtr<T>::get_ptr(base), p_method, p_args, BuildIndexSequence<sizeof...(P)>{});
  454. }
  455. template <typename T, typename R, typename... P>
  456. void call_with_validated_variant_args_ret(Variant *base, R (T::*p_method)(P...), const Variant **p_args, Variant *r_ret) {
  457. call_with_validated_variant_args_ret_helper<T, R, P...>(VariantGetInternalPtr<T>::get_ptr(base), p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{});
  458. }
  459. template <typename T, typename R, typename... P>
  460. void call_with_validated_variant_args_retc(Variant *base, R (T::*p_method)(P...) const, const Variant **p_args, Variant *r_ret) {
  461. call_with_validated_variant_args_retc_helper<T, R, P...>(VariantGetInternalPtr<T>::get_ptr(base), p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{});
  462. }
  463. template <typename T, typename... P>
  464. void call_with_validated_variant_args_static(Variant *base, void (*p_method)(T *, P...), const Variant **p_args) {
  465. call_with_validated_variant_args_static_helper<T, P...>(VariantGetInternalPtr<T>::get_ptr(base), p_method, p_args, BuildIndexSequence<sizeof...(P)>{});
  466. }
  467. template <typename T, typename R, typename... P>
  468. void call_with_validated_variant_args_static_retc(Variant *base, R (*p_method)(T *, P...), const Variant **p_args, Variant *r_ret) {
  469. call_with_validated_variant_args_static_retc_helper<T, R, P...>(VariantGetInternalPtr<T>::get_ptr(base), p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{});
  470. }
  471. template <typename... P>
  472. void call_with_validated_variant_args_static_method(void (*p_method)(P...), const Variant **p_args) {
  473. call_with_validated_variant_args_static_method_helper<P...>(p_method, p_args, BuildIndexSequence<sizeof...(P)>{});
  474. }
  475. template <typename R, typename... P>
  476. void call_with_validated_variant_args_static_method_ret(R (*p_method)(P...), const Variant **p_args, Variant *r_ret) {
  477. call_with_validated_variant_args_static_method_ret_helper<R, P...>(p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{});
  478. }
  479. // Validated Object
  480. template <typename T, typename... P>
  481. void call_with_validated_object_instance_args(T *base, void (T::*p_method)(P...), const Variant **p_args) {
  482. call_with_validated_variant_args_helper<T, P...>(base, p_method, p_args, BuildIndexSequence<sizeof...(P)>{});
  483. }
  484. template <typename T, typename... P>
  485. void call_with_validated_object_instance_argsc(T *base, void (T::*p_method)(P...) const, const Variant **p_args) {
  486. call_with_validated_variant_argsc_helper<T, P...>(base, p_method, p_args, BuildIndexSequence<sizeof...(P)>{});
  487. }
  488. template <typename T, typename R, typename... P>
  489. void call_with_validated_object_instance_args_ret(T *base, R (T::*p_method)(P...), const Variant **p_args, Variant *r_ret) {
  490. call_with_validated_variant_args_ret_helper<T, R, P...>(base, p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{});
  491. }
  492. template <typename T, typename R, typename... P>
  493. void call_with_validated_object_instance_args_retc(T *base, R (T::*p_method)(P...) const, const Variant **p_args, Variant *r_ret) {
  494. call_with_validated_variant_args_retc_helper<T, R, P...>(base, p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{});
  495. }
  496. template <typename T, typename... P>
  497. void call_with_validated_object_instance_args_static(T *base, void (*p_method)(T *, P...), const Variant **p_args) {
  498. call_with_validated_variant_args_static_helper<T, P...>(base, p_method, p_args, BuildIndexSequence<sizeof...(P)>{});
  499. }
  500. template <typename T, typename R, typename... P>
  501. void call_with_validated_object_instance_args_static_retc(T *base, R (*p_method)(T *, P...), const Variant **p_args, Variant *r_ret) {
  502. call_with_validated_variant_args_static_retc_helper<T, R, P...>(base, p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{});
  503. }
  504. // GCC raises "parameter 'p_args' set but not used" when P = {},
  505. // it's not clever enough to treat other P values as making this branch valid.
  506. GODOT_GCC_WARNING_PUSH_AND_IGNORE("-Wunused-but-set-parameter")
  507. template <typename Q>
  508. void call_get_argument_type_helper(int p_arg, int &index, Variant::Type &type) {
  509. if (p_arg == index) {
  510. type = GetTypeInfo<Q>::VARIANT_TYPE;
  511. }
  512. index++;
  513. }
  514. template <typename... P>
  515. Variant::Type call_get_argument_type(int p_arg) {
  516. Variant::Type type = Variant::NIL;
  517. int index = 0;
  518. // I think rocket science is simpler than modern C++.
  519. using expand_type = int[];
  520. expand_type a{ 0, (call_get_argument_type_helper<P>(p_arg, index, type), 0)... };
  521. (void)a; // Suppress (valid, but unavoidable) -Wunused-variable warning.
  522. (void)index; // Suppress GCC warning.
  523. return type;
  524. }
  525. template <typename Q>
  526. void call_get_argument_type_info_helper(int p_arg, int &index, PropertyInfo &info) {
  527. if (p_arg == index) {
  528. info = GetTypeInfo<Q>::get_class_info();
  529. }
  530. index++;
  531. }
  532. template <typename... P>
  533. void call_get_argument_type_info(int p_arg, PropertyInfo &info) {
  534. int index = 0;
  535. // I think rocket science is simpler than modern C++.
  536. using expand_type = int[];
  537. expand_type a{ 0, (call_get_argument_type_info_helper<P>(p_arg, index, info), 0)... };
  538. (void)a; // Suppress (valid, but unavoidable) -Wunused-variable warning.
  539. (void)index; // Suppress GCC warning.
  540. }
  541. #ifdef DEBUG_METHODS_ENABLED
  542. template <typename Q>
  543. void call_get_argument_metadata_helper(int p_arg, int &index, GodotTypeInfo::Metadata &md) {
  544. if (p_arg == index) {
  545. md = GetTypeInfo<Q>::METADATA;
  546. }
  547. index++;
  548. }
  549. template <typename... P>
  550. GodotTypeInfo::Metadata call_get_argument_metadata(int p_arg) {
  551. GodotTypeInfo::Metadata md = GodotTypeInfo::METADATA_NONE;
  552. int index = 0;
  553. // I think rocket science is simpler than modern C++.
  554. using expand_type = int[];
  555. expand_type a{ 0, (call_get_argument_metadata_helper<P>(p_arg, index, md), 0)... };
  556. (void)a; // Suppress (valid, but unavoidable) -Wunused-variable warning.
  557. (void)index;
  558. return md;
  559. }
  560. #endif // DEBUG_METHODS_ENABLED
  561. //////////////////////
  562. template <typename T, typename R, typename... P, size_t... Is>
  563. void call_with_variant_args_ret_helper(T *p_instance, R (T::*p_method)(P...), const Variant **p_args, Variant &r_ret, Callable::CallError &r_error, IndexSequence<Is...>) {
  564. r_error.error = Callable::CallError::CALL_OK;
  565. #ifdef DEBUG_METHODS_ENABLED
  566. r_ret = (p_instance->*p_method)(VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...);
  567. #else
  568. r_ret = (p_instance->*p_method)(VariantCaster<P>::cast(*p_args[Is])...);
  569. #endif
  570. }
  571. template <typename R, typename... P, size_t... Is>
  572. void call_with_variant_args_static_ret(R (*p_method)(P...), const Variant **p_args, Variant &r_ret, Callable::CallError &r_error, IndexSequence<Is...>) {
  573. r_error.error = Callable::CallError::CALL_OK;
  574. #ifdef DEBUG_METHODS_ENABLED
  575. r_ret = (p_method)(VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...);
  576. #else
  577. r_ret = (p_method)(VariantCaster<P>::cast(*p_args[Is])...);
  578. #endif
  579. }
  580. template <typename... P, size_t... Is>
  581. void call_with_variant_args_static(void (*p_method)(P...), const Variant **p_args, Callable::CallError &r_error, IndexSequence<Is...>) {
  582. r_error.error = Callable::CallError::CALL_OK;
  583. #ifdef DEBUG_METHODS_ENABLED
  584. (p_method)(VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...);
  585. #else
  586. (p_method)(VariantCaster<P>::cast(*p_args[Is])...);
  587. #endif
  588. }
  589. template <typename T, typename R, typename... P>
  590. void call_with_variant_args_ret(T *p_instance, R (T::*p_method)(P...), const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
  591. #ifdef DEBUG_METHODS_ENABLED
  592. if ((size_t)p_argcount > sizeof...(P)) {
  593. r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
  594. r_error.expected = sizeof...(P);
  595. return;
  596. }
  597. if ((size_t)p_argcount < sizeof...(P)) {
  598. r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  599. r_error.expected = sizeof...(P);
  600. return;
  601. }
  602. #endif
  603. call_with_variant_args_ret_helper<T, R, P...>(p_instance, p_method, p_args, r_ret, r_error, BuildIndexSequence<sizeof...(P)>{});
  604. }
  605. template <typename T, typename R, typename... P, size_t... Is>
  606. void call_with_variant_args_retc_helper(T *p_instance, R (T::*p_method)(P...) const, const Variant **p_args, Variant &r_ret, Callable::CallError &r_error, IndexSequence<Is...>) {
  607. r_error.error = Callable::CallError::CALL_OK;
  608. #ifdef DEBUG_METHODS_ENABLED
  609. r_ret = (p_instance->*p_method)(VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...);
  610. #else
  611. r_ret = (p_instance->*p_method)(VariantCaster<P>::cast(*p_args[Is])...);
  612. #endif
  613. (void)p_args;
  614. }
  615. template <typename R, typename... P>
  616. void call_with_variant_args_static_ret(R (*p_method)(P...), const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
  617. #ifdef DEBUG_METHODS_ENABLED
  618. if ((size_t)p_argcount > sizeof...(P)) {
  619. r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
  620. r_error.expected = sizeof...(P);
  621. return;
  622. }
  623. if ((size_t)p_argcount < sizeof...(P)) {
  624. r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  625. r_error.expected = sizeof...(P);
  626. return;
  627. }
  628. #endif
  629. call_with_variant_args_static_ret<R, P...>(p_method, p_args, r_ret, r_error, BuildIndexSequence<sizeof...(P)>{});
  630. }
  631. template <typename... P>
  632. void call_with_variant_args_static(void (*p_method)(P...), const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
  633. #ifdef DEBUG_METHODS_ENABLED
  634. if ((size_t)p_argcount > sizeof...(P)) {
  635. r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
  636. r_error.expected = sizeof...(P);
  637. return;
  638. }
  639. if ((size_t)p_argcount < sizeof...(P)) {
  640. r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  641. r_error.expected = sizeof...(P);
  642. return;
  643. }
  644. #endif
  645. call_with_variant_args_static<P...>(p_method, p_args, r_error, BuildIndexSequence<sizeof...(P)>{});
  646. }
  647. template <typename T, typename R, typename... P>
  648. void call_with_variant_args_retc(T *p_instance, R (T::*p_method)(P...) const, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
  649. #ifdef DEBUG_METHODS_ENABLED
  650. if ((size_t)p_argcount > sizeof...(P)) {
  651. r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
  652. r_error.expected = sizeof...(P);
  653. return;
  654. }
  655. if ((size_t)p_argcount < sizeof...(P)) {
  656. r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  657. r_error.expected = sizeof...(P);
  658. return;
  659. }
  660. #endif
  661. call_with_variant_args_retc_helper<T, R, P...>(p_instance, p_method, p_args, r_ret, r_error, BuildIndexSequence<sizeof...(P)>{});
  662. }
  663. template <typename T, typename R, typename... P, size_t... Is>
  664. void call_with_variant_args_retc_static_helper(T *p_instance, R (*p_method)(T *, P...), const Variant **p_args, Variant &r_ret, Callable::CallError &r_error, IndexSequence<Is...>) {
  665. r_error.error = Callable::CallError::CALL_OK;
  666. #ifdef DEBUG_METHODS_ENABLED
  667. r_ret = (p_method)(p_instance, VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...);
  668. #else
  669. r_ret = (p_method)(p_instance, VariantCaster<P>::cast(*p_args[Is])...);
  670. #endif
  671. (void)p_args;
  672. }
  673. template <typename T, typename R, typename... P>
  674. void call_with_variant_args_retc_static_helper_dv(T *p_instance, R (*p_method)(T *, P...), const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &default_values, Callable::CallError &r_error) {
  675. #ifdef DEBUG_ENABLED
  676. if ((size_t)p_argcount > sizeof...(P)) {
  677. r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
  678. r_error.expected = sizeof...(P);
  679. return;
  680. }
  681. #endif
  682. int32_t missing = (int32_t)sizeof...(P) - (int32_t)p_argcount;
  683. int32_t dvs = default_values.size();
  684. #ifdef DEBUG_ENABLED
  685. if (missing > dvs) {
  686. r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  687. r_error.expected = sizeof...(P);
  688. return;
  689. }
  690. #endif
  691. const Variant *args[sizeof...(P) == 0 ? 1 : sizeof...(P)]; //avoid zero sized array
  692. for (int32_t i = 0; i < (int32_t)sizeof...(P); i++) {
  693. if (i < p_argcount) {
  694. args[i] = p_args[i];
  695. } else {
  696. args[i] = &default_values[i - p_argcount + (dvs - missing)];
  697. }
  698. }
  699. call_with_variant_args_retc_static_helper(p_instance, p_method, args, r_ret, r_error, BuildIndexSequence<sizeof...(P)>{});
  700. }
  701. template <typename T, typename... P, size_t... Is>
  702. void call_with_variant_args_static_helper(T *p_instance, void (*p_method)(T *, P...), const Variant **p_args, Callable::CallError &r_error, IndexSequence<Is...>) {
  703. r_error.error = Callable::CallError::CALL_OK;
  704. #ifdef DEBUG_METHODS_ENABLED
  705. (p_method)(p_instance, VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...);
  706. #else
  707. (p_method)(p_instance, VariantCaster<P>::cast(*p_args[Is])...);
  708. #endif
  709. (void)p_args;
  710. }
  711. template <typename T, typename... P>
  712. void call_with_variant_args_static_helper_dv(T *p_instance, void (*p_method)(T *, P...), const Variant **p_args, int p_argcount, const Vector<Variant> &default_values, Callable::CallError &r_error) {
  713. #ifdef DEBUG_ENABLED
  714. if ((size_t)p_argcount > sizeof...(P)) {
  715. r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
  716. r_error.expected = sizeof...(P);
  717. return;
  718. }
  719. #endif
  720. int32_t missing = (int32_t)sizeof...(P) - (int32_t)p_argcount;
  721. int32_t dvs = default_values.size();
  722. #ifdef DEBUG_ENABLED
  723. if (missing > dvs) {
  724. r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  725. r_error.expected = sizeof...(P);
  726. return;
  727. }
  728. #endif
  729. const Variant *args[sizeof...(P) == 0 ? 1 : sizeof...(P)]; //avoid zero sized array
  730. for (int32_t i = 0; i < (int32_t)sizeof...(P); i++) {
  731. if (i < p_argcount) {
  732. args[i] = p_args[i];
  733. } else {
  734. args[i] = &default_values[i - p_argcount + (dvs - missing)];
  735. }
  736. }
  737. call_with_variant_args_static_helper(p_instance, p_method, args, r_error, BuildIndexSequence<sizeof...(P)>{});
  738. }
  739. template <typename R, typename... P>
  740. void call_with_variant_args_static_ret_dv(R (*p_method)(P...), const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error, const Vector<Variant> &default_values) {
  741. #ifdef DEBUG_ENABLED
  742. if ((size_t)p_argcount > sizeof...(P)) {
  743. r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
  744. r_error.expected = sizeof...(P);
  745. return;
  746. }
  747. #endif
  748. int32_t missing = (int32_t)sizeof...(P) - (int32_t)p_argcount;
  749. int32_t dvs = default_values.size();
  750. #ifdef DEBUG_ENABLED
  751. if (missing > dvs) {
  752. r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  753. r_error.expected = sizeof...(P);
  754. return;
  755. }
  756. #endif
  757. const Variant *args[sizeof...(P) == 0 ? 1 : sizeof...(P)]; //avoid zero sized array
  758. for (int32_t i = 0; i < (int32_t)sizeof...(P); i++) {
  759. if (i < p_argcount) {
  760. args[i] = p_args[i];
  761. } else {
  762. args[i] = &default_values[i - p_argcount + (dvs - missing)];
  763. }
  764. }
  765. call_with_variant_args_static_ret(p_method, args, r_ret, r_error, BuildIndexSequence<sizeof...(P)>{});
  766. }
  767. template <typename... P>
  768. void call_with_variant_args_static_dv(void (*p_method)(P...), const Variant **p_args, int p_argcount, Callable::CallError &r_error, const Vector<Variant> &default_values) {
  769. #ifdef DEBUG_ENABLED
  770. if ((size_t)p_argcount > sizeof...(P)) {
  771. r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
  772. r_error.expected = sizeof...(P);
  773. return;
  774. }
  775. #endif
  776. int32_t missing = (int32_t)sizeof...(P) - (int32_t)p_argcount;
  777. int32_t dvs = default_values.size();
  778. #ifdef DEBUG_ENABLED
  779. if (missing > dvs) {
  780. r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  781. r_error.expected = sizeof...(P);
  782. return;
  783. }
  784. #endif
  785. const Variant *args[sizeof...(P) == 0 ? 1 : sizeof...(P)]; //avoid zero sized array
  786. for (int32_t i = 0; i < (int32_t)sizeof...(P); i++) {
  787. if (i < p_argcount) {
  788. args[i] = p_args[i];
  789. } else {
  790. args[i] = &default_values[i - p_argcount + (dvs - missing)];
  791. }
  792. }
  793. call_with_variant_args_static(p_method, args, r_error, BuildIndexSequence<sizeof...(P)>{});
  794. }
  795. GODOT_GCC_WARNING_POP