method_bind.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. /*************************************************************************/
  2. /* method_bind.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  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. #ifndef METHOD_BIND_H
  31. #define METHOD_BIND_H
  32. #include "core/variant/binder_common.h"
  33. enum MethodFlags {
  34. METHOD_FLAG_NORMAL = 1,
  35. METHOD_FLAG_EDITOR = 2,
  36. METHOD_FLAG_NOSCRIPT = 4,
  37. METHOD_FLAG_CONST = 8,
  38. METHOD_FLAG_REVERSE = 16, // used for events
  39. METHOD_FLAG_VIRTUAL = 32,
  40. METHOD_FLAG_FROM_SCRIPT = 64,
  41. METHOD_FLAG_VARARG = 128,
  42. METHOD_FLAGS_DEFAULT = METHOD_FLAG_NORMAL,
  43. };
  44. VARIANT_ENUM_CAST(MethodFlags)
  45. // some helpers
  46. class MethodBind {
  47. int method_id;
  48. uint32_t hint_flags = METHOD_FLAGS_DEFAULT;
  49. StringName name;
  50. StringName instance_class;
  51. Vector<Variant> default_arguments;
  52. int default_argument_count = 0;
  53. int argument_count = 0;
  54. bool _const = false;
  55. bool _returns = false;
  56. protected:
  57. #ifdef DEBUG_METHODS_ENABLED
  58. Variant::Type *argument_types = nullptr;
  59. Vector<StringName> arg_names;
  60. #endif
  61. void _set_const(bool p_const);
  62. void _set_returns(bool p_returns);
  63. #ifdef DEBUG_METHODS_ENABLED
  64. virtual Variant::Type _gen_argument_type(int p_arg) const = 0;
  65. virtual PropertyInfo _gen_argument_type_info(int p_arg) const = 0;
  66. void _generate_argument_types(int p_count);
  67. #endif
  68. void set_argument_count(int p_count) { argument_count = p_count; }
  69. public:
  70. _FORCE_INLINE_ const Vector<Variant> &get_default_arguments() const { return default_arguments; }
  71. _FORCE_INLINE_ int get_default_argument_count() const { return default_argument_count; }
  72. _FORCE_INLINE_ Variant has_default_argument(int p_arg) const {
  73. int idx = p_arg - (argument_count - default_arguments.size());
  74. if (idx < 0 || idx >= default_arguments.size()) {
  75. return false;
  76. } else {
  77. return true;
  78. }
  79. }
  80. _FORCE_INLINE_ Variant get_default_argument(int p_arg) const {
  81. int idx = p_arg - (argument_count - default_arguments.size());
  82. if (idx < 0 || idx >= default_arguments.size()) {
  83. return Variant();
  84. } else {
  85. return default_arguments[idx];
  86. }
  87. }
  88. #ifdef DEBUG_METHODS_ENABLED
  89. _FORCE_INLINE_ Variant::Type get_argument_type(int p_argument) const {
  90. ERR_FAIL_COND_V(p_argument < -1 || p_argument > argument_count, Variant::NIL);
  91. return argument_types[p_argument + 1];
  92. }
  93. PropertyInfo get_argument_info(int p_argument) const;
  94. PropertyInfo get_return_info() const;
  95. void set_argument_names(const Vector<StringName> &p_names); // Set by ClassDB, can't be inferred otherwise.
  96. Vector<StringName> get_argument_names() const;
  97. virtual GodotTypeInfo::Metadata get_argument_meta(int p_arg) const = 0;
  98. #endif
  99. void set_hint_flags(uint32_t p_hint) { hint_flags = p_hint; }
  100. uint32_t get_hint_flags() const { return hint_flags | (is_const() ? METHOD_FLAG_CONST : 0) | (is_vararg() ? METHOD_FLAG_VARARG : 0); }
  101. _FORCE_INLINE_ StringName get_instance_class() const { return instance_class; }
  102. _FORCE_INLINE_ void set_instance_class(const StringName &p_class) { instance_class = p_class; }
  103. _FORCE_INLINE_ int get_argument_count() const { return argument_count; };
  104. virtual Variant call(Object *p_object, const Variant **p_args, int p_arg_count, Callable::CallError &r_error) = 0;
  105. virtual void ptrcall(Object *p_object, const void **p_args, void *r_ret) = 0;
  106. StringName get_name() const;
  107. void set_name(const StringName &p_name);
  108. _FORCE_INLINE_ int get_method_id() const { return method_id; }
  109. _FORCE_INLINE_ bool is_const() const { return _const; }
  110. _FORCE_INLINE_ bool has_return() const { return _returns; }
  111. virtual bool is_vararg() const { return false; }
  112. void set_default_arguments(const Vector<Variant> &p_defargs);
  113. MethodBind();
  114. virtual ~MethodBind();
  115. };
  116. template <class T>
  117. class MethodBindVarArg : public MethodBind {
  118. public:
  119. typedef Variant (T::*NativeCall)(const Variant **, int, Callable::CallError &);
  120. protected:
  121. NativeCall call_method = nullptr;
  122. #ifdef DEBUG_METHODS_ENABLED
  123. MethodInfo arguments;
  124. #endif
  125. public:
  126. #ifdef DEBUG_METHODS_ENABLED
  127. virtual PropertyInfo _gen_argument_type_info(int p_arg) const {
  128. if (p_arg < 0) {
  129. return arguments.return_val;
  130. } else if (p_arg < arguments.arguments.size()) {
  131. return arguments.arguments[p_arg];
  132. } else {
  133. return PropertyInfo(Variant::NIL, "arg_" + itos(p_arg), PROPERTY_HINT_NONE, String(), PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT);
  134. }
  135. }
  136. virtual Variant::Type _gen_argument_type(int p_arg) const {
  137. return _gen_argument_type_info(p_arg).type;
  138. }
  139. virtual GodotTypeInfo::Metadata get_argument_meta(int) const {
  140. return GodotTypeInfo::METADATA_NONE;
  141. }
  142. #else
  143. virtual Variant::Type _gen_argument_type(int p_arg) const {
  144. return Variant::NIL;
  145. }
  146. #endif
  147. virtual Variant call(Object *p_object, const Variant **p_args, int p_arg_count, Callable::CallError &r_error) {
  148. T *instance = static_cast<T *>(p_object);
  149. return (instance->*call_method)(p_args, p_arg_count, r_error);
  150. }
  151. void set_method_info(const MethodInfo &p_info, bool p_return_nil_is_variant) {
  152. set_argument_count(p_info.arguments.size());
  153. #ifdef DEBUG_METHODS_ENABLED
  154. Variant::Type *at = memnew_arr(Variant::Type, p_info.arguments.size() + 1);
  155. at[0] = p_info.return_val.type;
  156. if (p_info.arguments.size()) {
  157. Vector<StringName> names;
  158. names.resize(p_info.arguments.size());
  159. for (int i = 0; i < p_info.arguments.size(); i++) {
  160. at[i + 1] = p_info.arguments[i].type;
  161. names.write[i] = p_info.arguments[i].name;
  162. }
  163. set_argument_names(names);
  164. }
  165. argument_types = at;
  166. arguments = p_info;
  167. if (p_return_nil_is_variant) {
  168. arguments.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
  169. }
  170. #endif
  171. }
  172. virtual void ptrcall(Object *p_object, const void **p_args, void *r_ret) {
  173. ERR_FAIL(); // Can't call.
  174. }
  175. void set_method(NativeCall p_method) { call_method = p_method; }
  176. virtual bool is_const() const { return false; }
  177. virtual bool is_vararg() const { return true; }
  178. MethodBindVarArg() {
  179. _set_returns(true);
  180. }
  181. };
  182. template <class T>
  183. MethodBind *create_vararg_method_bind(Variant (T::*p_method)(const Variant **, int, Callable::CallError &), const MethodInfo &p_info, bool p_return_nil_is_variant) {
  184. MethodBindVarArg<T> *a = memnew((MethodBindVarArg<T>));
  185. a->set_method(p_method);
  186. a->set_method_info(p_info, p_return_nil_is_variant);
  187. a->set_instance_class(T::get_class_static());
  188. return a;
  189. }
  190. /**** VARIADIC TEMPLATES ****/
  191. #ifndef TYPED_METHOD_BIND
  192. class __UnexistingClass;
  193. #define MB_T __UnexistingClass
  194. #else
  195. #define MB_T T
  196. #endif
  197. // no return, not const
  198. #ifdef TYPED_METHOD_BIND
  199. template <class T, class... P>
  200. #else
  201. template <class... P>
  202. #endif
  203. class MethodBindT : public MethodBind {
  204. void (MB_T::*method)(P...);
  205. protected:
  206. #ifdef DEBUG_METHODS_ENABLED
  207. // GCC raises warnings in the case P = {} as the comparison is always false...
  208. #if defined(__GNUC__) && !defined(__clang__)
  209. #pragma GCC diagnostic push
  210. #pragma GCC diagnostic ignored "-Wlogical-op"
  211. #endif
  212. virtual Variant::Type _gen_argument_type(int p_arg) const {
  213. if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
  214. return call_get_argument_type<P...>(p_arg);
  215. } else {
  216. return Variant::NIL;
  217. }
  218. }
  219. #if defined(__GNUC__) && !defined(__clang__)
  220. #pragma GCC diagnostic pop
  221. #endif
  222. virtual PropertyInfo _gen_argument_type_info(int p_arg) const {
  223. PropertyInfo pi;
  224. call_get_argument_type_info<P...>(p_arg, pi);
  225. return pi;
  226. }
  227. #endif
  228. public:
  229. #ifdef DEBUG_METHODS_ENABLED
  230. virtual GodotTypeInfo::Metadata get_argument_meta(int p_arg) const {
  231. return call_get_argument_metadata<P...>(p_arg);
  232. }
  233. #endif
  234. virtual Variant call(Object *p_object, const Variant **p_args, int p_arg_count, Callable::CallError &r_error) {
  235. #ifdef TYPED_METHOD_BIND
  236. call_with_variant_args_dv(static_cast<T *>(p_object), method, p_args, p_arg_count, r_error, get_default_arguments());
  237. #else
  238. call_with_variant_args_dv((MB_T *)(p_object), method, p_args, p_arg_count, r_error, get_default_arguments());
  239. #endif
  240. return Variant();
  241. }
  242. virtual void ptrcall(Object *p_object, const void **p_args, void *r_ret) {
  243. #ifdef TYPED_METHOD_BIND
  244. call_with_ptr_args<T, P...>(static_cast<T *>(p_object), method, p_args);
  245. #else
  246. call_with_ptr_args<MB_T, P...>((MB_T *)(p_object), method, p_args);
  247. #endif
  248. }
  249. MethodBindT(void (MB_T::*p_method)(P...)) {
  250. method = p_method;
  251. #ifdef DEBUG_METHODS_ENABLED
  252. _generate_argument_types(sizeof...(P));
  253. #endif
  254. set_argument_count(sizeof...(P));
  255. }
  256. };
  257. template <class T, class... P>
  258. MethodBind *create_method_bind(void (T::*p_method)(P...)) {
  259. #ifdef TYPED_METHOD_BIND
  260. MethodBind *a = memnew((MethodBindT<T, P...>)(p_method));
  261. #else
  262. MethodBind *a = memnew((MethodBindT<P...>)(reinterpret_cast<void (MB_T::*)(P...)>(p_method)));
  263. #endif
  264. a->set_instance_class(T::get_class_static());
  265. return a;
  266. }
  267. // no return, not const
  268. #ifdef TYPED_METHOD_BIND
  269. template <class T, class... P>
  270. #else
  271. template <class... P>
  272. #endif
  273. class MethodBindTC : public MethodBind {
  274. void (MB_T::*method)(P...) const;
  275. protected:
  276. #ifdef DEBUG_METHODS_ENABLED
  277. // GCC raises warnings in the case P = {} as the comparison is always false...
  278. #if defined(__GNUC__) && !defined(__clang__)
  279. #pragma GCC diagnostic push
  280. #pragma GCC diagnostic ignored "-Wlogical-op"
  281. #endif
  282. virtual Variant::Type _gen_argument_type(int p_arg) const {
  283. if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
  284. return call_get_argument_type<P...>(p_arg);
  285. } else {
  286. return Variant::NIL;
  287. }
  288. }
  289. #if defined(__GNUC__) && !defined(__clang__)
  290. #pragma GCC diagnostic pop
  291. #endif
  292. virtual PropertyInfo _gen_argument_type_info(int p_arg) const {
  293. PropertyInfo pi;
  294. call_get_argument_type_info<P...>(p_arg, pi);
  295. return pi;
  296. }
  297. #endif
  298. public:
  299. #ifdef DEBUG_METHODS_ENABLED
  300. virtual GodotTypeInfo::Metadata get_argument_meta(int p_arg) const {
  301. return call_get_argument_metadata<P...>(p_arg);
  302. }
  303. #endif
  304. virtual Variant call(Object *p_object, const Variant **p_args, int p_arg_count, Callable::CallError &r_error) {
  305. #ifdef TYPED_METHOD_BIND
  306. call_with_variant_argsc_dv(static_cast<T *>(p_object), method, p_args, p_arg_count, r_error, get_default_arguments());
  307. #else
  308. call_with_variant_argsc_dv((MB_T *)(p_object), method, p_args, p_arg_count, r_error, get_default_arguments());
  309. #endif
  310. return Variant();
  311. }
  312. virtual void ptrcall(Object *p_object, const void **p_args, void *r_ret) {
  313. #ifdef TYPED_METHOD_BIND
  314. call_with_ptr_argsc<T, P...>(static_cast<T *>(p_object), method, p_args);
  315. #else
  316. call_with_ptr_argsc<MB_T, P...>((MB_T *)(p_object), method, p_args);
  317. #endif
  318. }
  319. MethodBindTC(void (MB_T::*p_method)(P...) const) {
  320. method = p_method;
  321. _set_const(true);
  322. #ifdef DEBUG_METHODS_ENABLED
  323. _generate_argument_types(sizeof...(P));
  324. #endif
  325. set_argument_count(sizeof...(P));
  326. }
  327. };
  328. template <class T, class... P>
  329. MethodBind *create_method_bind(void (T::*p_method)(P...) const) {
  330. #ifdef TYPED_METHOD_BIND
  331. MethodBind *a = memnew((MethodBindTC<T, P...>)(p_method));
  332. #else
  333. MethodBind *a = memnew((MethodBindTC<P...>)(reinterpret_cast<void (MB_T::*)(P...) const>(p_method)));
  334. #endif
  335. a->set_instance_class(T::get_class_static());
  336. return a;
  337. }
  338. // return, not const
  339. #ifdef TYPED_METHOD_BIND
  340. template <class T, class R, class... P>
  341. #else
  342. template <class R, class... P>
  343. #endif
  344. class MethodBindTR : public MethodBind {
  345. R(MB_T::*method)
  346. (P...);
  347. protected:
  348. #ifdef DEBUG_METHODS_ENABLED
  349. // GCC raises warnings in the case P = {} as the comparison is always false...
  350. #if defined(__GNUC__) && !defined(__clang__)
  351. #pragma GCC diagnostic push
  352. #pragma GCC diagnostic ignored "-Wlogical-op"
  353. #endif
  354. virtual Variant::Type _gen_argument_type(int p_arg) const {
  355. if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
  356. return call_get_argument_type<P...>(p_arg);
  357. } else {
  358. return GetTypeInfo<R>::VARIANT_TYPE;
  359. }
  360. }
  361. virtual PropertyInfo _gen_argument_type_info(int p_arg) const {
  362. if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
  363. PropertyInfo pi;
  364. call_get_argument_type_info<P...>(p_arg, pi);
  365. return pi;
  366. } else {
  367. return GetTypeInfo<R>::get_class_info();
  368. }
  369. }
  370. #if defined(__GNUC__) && !defined(__clang__)
  371. #pragma GCC diagnostic pop
  372. #endif
  373. #endif
  374. public:
  375. #ifdef DEBUG_METHODS_ENABLED
  376. virtual GodotTypeInfo::Metadata get_argument_meta(int p_arg) const {
  377. if (p_arg >= 0) {
  378. return call_get_argument_metadata<P...>(p_arg);
  379. } else {
  380. return GetTypeInfo<R>::METADATA;
  381. }
  382. }
  383. #endif
  384. virtual Variant call(Object *p_object, const Variant **p_args, int p_arg_count, Callable::CallError &r_error) {
  385. Variant ret;
  386. #ifdef TYPED_METHOD_BIND
  387. call_with_variant_args_ret_dv(static_cast<T *>(p_object), method, p_args, p_arg_count, ret, r_error, get_default_arguments());
  388. #else
  389. call_with_variant_args_ret_dv((MB_T *)p_object, method, p_args, p_arg_count, ret, r_error, get_default_arguments());
  390. #endif
  391. return ret;
  392. }
  393. virtual void ptrcall(Object *p_object, const void **p_args, void *r_ret) {
  394. #ifdef TYPED_METHOD_BIND
  395. call_with_ptr_args_ret<T, R, P...>(static_cast<T *>(p_object), method, p_args, r_ret);
  396. #else
  397. call_with_ptr_args_ret<MB_T, R, P...>((MB_T *)(p_object), method, p_args, r_ret);
  398. #endif
  399. }
  400. MethodBindTR(R (MB_T::*p_method)(P...)) {
  401. method = p_method;
  402. _set_returns(true);
  403. #ifdef DEBUG_METHODS_ENABLED
  404. _generate_argument_types(sizeof...(P));
  405. #endif
  406. set_argument_count(sizeof...(P));
  407. }
  408. };
  409. template <class T, class R, class... P>
  410. MethodBind *create_method_bind(R (T::*p_method)(P...)) {
  411. #ifdef TYPED_METHOD_BIND
  412. MethodBind *a = memnew((MethodBindTR<T, R, P...>)(p_method));
  413. #else
  414. MethodBind *a = memnew((MethodBindTR<R, P...>)(reinterpret_cast<R (MB_T::*)(P...)>(p_method)));
  415. #endif
  416. a->set_instance_class(T::get_class_static());
  417. return a;
  418. }
  419. // return, const
  420. #ifdef TYPED_METHOD_BIND
  421. template <class T, class R, class... P>
  422. #else
  423. template <class R, class... P>
  424. #endif
  425. class MethodBindTRC : public MethodBind {
  426. R(MB_T::*method)
  427. (P...) const;
  428. protected:
  429. #ifdef DEBUG_METHODS_ENABLED
  430. // GCC raises warnings in the case P = {} as the comparison is always false...
  431. #if defined(__GNUC__) && !defined(__clang__)
  432. #pragma GCC diagnostic push
  433. #pragma GCC diagnostic ignored "-Wlogical-op"
  434. #endif
  435. virtual Variant::Type _gen_argument_type(int p_arg) const {
  436. if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
  437. return call_get_argument_type<P...>(p_arg);
  438. } else {
  439. return GetTypeInfo<R>::VARIANT_TYPE;
  440. }
  441. }
  442. virtual PropertyInfo _gen_argument_type_info(int p_arg) const {
  443. if (p_arg >= 0 && p_arg < (int)sizeof...(P)) {
  444. PropertyInfo pi;
  445. call_get_argument_type_info<P...>(p_arg, pi);
  446. return pi;
  447. } else {
  448. return GetTypeInfo<R>::get_class_info();
  449. }
  450. }
  451. #if defined(__GNUC__) && !defined(__clang__)
  452. #pragma GCC diagnostic pop
  453. #endif
  454. #endif
  455. public:
  456. #ifdef DEBUG_METHODS_ENABLED
  457. virtual GodotTypeInfo::Metadata get_argument_meta(int p_arg) const {
  458. if (p_arg >= 0) {
  459. return call_get_argument_metadata<P...>(p_arg);
  460. } else {
  461. return GetTypeInfo<R>::METADATA;
  462. }
  463. }
  464. #endif
  465. virtual Variant call(Object *p_object, const Variant **p_args, int p_arg_count, Callable::CallError &r_error) {
  466. Variant ret;
  467. #ifdef TYPED_METHOD_BIND
  468. call_with_variant_args_retc_dv(static_cast<T *>(p_object), method, p_args, p_arg_count, ret, r_error, get_default_arguments());
  469. #else
  470. call_with_variant_args_retc_dv((MB_T *)(p_object), method, p_args, p_arg_count, ret, r_error, get_default_arguments());
  471. #endif
  472. return ret;
  473. }
  474. virtual void ptrcall(Object *p_object, const void **p_args, void *r_ret) {
  475. #ifdef TYPED_METHOD_BIND
  476. call_with_ptr_args_retc<T, R, P...>(static_cast<T *>(p_object), method, p_args, r_ret);
  477. #else
  478. call_with_ptr_args_retc<MB_T, R, P...>((MB_T *)(p_object), method, p_args, r_ret);
  479. #endif
  480. }
  481. MethodBindTRC(R (MB_T::*p_method)(P...) const) {
  482. method = p_method;
  483. _set_returns(true);
  484. _set_const(true);
  485. #ifdef DEBUG_METHODS_ENABLED
  486. _generate_argument_types(sizeof...(P));
  487. #endif
  488. set_argument_count(sizeof...(P));
  489. }
  490. };
  491. template <class T, class R, class... P>
  492. MethodBind *create_method_bind(R (T::*p_method)(P...) const) {
  493. #ifdef TYPED_METHOD_BIND
  494. MethodBind *a = memnew((MethodBindTRC<T, R, P...>)(p_method));
  495. #else
  496. MethodBind *a = memnew((MethodBindTRC<R, P...>)(reinterpret_cast<R (MB_T::*)(P...) const>(p_method)));
  497. #endif
  498. a->set_instance_class(T::get_class_static());
  499. return a;
  500. }
  501. #endif // METHOD_BIND_H