2
0

method_bind.h 18 KB

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