variant_call.cpp 119 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085
  1. /*************************************************************************/
  2. /* variant_call.cpp */
  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. #include "variant.h"
  31. #include "core/core_string_names.h"
  32. #include "core/crypto/crypto_core.h"
  33. #include "core/debugger/engine_debugger.h"
  34. #include "core/io/compression.h"
  35. #include "core/io/marshalls.h"
  36. #include "core/object/class_db.h"
  37. #include "core/os/os.h"
  38. #include "core/templates/local_vector.h"
  39. #include "core/templates/oa_hash_map.h"
  40. typedef void (*VariantFunc)(Variant &r_ret, Variant &p_self, const Variant **p_args);
  41. typedef void (*VariantConstructFunc)(Variant &r_ret, const Variant **p_args);
  42. template <class R, class... P>
  43. static _FORCE_INLINE_ void vc_static_method_call(R (*method)(P...), const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) {
  44. call_with_variant_args_static_ret_dv(method, p_args, p_argcount, r_ret, r_error, p_defvals);
  45. }
  46. template <class... P>
  47. static _FORCE_INLINE_ void vc_static_method_call(void (*method)(P...), const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) {
  48. call_with_variant_args_static_dv(method, p_args, p_argcount, r_error, p_defvals);
  49. }
  50. template <class R, class T, class... P>
  51. static _FORCE_INLINE_ void vc_method_call(R (T::*method)(P...), Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) {
  52. call_with_variant_args_ret_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_ret, r_error, p_defvals);
  53. }
  54. template <class R, class T, class... P>
  55. static _FORCE_INLINE_ void vc_method_call(R (T::*method)(P...) const, Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) {
  56. call_with_variant_args_retc_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_ret, r_error, p_defvals);
  57. }
  58. template <class T, class... P>
  59. static _FORCE_INLINE_ void vc_method_call(void (T::*method)(P...), Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) {
  60. call_with_variant_args_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_error, p_defvals);
  61. }
  62. template <class T, class... P>
  63. static _FORCE_INLINE_ void vc_method_call(void (T::*method)(P...) const, Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) {
  64. call_with_variant_argsc_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_error, p_defvals);
  65. }
  66. template <class R, class T, class... P>
  67. static _FORCE_INLINE_ void vc_method_call_static(R (*method)(T *, P...), Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) {
  68. call_with_variant_args_retc_static_helper_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_ret, p_defvals, r_error);
  69. }
  70. template <class T, class... P>
  71. static _FORCE_INLINE_ void vc_method_call_static(void (*method)(T *, P...), Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) {
  72. call_with_variant_args_static_helper_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, p_defvals, r_error);
  73. }
  74. template <class R, class T, class... P>
  75. static _FORCE_INLINE_ void vc_validated_call(R (T::*method)(P...), Variant *base, const Variant **p_args, Variant *r_ret) {
  76. call_with_validated_variant_args_ret(base, method, p_args, r_ret);
  77. }
  78. template <class R, class T, class... P>
  79. static _FORCE_INLINE_ void vc_validated_call(R (T::*method)(P...) const, Variant *base, const Variant **p_args, Variant *r_ret) {
  80. call_with_validated_variant_args_retc(base, method, p_args, r_ret);
  81. }
  82. template <class T, class... P>
  83. static _FORCE_INLINE_ void vc_validated_call(void (T::*method)(P...), Variant *base, const Variant **p_args, Variant *r_ret) {
  84. call_with_validated_variant_args(base, method, p_args);
  85. }
  86. template <class T, class... P>
  87. static _FORCE_INLINE_ void vc_validated_call(void (T::*method)(P...) const, Variant *base, const Variant **p_args, Variant *r_ret) {
  88. call_with_validated_variant_argsc(base, method, p_args);
  89. }
  90. template <class R, class T, class... P>
  91. static _FORCE_INLINE_ void vc_validated_call_static(R (*method)(T *, P...), Variant *base, const Variant **p_args, Variant *r_ret) {
  92. call_with_validated_variant_args_static_retc(base, method, p_args, r_ret);
  93. }
  94. template <class T, class... P>
  95. static _FORCE_INLINE_ void vc_validated_call_static(void (*method)(T *, P...), Variant *base, const Variant **p_args, Variant *r_ret) {
  96. call_with_validated_variant_args_static(base, method, p_args);
  97. }
  98. template <class R, class... P>
  99. static _FORCE_INLINE_ void vc_validated_static_call(R (*method)(P...), const Variant **p_args, Variant *r_ret) {
  100. call_with_validated_variant_args_static_method_ret(method, p_args, r_ret);
  101. }
  102. template <class... P>
  103. static _FORCE_INLINE_ void vc_validated_static_call(void (*method)(P...), const Variant **p_args, Variant *r_ret) {
  104. call_with_validated_variant_args_static_method(method, p_args);
  105. }
  106. template <class R, class T, class... P>
  107. static _FORCE_INLINE_ void vc_ptrcall(R (T::*method)(P...), void *p_base, const void **p_args, void *r_ret) {
  108. call_with_ptr_args_ret(reinterpret_cast<T *>(p_base), method, p_args, r_ret);
  109. }
  110. template <class R, class T, class... P>
  111. static _FORCE_INLINE_ void vc_ptrcall(R (T::*method)(P...) const, void *p_base, const void **p_args, void *r_ret) {
  112. call_with_ptr_args_retc(reinterpret_cast<T *>(p_base), method, p_args, r_ret);
  113. }
  114. template <class T, class... P>
  115. static _FORCE_INLINE_ void vc_ptrcall(void (T::*method)(P...), void *p_base, const void **p_args, void *r_ret) {
  116. call_with_ptr_args(reinterpret_cast<T *>(p_base), method, p_args);
  117. }
  118. template <class T, class... P>
  119. static _FORCE_INLINE_ void vc_ptrcall(void (T::*method)(P...) const, void *p_base, const void **p_args, void *r_ret) {
  120. call_with_ptr_argsc(reinterpret_cast<T *>(p_base), method, p_args);
  121. }
  122. template <class R, class T, class... P>
  123. static _FORCE_INLINE_ int vc_get_argument_count(R (T::*method)(P...)) {
  124. return sizeof...(P);
  125. }
  126. template <class R, class T, class... P>
  127. static _FORCE_INLINE_ int vc_get_argument_count(R (T::*method)(P...) const) {
  128. return sizeof...(P);
  129. }
  130. template <class T, class... P>
  131. static _FORCE_INLINE_ int vc_get_argument_count(void (T::*method)(P...)) {
  132. return sizeof...(P);
  133. }
  134. template <class T, class... P>
  135. static _FORCE_INLINE_ int vc_get_argument_count(void (T::*method)(P...) const) {
  136. return sizeof...(P);
  137. }
  138. template <class R, class T, class... P>
  139. static _FORCE_INLINE_ int vc_get_argument_count(R (*method)(T *, P...)) {
  140. return sizeof...(P);
  141. }
  142. template <class R, class... P>
  143. static _FORCE_INLINE_ int vc_get_argument_count_static(R (*method)(P...)) {
  144. return sizeof...(P);
  145. }
  146. template <class R, class T, class... P>
  147. static _FORCE_INLINE_ Variant::Type vc_get_argument_type(R (T::*method)(P...), int p_arg) {
  148. return call_get_argument_type<P...>(p_arg);
  149. }
  150. template <class R, class T, class... P>
  151. static _FORCE_INLINE_ Variant::Type vc_get_argument_type(R (T::*method)(P...) const, int p_arg) {
  152. return call_get_argument_type<P...>(p_arg);
  153. }
  154. template <class T, class... P>
  155. static _FORCE_INLINE_ Variant::Type vc_get_argument_type(void (T::*method)(P...), int p_arg) {
  156. return call_get_argument_type<P...>(p_arg);
  157. }
  158. template <class T, class... P>
  159. static _FORCE_INLINE_ Variant::Type vc_get_argument_type(void (T::*method)(P...) const, int p_arg) {
  160. return call_get_argument_type<P...>(p_arg);
  161. }
  162. template <class R, class T, class... P>
  163. static _FORCE_INLINE_ Variant::Type vc_get_argument_type(R (*method)(T *, P...), int p_arg) {
  164. return call_get_argument_type<P...>(p_arg);
  165. }
  166. template <class R, class... P>
  167. static _FORCE_INLINE_ Variant::Type vc_get_argument_type_static(R (*method)(P...), int p_arg) {
  168. return call_get_argument_type<P...>(p_arg);
  169. }
  170. template <class R, class T, class... P>
  171. static _FORCE_INLINE_ Variant::Type vc_get_return_type(R (T::*method)(P...)) {
  172. return GetTypeInfo<R>::VARIANT_TYPE;
  173. }
  174. template <class R, class T, class... P>
  175. static _FORCE_INLINE_ Variant::Type vc_get_return_type(R (T::*method)(P...) const) {
  176. return GetTypeInfo<R>::VARIANT_TYPE;
  177. }
  178. template <class T, class... P>
  179. static _FORCE_INLINE_ Variant::Type vc_get_return_type(void (T::*method)(P...)) {
  180. return Variant::NIL;
  181. }
  182. template <class T, class... P>
  183. static _FORCE_INLINE_ Variant::Type vc_get_return_type(void (T::*method)(P...) const) {
  184. return Variant::NIL;
  185. }
  186. template <class R, class... P>
  187. static _FORCE_INLINE_ Variant::Type vc_get_return_type(R (*method)(P...)) {
  188. return GetTypeInfo<R>::VARIANT_TYPE;
  189. }
  190. template <class... P>
  191. static _FORCE_INLINE_ Variant::Type vc_get_return_type(void (*method)(P...)) {
  192. return Variant::NIL;
  193. }
  194. template <class R, class T, class... P>
  195. static _FORCE_INLINE_ bool vc_has_return_type(R (T::*method)(P...)) {
  196. return true;
  197. }
  198. template <class R, class T, class... P>
  199. static _FORCE_INLINE_ bool vc_has_return_type(R (T::*method)(P...) const) {
  200. return true;
  201. }
  202. template <class T, class... P>
  203. static _FORCE_INLINE_ bool vc_has_return_type(void (T::*method)(P...)) {
  204. return false;
  205. }
  206. template <class T, class... P>
  207. static _FORCE_INLINE_ bool vc_has_return_type(void (T::*method)(P...) const) {
  208. return false;
  209. }
  210. template <class... P>
  211. static _FORCE_INLINE_ bool vc_has_return_type_static(void (*method)(P...)) {
  212. return false;
  213. }
  214. template <class R, class... P>
  215. static _FORCE_INLINE_ bool vc_has_return_type_static(R (*method)(P...)) {
  216. return true;
  217. }
  218. template <class R, class T, class... P>
  219. static _FORCE_INLINE_ bool vc_is_const(R (T::*method)(P...)) {
  220. return false;
  221. }
  222. template <class R, class T, class... P>
  223. static _FORCE_INLINE_ bool vc_is_const(R (T::*method)(P...) const) {
  224. return true;
  225. }
  226. template <class T, class... P>
  227. static _FORCE_INLINE_ bool vc_is_const(void (T::*method)(P...)) {
  228. return false;
  229. }
  230. template <class T, class... P>
  231. static _FORCE_INLINE_ bool vc_is_const(void (T::*method)(P...) const) {
  232. return true;
  233. }
  234. template <class R, class T, class... P>
  235. static _FORCE_INLINE_ Variant::Type vc_get_base_type(R (T::*method)(P...)) {
  236. return GetTypeInfo<T>::VARIANT_TYPE;
  237. }
  238. template <class R, class T, class... P>
  239. static _FORCE_INLINE_ Variant::Type vc_get_base_type(R (T::*method)(P...) const) {
  240. return GetTypeInfo<T>::VARIANT_TYPE;
  241. }
  242. template <class T, class... P>
  243. static _FORCE_INLINE_ Variant::Type vc_get_base_type(void (T::*method)(P...)) {
  244. return GetTypeInfo<T>::VARIANT_TYPE;
  245. }
  246. template <class T, class... P>
  247. static _FORCE_INLINE_ Variant::Type vc_get_base_type(void (T::*method)(P...) const) {
  248. return GetTypeInfo<T>::VARIANT_TYPE;
  249. }
  250. #define METHOD_CLASS(m_class, m_method_name, m_method_ptr) \
  251. struct Method_##m_class##_##m_method_name { \
  252. static void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { \
  253. vc_method_call(m_method_ptr, base, p_args, p_argcount, r_ret, p_defvals, r_error); \
  254. } \
  255. static void validated_call(Variant *base, const Variant **p_args, int p_argcount, Variant *r_ret) { \
  256. vc_validated_call(m_method_ptr, base, p_args, r_ret); \
  257. } \
  258. static void ptrcall(void *p_base, const void **p_args, void *r_ret, int p_argcount) { \
  259. vc_ptrcall(m_method_ptr, p_base, p_args, r_ret); \
  260. } \
  261. static int get_argument_count() { \
  262. return vc_get_argument_count(m_method_ptr); \
  263. } \
  264. static Variant::Type get_argument_type(int p_arg) { \
  265. return vc_get_argument_type(m_method_ptr, p_arg); \
  266. } \
  267. static Variant::Type get_return_type() { \
  268. return vc_get_return_type(m_method_ptr); \
  269. } \
  270. static bool has_return_type() { \
  271. return vc_has_return_type(m_method_ptr); \
  272. } \
  273. static bool is_const() { \
  274. return vc_is_const(m_method_ptr); \
  275. } \
  276. static bool is_static() { \
  277. return false; \
  278. } \
  279. static bool is_vararg() { \
  280. return false; \
  281. } \
  282. static Variant::Type get_base_type() { \
  283. return vc_get_base_type(m_method_ptr); \
  284. } \
  285. static StringName get_name() { \
  286. return #m_method_name; \
  287. } \
  288. };
  289. template <class R, class... P>
  290. static _FORCE_INLINE_ void vc_static_ptrcall(R (*method)(P...), const void **p_args, void *r_ret) {
  291. call_with_ptr_args_static_method_ret<R, P...>(method, p_args, r_ret);
  292. }
  293. template <class... P>
  294. static _FORCE_INLINE_ void vc_static_ptrcall(void (*method)(P...), const void **p_args, void *r_ret) {
  295. call_with_ptr_args_static_method<P...>(method, p_args);
  296. }
  297. #define STATIC_METHOD_CLASS(m_class, m_method_name, m_method_ptr) \
  298. struct Method_##m_class##_##m_method_name { \
  299. static void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { \
  300. vc_static_method_call(m_method_ptr, p_args, p_argcount, r_ret, p_defvals, r_error); \
  301. } \
  302. static void validated_call(Variant *base, const Variant **p_args, int p_argcount, Variant *r_ret) { \
  303. vc_validated_static_call(m_method_ptr, p_args, r_ret); \
  304. } \
  305. static void ptrcall(void *p_base, const void **p_args, void *r_ret, int p_argcount) { \
  306. vc_static_ptrcall(m_method_ptr, p_args, r_ret); \
  307. } \
  308. static int get_argument_count() { \
  309. return vc_get_argument_count_static(m_method_ptr); \
  310. } \
  311. static Variant::Type get_argument_type(int p_arg) { \
  312. return vc_get_argument_type_static(m_method_ptr, p_arg); \
  313. } \
  314. static Variant::Type get_return_type() { \
  315. return vc_get_return_type(m_method_ptr); \
  316. } \
  317. static bool has_return_type() { \
  318. return vc_has_return_type_static(m_method_ptr); \
  319. } \
  320. static bool is_const() { \
  321. return false; \
  322. } \
  323. static bool is_static() { \
  324. return true; \
  325. } \
  326. static bool is_vararg() { \
  327. return false; \
  328. } \
  329. static Variant::Type get_base_type() { \
  330. return GetTypeInfo<m_class>::VARIANT_TYPE; \
  331. } \
  332. static StringName get_name() { \
  333. return #m_method_name; \
  334. } \
  335. };
  336. template <class R, class T, class... P>
  337. static _FORCE_INLINE_ void vc_ptrcall(R (*method)(T *, P...), void *p_base, const void **p_args, void *r_ret) {
  338. call_with_ptr_args_static_retc<T, R, P...>(reinterpret_cast<T *>(p_base), method, p_args, r_ret);
  339. }
  340. template <class T, class... P>
  341. static _FORCE_INLINE_ void vc_ptrcall(void (*method)(T *, P...), void *p_base, const void **p_args, void *r_ret) {
  342. call_with_ptr_args_static<T, P...>(reinterpret_cast<T *>(p_base), method, p_args);
  343. }
  344. #define FUNCTION_CLASS(m_class, m_method_name, m_method_ptr, m_const) \
  345. struct Method_##m_class##_##m_method_name { \
  346. static void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { \
  347. vc_method_call_static(m_method_ptr, base, p_args, p_argcount, r_ret, p_defvals, r_error); \
  348. } \
  349. static void validated_call(Variant *base, const Variant **p_args, int p_argcount, Variant *r_ret) { \
  350. vc_validated_call_static(m_method_ptr, base, p_args, r_ret); \
  351. } \
  352. static void ptrcall(void *p_base, const void **p_args, void *r_ret, int p_argcount) { \
  353. vc_ptrcall(m_method_ptr, p_base, p_args, r_ret); \
  354. } \
  355. static int get_argument_count() { \
  356. return vc_get_argument_count(m_method_ptr); \
  357. } \
  358. static Variant::Type get_argument_type(int p_arg) { \
  359. return vc_get_argument_type(m_method_ptr, p_arg); \
  360. } \
  361. static Variant::Type get_return_type() { \
  362. return vc_get_return_type(m_method_ptr); \
  363. } \
  364. static bool has_return_type() { \
  365. return vc_has_return_type_static(m_method_ptr); \
  366. } \
  367. static bool is_const() { \
  368. return m_const; \
  369. } \
  370. static bool is_static() { \
  371. return false; \
  372. } \
  373. static bool is_vararg() { \
  374. return false; \
  375. } \
  376. static Variant::Type get_base_type() { \
  377. return GetTypeInfo<m_class>::VARIANT_TYPE; \
  378. } \
  379. static StringName get_name() { \
  380. return #m_method_name; \
  381. } \
  382. };
  383. #define VARARG_CLASS(m_class, m_method_name, m_method_ptr, m_has_return, m_return_type) \
  384. struct Method_##m_class##_##m_method_name { \
  385. static void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { \
  386. m_method_ptr(base, p_args, p_argcount, r_ret, r_error); \
  387. } \
  388. static void validated_call(Variant *base, const Variant **p_args, int p_argcount, Variant *r_ret) { \
  389. Callable::CallError ce; \
  390. m_method_ptr(base, p_args, p_argcount, *r_ret, ce); \
  391. } \
  392. static void ptrcall(void *p_base, const void **p_args, void *r_ret, int p_argcount) { \
  393. LocalVector<Variant> vars; \
  394. vars.resize(p_argcount); \
  395. LocalVector<const Variant *> vars_ptrs; \
  396. vars_ptrs.resize(p_argcount); \
  397. for (int i = 0; i < p_argcount; i++) { \
  398. vars[i] = PtrToArg<Variant>::convert(p_args[i]); \
  399. vars_ptrs[i] = &vars[i]; \
  400. } \
  401. Variant base = PtrToArg<m_class>::convert(p_base); \
  402. Variant ret; \
  403. Callable::CallError ce; \
  404. m_method_ptr(&base, (const Variant **)&vars_ptrs[0], p_argcount, ret, ce); \
  405. if (m_has_return) { \
  406. m_return_type r = ret; \
  407. PtrToArg<m_return_type>::encode(ret, r_ret); \
  408. } \
  409. } \
  410. static int get_argument_count() { \
  411. return 0; \
  412. } \
  413. static Variant::Type get_argument_type(int p_arg) { \
  414. return Variant::NIL; \
  415. } \
  416. static Variant::Type get_return_type() { \
  417. return GetTypeInfo<m_return_type>::VARIANT_TYPE; \
  418. } \
  419. static bool has_return_type() { \
  420. return m_has_return; \
  421. } \
  422. static bool is_const() { \
  423. return true; \
  424. } \
  425. static bool is_static() { \
  426. return false; \
  427. } \
  428. static bool is_vararg() { \
  429. return true; \
  430. } \
  431. static Variant::Type get_base_type() { \
  432. return GetTypeInfo<m_class>::VARIANT_TYPE; \
  433. } \
  434. static StringName get_name() { \
  435. return #m_method_name; \
  436. } \
  437. };
  438. #define VARARG_CLASS1(m_class, m_method_name, m_method_ptr, m_arg_type) \
  439. struct Method_##m_class##_##m_method_name { \
  440. static void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { \
  441. m_method_ptr(base, p_args, p_argcount, r_ret, r_error); \
  442. } \
  443. static void validated_call(Variant *base, const Variant **p_args, int p_argcount, Variant *r_ret) { \
  444. Callable::CallError ce; \
  445. m_method_ptr(base, p_args, p_argcount, *r_ret, ce); \
  446. } \
  447. static void ptrcall(void *p_base, const void **p_args, void *r_ret, int p_argcount) { \
  448. LocalVector<Variant> vars; \
  449. vars.resize(p_argcount); \
  450. LocalVector<const Variant *> vars_ptrs; \
  451. vars_ptrs.resize(p_argcount); \
  452. for (int i = 0; i < p_argcount; i++) { \
  453. vars[i] = PtrToArg<Variant>::convert(p_args[i]); \
  454. vars_ptrs[i] = &vars[i]; \
  455. } \
  456. Variant base = PtrToArg<m_class>::convert(p_base); \
  457. Variant ret; \
  458. Callable::CallError ce; \
  459. m_method_ptr(&base, (const Variant **)&vars_ptrs[0], p_argcount, ret, ce); \
  460. } \
  461. static int get_argument_count() { \
  462. return 1; \
  463. } \
  464. static Variant::Type get_argument_type(int p_arg) { \
  465. return m_arg_type; \
  466. } \
  467. static Variant::Type get_return_type() { \
  468. return Variant::NIL; \
  469. } \
  470. static bool has_return_type() { \
  471. return false; \
  472. } \
  473. static bool is_const() { \
  474. return true; \
  475. } \
  476. static bool is_static() { \
  477. return false; \
  478. } \
  479. static bool is_vararg() { \
  480. return true; \
  481. } \
  482. static Variant::Type get_base_type() { \
  483. return GetTypeInfo<m_class>::VARIANT_TYPE; \
  484. } \
  485. static StringName get_name() { \
  486. return #m_method_name; \
  487. } \
  488. };
  489. struct _VariantCall {
  490. static String func_PackedByteArray_get_string_from_ascii(PackedByteArray *p_instance) {
  491. String s;
  492. if (p_instance->size() > 0) {
  493. const uint8_t *r = p_instance->ptr();
  494. CharString cs;
  495. cs.resize(p_instance->size() + 1);
  496. memcpy(cs.ptrw(), r, p_instance->size());
  497. cs[p_instance->size()] = 0;
  498. s = cs.get_data();
  499. }
  500. return s;
  501. }
  502. static String func_PackedByteArray_get_string_from_utf8(PackedByteArray *p_instance) {
  503. String s;
  504. if (p_instance->size() > 0) {
  505. const uint8_t *r = p_instance->ptr();
  506. s.parse_utf8((const char *)r, p_instance->size());
  507. }
  508. return s;
  509. }
  510. static String func_PackedByteArray_get_string_from_utf16(PackedByteArray *p_instance) {
  511. String s;
  512. if (p_instance->size() > 0) {
  513. const uint8_t *r = p_instance->ptr();
  514. s.parse_utf16((const char16_t *)r, floor((double)p_instance->size() / (double)sizeof(char16_t)));
  515. }
  516. return s;
  517. }
  518. static String func_PackedByteArray_get_string_from_utf32(PackedByteArray *p_instance) {
  519. String s;
  520. if (p_instance->size() > 0) {
  521. const uint8_t *r = p_instance->ptr();
  522. s = String((const char32_t *)r, floor((double)p_instance->size() / (double)sizeof(char32_t)));
  523. }
  524. return s;
  525. }
  526. static PackedByteArray func_PackedByteArray_compress(PackedByteArray *p_instance, int p_mode) {
  527. PackedByteArray compressed;
  528. if (p_instance->size() > 0) {
  529. Compression::Mode mode = (Compression::Mode)(p_mode);
  530. compressed.resize(Compression::get_max_compressed_buffer_size(p_instance->size(), mode));
  531. int result = Compression::compress(compressed.ptrw(), p_instance->ptr(), p_instance->size(), mode);
  532. result = result >= 0 ? result : 0;
  533. compressed.resize(result);
  534. }
  535. return compressed;
  536. }
  537. static PackedByteArray func_PackedByteArray_decompress(PackedByteArray *p_instance, int64_t p_buffer_size, int p_mode) {
  538. PackedByteArray decompressed;
  539. Compression::Mode mode = (Compression::Mode)(p_mode);
  540. int64_t buffer_size = p_buffer_size;
  541. if (buffer_size <= 0) {
  542. ERR_FAIL_V_MSG(decompressed, "Decompression buffer size must be greater than zero.");
  543. }
  544. if (p_instance->size() == 0) {
  545. ERR_FAIL_V_MSG(decompressed, "Compressed buffer size must be greater than zero.");
  546. }
  547. decompressed.resize(buffer_size);
  548. int result = Compression::decompress(decompressed.ptrw(), buffer_size, p_instance->ptr(), p_instance->size(), mode);
  549. result = result >= 0 ? result : 0;
  550. decompressed.resize(result);
  551. return decompressed;
  552. }
  553. static PackedByteArray func_PackedByteArray_decompress_dynamic(PackedByteArray *p_instance, int64_t p_buffer_size, int p_mode) {
  554. PackedByteArray decompressed;
  555. int64_t max_output_size = p_buffer_size;
  556. Compression::Mode mode = (Compression::Mode)(p_mode);
  557. int result = Compression::decompress_dynamic(&decompressed, max_output_size, p_instance->ptr(), p_instance->size(), mode);
  558. if (result == OK) {
  559. return decompressed;
  560. } else {
  561. decompressed.clear();
  562. ERR_FAIL_V_MSG(decompressed, "Decompression failed.");
  563. }
  564. }
  565. static String func_PackedByteArray_hex_encode(PackedByteArray *p_instance) {
  566. if (p_instance->size() == 0) {
  567. return String();
  568. }
  569. const uint8_t *r = p_instance->ptr();
  570. String s = String::hex_encode_buffer(&r[0], p_instance->size());
  571. return s;
  572. }
  573. static int64_t func_PackedByteArray_decode_u8(PackedByteArray *p_instance, int64_t p_offset) {
  574. uint64_t size = p_instance->size();
  575. ERR_FAIL_COND_V(p_offset < 0 || p_offset > int64_t(size) - 1, 0);
  576. const uint8_t *r = p_instance->ptr();
  577. return r[p_offset];
  578. }
  579. static int64_t func_PackedByteArray_decode_s8(PackedByteArray *p_instance, int64_t p_offset) {
  580. uint64_t size = p_instance->size();
  581. ERR_FAIL_COND_V(p_offset < 0 || p_offset > int64_t(size) - 1, 0);
  582. const uint8_t *r = p_instance->ptr();
  583. return *((const int8_t *)&r[p_offset]);
  584. }
  585. static int64_t func_PackedByteArray_decode_u16(PackedByteArray *p_instance, int64_t p_offset) {
  586. uint64_t size = p_instance->size();
  587. ERR_FAIL_COND_V(p_offset < 0 || p_offset > (int64_t(size) - 2), 0);
  588. const uint8_t *r = p_instance->ptr();
  589. return decode_uint16(&r[p_offset]);
  590. }
  591. static int64_t func_PackedByteArray_decode_s16(PackedByteArray *p_instance, int64_t p_offset) {
  592. uint64_t size = p_instance->size();
  593. ERR_FAIL_COND_V(p_offset < 0 || p_offset > (int64_t(size) - 2), 0);
  594. const uint8_t *r = p_instance->ptr();
  595. return (int16_t)decode_uint16(&r[p_offset]);
  596. }
  597. static int64_t func_PackedByteArray_decode_u32(PackedByteArray *p_instance, int64_t p_offset) {
  598. uint64_t size = p_instance->size();
  599. ERR_FAIL_COND_V(p_offset < 0 || p_offset > (int64_t(size) - 4), 0);
  600. const uint8_t *r = p_instance->ptr();
  601. return decode_uint32(&r[p_offset]);
  602. }
  603. static int64_t func_PackedByteArray_decode_s32(PackedByteArray *p_instance, int64_t p_offset) {
  604. uint64_t size = p_instance->size();
  605. ERR_FAIL_COND_V(p_offset < 0 || p_offset > (int64_t(size) - 4), 0);
  606. const uint8_t *r = p_instance->ptr();
  607. return (int32_t)decode_uint32(&r[p_offset]);
  608. }
  609. static int64_t func_PackedByteArray_decode_u64(PackedByteArray *p_instance, int64_t p_offset) {
  610. uint64_t size = p_instance->size();
  611. ERR_FAIL_COND_V(p_offset < 0 || p_offset > (int64_t(size) - 8), 0);
  612. const uint8_t *r = p_instance->ptr();
  613. return (int64_t)decode_uint64(&r[p_offset]);
  614. }
  615. static int64_t func_PackedByteArray_decode_s64(PackedByteArray *p_instance, int64_t p_offset) {
  616. uint64_t size = p_instance->size();
  617. ERR_FAIL_COND_V(p_offset < 0 || p_offset > (int64_t(size) - 8), 0);
  618. const uint8_t *r = p_instance->ptr();
  619. return (int64_t)decode_uint64(&r[p_offset]);
  620. }
  621. static double func_PackedByteArray_decode_half(PackedByteArray *p_instance, int64_t p_offset) {
  622. uint64_t size = p_instance->size();
  623. ERR_FAIL_COND_V(p_offset < 0 || p_offset > (int64_t(size) - 2), 0);
  624. const uint8_t *r = p_instance->ptr();
  625. return Math::half_to_float(decode_uint16(&r[p_offset]));
  626. }
  627. static double func_PackedByteArray_decode_float(PackedByteArray *p_instance, int64_t p_offset) {
  628. uint64_t size = p_instance->size();
  629. ERR_FAIL_COND_V(p_offset < 0 || p_offset > (int64_t(size) - 4), 0);
  630. const uint8_t *r = p_instance->ptr();
  631. return decode_float(&r[p_offset]);
  632. }
  633. static double func_PackedByteArray_decode_double(PackedByteArray *p_instance, int64_t p_offset) {
  634. uint64_t size = p_instance->size();
  635. ERR_FAIL_COND_V(p_offset < 0 || p_offset > (int64_t(size) - 8), 0);
  636. const uint8_t *r = p_instance->ptr();
  637. return decode_double(&r[p_offset]);
  638. }
  639. static bool func_PackedByteArray_has_encoded_var(PackedByteArray *p_instance, int64_t p_offset, bool p_allow_objects) {
  640. uint64_t size = p_instance->size();
  641. ERR_FAIL_COND_V(p_offset < 0, false);
  642. const uint8_t *r = p_instance->ptr();
  643. Variant ret;
  644. Error err = decode_variant(ret, r + p_offset, size - p_offset, nullptr, p_allow_objects);
  645. return err == OK;
  646. }
  647. static Variant func_PackedByteArray_decode_var(PackedByteArray *p_instance, int64_t p_offset, bool p_allow_objects) {
  648. uint64_t size = p_instance->size();
  649. ERR_FAIL_COND_V(p_offset < 0, Variant());
  650. const uint8_t *r = p_instance->ptr();
  651. Variant ret;
  652. Error err = decode_variant(ret, r + p_offset, size - p_offset, nullptr, p_allow_objects);
  653. if (err != OK) {
  654. ret = Variant();
  655. }
  656. return ret;
  657. }
  658. static int64_t func_PackedByteArray_decode_var_size(PackedByteArray *p_instance, int64_t p_offset, bool p_allow_objects) {
  659. uint64_t size = p_instance->size();
  660. ERR_FAIL_COND_V(p_offset < 0, 0);
  661. const uint8_t *r = p_instance->ptr();
  662. Variant ret;
  663. int r_size;
  664. Error err = decode_variant(ret, r + p_offset, size - p_offset, &r_size, p_allow_objects);
  665. if (err == OK) {
  666. return r_size;
  667. }
  668. return 0;
  669. }
  670. static void func_PackedByteArray_encode_u8(PackedByteArray *p_instance, int64_t p_offset, int64_t p_value) {
  671. uint64_t size = p_instance->size();
  672. ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 1);
  673. uint8_t *w = p_instance->ptrw();
  674. *((uint8_t *)&w[p_offset]) = p_value;
  675. }
  676. static void func_PackedByteArray_encode_s8(PackedByteArray *p_instance, int64_t p_offset, int64_t p_value) {
  677. uint64_t size = p_instance->size();
  678. ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 1);
  679. uint8_t *w = p_instance->ptrw();
  680. *((int8_t *)&w[p_offset]) = p_value;
  681. }
  682. static void func_PackedByteArray_encode_u16(PackedByteArray *p_instance, int64_t p_offset, int64_t p_value) {
  683. uint64_t size = p_instance->size();
  684. ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 2);
  685. uint8_t *w = p_instance->ptrw();
  686. encode_uint16((uint16_t)p_value, &w[p_offset]);
  687. }
  688. static void func_PackedByteArray_encode_s16(PackedByteArray *p_instance, int64_t p_offset, int64_t p_value) {
  689. uint64_t size = p_instance->size();
  690. ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 2);
  691. uint8_t *w = p_instance->ptrw();
  692. encode_uint16((int16_t)p_value, &w[p_offset]);
  693. }
  694. static void func_PackedByteArray_encode_u32(PackedByteArray *p_instance, int64_t p_offset, int64_t p_value) {
  695. uint64_t size = p_instance->size();
  696. ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 4);
  697. uint8_t *w = p_instance->ptrw();
  698. encode_uint32((uint32_t)p_value, &w[p_offset]);
  699. }
  700. static void func_PackedByteArray_encode_s32(PackedByteArray *p_instance, int64_t p_offset, int64_t p_value) {
  701. uint64_t size = p_instance->size();
  702. ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 4);
  703. uint8_t *w = p_instance->ptrw();
  704. encode_uint32((int32_t)p_value, &w[p_offset]);
  705. }
  706. static void func_PackedByteArray_encode_u64(PackedByteArray *p_instance, int64_t p_offset, int64_t p_value) {
  707. uint64_t size = p_instance->size();
  708. ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 8);
  709. uint8_t *w = p_instance->ptrw();
  710. encode_uint64((uint64_t)p_value, &w[p_offset]);
  711. }
  712. static void func_PackedByteArray_encode_s64(PackedByteArray *p_instance, int64_t p_offset, int64_t p_value) {
  713. uint64_t size = p_instance->size();
  714. ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 8);
  715. uint8_t *w = p_instance->ptrw();
  716. encode_uint64((int64_t)p_value, &w[p_offset]);
  717. }
  718. static void func_PackedByteArray_encode_half(PackedByteArray *p_instance, int64_t p_offset, double p_value) {
  719. uint64_t size = p_instance->size();
  720. ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 2);
  721. uint8_t *w = p_instance->ptrw();
  722. encode_uint16(Math::make_half_float(p_value), &w[p_offset]);
  723. }
  724. static void func_PackedByteArray_encode_float(PackedByteArray *p_instance, int64_t p_offset, double p_value) {
  725. uint64_t size = p_instance->size();
  726. ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 4);
  727. uint8_t *w = p_instance->ptrw();
  728. encode_float(p_value, &w[p_offset]);
  729. }
  730. static void func_PackedByteArray_encode_double(PackedByteArray *p_instance, int64_t p_offset, double p_value) {
  731. uint64_t size = p_instance->size();
  732. ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 8);
  733. uint8_t *w = p_instance->ptrw();
  734. encode_double(p_value, &w[p_offset]);
  735. }
  736. static int64_t func_PackedByteArray_encode_var(PackedByteArray *p_instance, int64_t p_offset, const Variant &p_value, bool p_allow_objects) {
  737. uint64_t size = p_instance->size();
  738. ERR_FAIL_COND_V(p_offset < 0, -1);
  739. uint8_t *w = p_instance->ptrw();
  740. int len;
  741. Error err = encode_variant(p_value, nullptr, len, p_allow_objects);
  742. if (err != OK) {
  743. return -1;
  744. }
  745. if (uint64_t(p_offset + len) > size) {
  746. return -1; // did not fit
  747. }
  748. encode_variant(p_value, w + p_offset, len, p_allow_objects);
  749. return len;
  750. }
  751. static void func_Callable_call(Variant *v, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
  752. Callable *callable = VariantGetInternalPtr<Callable>::get_ptr(v);
  753. callable->call(p_args, p_argcount, r_ret, r_error);
  754. }
  755. static void func_Callable_call_deferred(Variant *v, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
  756. Callable *callable = VariantGetInternalPtr<Callable>::get_ptr(v);
  757. callable->call_deferred(p_args, p_argcount);
  758. }
  759. static void func_Callable_rpc(Variant *v, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
  760. Callable *callable = VariantGetInternalPtr<Callable>::get_ptr(v);
  761. callable->rpc(0, p_args, p_argcount, r_error);
  762. }
  763. static void func_Callable_rpc_id(Variant *v, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
  764. if (p_argcount == 0) {
  765. r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  766. r_error.argument = 0;
  767. r_error.expected = 1;
  768. } else if (p_args[0]->get_type() != Variant::INT) {
  769. r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
  770. r_error.argument = 0;
  771. r_error.expected = Variant::INT;
  772. } else {
  773. Callable *callable = VariantGetInternalPtr<Callable>::get_ptr(v);
  774. callable->rpc(*p_args[0], &p_args[1], p_argcount - 1, r_error);
  775. }
  776. }
  777. static void func_Callable_bind(Variant *v, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
  778. Callable *callable = VariantGetInternalPtr<Callable>::get_ptr(v);
  779. r_ret = callable->bind(p_args, p_argcount);
  780. }
  781. static void func_Signal_emit(Variant *v, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
  782. Signal *signal = VariantGetInternalPtr<Signal>::get_ptr(v);
  783. signal->emit(p_args, p_argcount);
  784. }
  785. struct ConstantData {
  786. Map<StringName, int> value;
  787. #ifdef DEBUG_ENABLED
  788. List<StringName> value_ordered;
  789. #endif
  790. Map<StringName, Variant> variant_value;
  791. #ifdef DEBUG_ENABLED
  792. List<StringName> variant_value_ordered;
  793. #endif
  794. };
  795. static ConstantData *constant_data;
  796. static void add_constant(int p_type, StringName p_constant_name, int p_constant_value) {
  797. constant_data[p_type].value[p_constant_name] = p_constant_value;
  798. #ifdef DEBUG_ENABLED
  799. constant_data[p_type].value_ordered.push_back(p_constant_name);
  800. #endif
  801. }
  802. static void add_variant_constant(int p_type, StringName p_constant_name, const Variant &p_constant_value) {
  803. constant_data[p_type].variant_value[p_constant_name] = p_constant_value;
  804. #ifdef DEBUG_ENABLED
  805. constant_data[p_type].variant_value_ordered.push_back(p_constant_name);
  806. #endif
  807. }
  808. };
  809. _VariantCall::ConstantData *_VariantCall::constant_data = nullptr;
  810. struct VariantBuiltInMethodInfo {
  811. void (*call)(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error);
  812. Variant::ValidatedBuiltInMethod validated_call;
  813. Variant::PTRBuiltInMethod ptrcall;
  814. Vector<Variant> default_arguments;
  815. Vector<String> argument_names;
  816. bool is_const;
  817. bool is_static;
  818. bool has_return_type;
  819. bool is_vararg;
  820. Variant::Type return_type;
  821. int argument_count;
  822. Variant::Type (*get_argument_type)(int p_arg);
  823. };
  824. typedef OAHashMap<StringName, VariantBuiltInMethodInfo> BuiltinMethodMap;
  825. static BuiltinMethodMap *builtin_method_info;
  826. static List<StringName> *builtin_method_names;
  827. template <class T>
  828. static void register_builtin_method(const Vector<String> &p_argnames, const Vector<Variant> &p_def_args) {
  829. StringName name = T::get_name();
  830. ERR_FAIL_COND(builtin_method_info[T::get_base_type()].has(name));
  831. VariantBuiltInMethodInfo imi;
  832. imi.call = T::call;
  833. imi.validated_call = T::validated_call;
  834. if (T::is_vararg()) {
  835. imi.ptrcall = nullptr;
  836. } else {
  837. imi.ptrcall = T::ptrcall;
  838. }
  839. imi.default_arguments = p_def_args;
  840. imi.argument_names = p_argnames;
  841. imi.is_const = T::is_const();
  842. imi.is_static = T::is_static();
  843. imi.is_vararg = T::is_vararg();
  844. imi.has_return_type = T::has_return_type();
  845. imi.return_type = T::get_return_type();
  846. imi.argument_count = T::get_argument_count();
  847. imi.get_argument_type = T::get_argument_type;
  848. #ifdef DEBUG_METHODS_ENABLED
  849. ERR_FAIL_COND(!imi.is_vararg && imi.argument_count != imi.argument_names.size());
  850. #endif
  851. builtin_method_info[T::get_base_type()].insert(name, imi);
  852. builtin_method_names[T::get_base_type()].push_back(name);
  853. }
  854. void Variant::call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
  855. if (type == Variant::OBJECT) {
  856. //call object
  857. Object *obj = _get_obj().obj;
  858. if (!obj) {
  859. r_error.error = Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL;
  860. return;
  861. }
  862. #ifdef DEBUG_ENABLED
  863. if (EngineDebugger::is_active() && !_get_obj().id.is_ref_counted() && ObjectDB::get_instance(_get_obj().id) == nullptr) {
  864. r_error.error = Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL;
  865. return;
  866. }
  867. #endif
  868. r_ret = _get_obj().obj->call(p_method, p_args, p_argcount, r_error);
  869. //else if (type==Variant::METHOD) {
  870. } else {
  871. r_error.error = Callable::CallError::CALL_OK;
  872. const VariantBuiltInMethodInfo *imf = builtin_method_info[type].lookup_ptr(p_method);
  873. if (!imf) {
  874. r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
  875. return;
  876. }
  877. imf->call(this, p_args, p_argcount, r_ret, imf->default_arguments, r_error);
  878. }
  879. }
  880. void Variant::call_static(Variant::Type p_type, const StringName &p_method, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
  881. r_error.error = Callable::CallError::CALL_OK;
  882. const VariantBuiltInMethodInfo *imf = builtin_method_info[p_type].lookup_ptr(p_method);
  883. if (!imf) {
  884. r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
  885. return;
  886. }
  887. if (!imf->is_static) {
  888. r_error.error = Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL;
  889. return;
  890. }
  891. imf->call(nullptr, p_args, p_argcount, r_ret, imf->default_arguments, r_error);
  892. }
  893. bool Variant::has_method(const StringName &p_method) const {
  894. if (type == OBJECT) {
  895. Object *obj = get_validated_object();
  896. if (!obj) {
  897. return false;
  898. }
  899. return obj->has_method(p_method);
  900. }
  901. return builtin_method_info[type].has(p_method);
  902. }
  903. bool Variant::has_builtin_method(Variant::Type p_type, const StringName &p_method) {
  904. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, false);
  905. return builtin_method_info[p_type].has(p_method);
  906. }
  907. Variant::ValidatedBuiltInMethod Variant::get_validated_builtin_method(Variant::Type p_type, const StringName &p_method) {
  908. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, nullptr);
  909. const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
  910. ERR_FAIL_COND_V(!method, nullptr);
  911. return method->validated_call;
  912. }
  913. Variant::PTRBuiltInMethod Variant::get_ptr_builtin_method(Variant::Type p_type, const StringName &p_method) {
  914. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, nullptr);
  915. const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
  916. ERR_FAIL_COND_V(!method, nullptr);
  917. return method->ptrcall;
  918. }
  919. int Variant::get_builtin_method_argument_count(Variant::Type p_type, const StringName &p_method) {
  920. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, 0);
  921. const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
  922. ERR_FAIL_COND_V(!method, 0);
  923. return method->argument_count;
  924. }
  925. Variant::Type Variant::get_builtin_method_argument_type(Variant::Type p_type, const StringName &p_method, int p_argument) {
  926. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, Variant::NIL);
  927. const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
  928. ERR_FAIL_COND_V(!method, Variant::NIL);
  929. ERR_FAIL_INDEX_V(p_argument, method->argument_count, Variant::NIL);
  930. return method->get_argument_type(p_argument);
  931. }
  932. String Variant::get_builtin_method_argument_name(Variant::Type p_type, const StringName &p_method, int p_argument) {
  933. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, String());
  934. const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
  935. ERR_FAIL_COND_V(!method, String());
  936. #ifdef DEBUG_METHODS_ENABLED
  937. ERR_FAIL_INDEX_V(p_argument, method->argument_count, String());
  938. return method->argument_names[p_argument];
  939. #else
  940. return "arg" + itos(p_argument + 1);
  941. #endif
  942. }
  943. Vector<Variant> Variant::get_builtin_method_default_arguments(Variant::Type p_type, const StringName &p_method) {
  944. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, Vector<Variant>());
  945. const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
  946. ERR_FAIL_COND_V(!method, Vector<Variant>());
  947. return method->default_arguments;
  948. }
  949. bool Variant::has_builtin_method_return_value(Variant::Type p_type, const StringName &p_method) {
  950. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, false);
  951. const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
  952. ERR_FAIL_COND_V(!method, false);
  953. return method->has_return_type;
  954. }
  955. void Variant::get_builtin_method_list(Variant::Type p_type, List<StringName> *p_list) {
  956. ERR_FAIL_INDEX(p_type, Variant::VARIANT_MAX);
  957. for (List<StringName>::Element *E = builtin_method_names[p_type].front(); E; E = E->next()) {
  958. p_list->push_back(E->get());
  959. }
  960. }
  961. int Variant::get_builtin_method_count(Variant::Type p_type) {
  962. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, -1);
  963. return builtin_method_names[p_type].size();
  964. }
  965. Variant::Type Variant::get_builtin_method_return_type(Variant::Type p_type, const StringName &p_method) {
  966. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, Variant::NIL);
  967. const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
  968. ERR_FAIL_COND_V(!method, Variant::NIL);
  969. return method->return_type;
  970. }
  971. bool Variant::is_builtin_method_const(Variant::Type p_type, const StringName &p_method) {
  972. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, false);
  973. const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
  974. ERR_FAIL_COND_V(!method, false);
  975. return method->is_const;
  976. }
  977. bool Variant::is_builtin_method_static(Variant::Type p_type, const StringName &p_method) {
  978. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, false);
  979. const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
  980. ERR_FAIL_COND_V(!method, false);
  981. return method->is_static;
  982. }
  983. bool Variant::is_builtin_method_vararg(Variant::Type p_type, const StringName &p_method) {
  984. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, false);
  985. const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
  986. ERR_FAIL_COND_V(!method, false);
  987. return method->is_vararg;
  988. }
  989. uint32_t Variant::get_builtin_method_hash(Variant::Type p_type, const StringName &p_method) {
  990. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, 0);
  991. const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
  992. ERR_FAIL_COND_V(!method, 0);
  993. uint32_t hash = hash_djb2_one_32(method->is_const);
  994. hash = hash_djb2_one_32(method->is_static, hash);
  995. hash = hash_djb2_one_32(method->is_vararg, hash);
  996. hash = hash_djb2_one_32(method->has_return_type, hash);
  997. if (method->has_return_type) {
  998. hash = hash_djb2_one_32(method->return_type, hash);
  999. }
  1000. hash = hash_djb2_one_32(method->argument_count, hash);
  1001. for (int i = 0; i < method->argument_count; i++) {
  1002. hash = method->get_argument_type(i);
  1003. }
  1004. return hash;
  1005. }
  1006. void Variant::get_method_list(List<MethodInfo> *p_list) const {
  1007. if (type == OBJECT) {
  1008. Object *obj = get_validated_object();
  1009. if (obj) {
  1010. obj->get_method_list(p_list);
  1011. }
  1012. } else {
  1013. for (List<StringName>::Element *E = builtin_method_names[type].front(); E; E = E->next()) {
  1014. const VariantBuiltInMethodInfo *method = builtin_method_info[type].lookup_ptr(E->get());
  1015. ERR_CONTINUE(!method);
  1016. MethodInfo mi;
  1017. mi.name = E->get();
  1018. //return type
  1019. if (method->has_return_type) {
  1020. mi.return_val.type = method->return_type;
  1021. if (mi.return_val.type == Variant::NIL) {
  1022. mi.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
  1023. }
  1024. }
  1025. if (method->is_const) {
  1026. mi.flags |= METHOD_FLAG_CONST;
  1027. }
  1028. if (method->is_vararg) {
  1029. mi.flags |= METHOD_FLAG_VARARG;
  1030. }
  1031. if (method->is_static) {
  1032. mi.flags |= METHOD_FLAG_STATIC;
  1033. }
  1034. for (int i = 0; i < method->argument_count; i++) {
  1035. PropertyInfo pi;
  1036. #ifdef DEBUG_METHODS_ENABLED
  1037. pi.name = method->argument_names[i];
  1038. #else
  1039. pi.name = "arg" + itos(i + 1);
  1040. #endif
  1041. pi.type = method->get_argument_type(i);
  1042. if (pi.type == Variant::NIL) {
  1043. pi.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
  1044. }
  1045. mi.arguments.push_back(pi);
  1046. }
  1047. mi.default_arguments = method->default_arguments;
  1048. p_list->push_back(mi);
  1049. }
  1050. }
  1051. }
  1052. void Variant::get_constants_for_type(Variant::Type p_type, List<StringName> *p_constants) {
  1053. ERR_FAIL_INDEX(p_type, Variant::VARIANT_MAX);
  1054. _VariantCall::ConstantData &cd = _VariantCall::constant_data[p_type];
  1055. #ifdef DEBUG_ENABLED
  1056. for (List<StringName>::Element *E = cd.value_ordered.front(); E; E = E->next()) {
  1057. p_constants->push_back(E->get());
  1058. #else
  1059. for (Map<StringName, int>::Element *E = cd.value.front(); E; E = E->next()) {
  1060. p_constants->push_back(E->key());
  1061. #endif
  1062. }
  1063. #ifdef DEBUG_ENABLED
  1064. for (List<StringName>::Element *E = cd.variant_value_ordered.front(); E; E = E->next()) {
  1065. p_constants->push_back(E->get());
  1066. #else
  1067. for (Map<StringName, Variant>::Element *E = cd.variant_value.front(); E; E = E->next()) {
  1068. p_constants->push_back(E->key());
  1069. #endif
  1070. }
  1071. }
  1072. int Variant::get_constants_count_for_type(Variant::Type p_type) {
  1073. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, -1);
  1074. _VariantCall::ConstantData &cd = _VariantCall::constant_data[p_type];
  1075. return cd.value.size() + cd.variant_value.size();
  1076. }
  1077. bool Variant::has_constant(Variant::Type p_type, const StringName &p_value) {
  1078. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, false);
  1079. _VariantCall::ConstantData &cd = _VariantCall::constant_data[p_type];
  1080. return cd.value.has(p_value) || cd.variant_value.has(p_value);
  1081. }
  1082. Variant Variant::get_constant_value(Variant::Type p_type, const StringName &p_value, bool *r_valid) {
  1083. if (r_valid) {
  1084. *r_valid = false;
  1085. }
  1086. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, 0);
  1087. _VariantCall::ConstantData &cd = _VariantCall::constant_data[p_type];
  1088. Map<StringName, int>::Element *E = cd.value.find(p_value);
  1089. if (!E) {
  1090. Map<StringName, Variant>::Element *F = cd.variant_value.find(p_value);
  1091. if (F) {
  1092. if (r_valid) {
  1093. *r_valid = true;
  1094. }
  1095. return F->get();
  1096. } else {
  1097. return -1;
  1098. }
  1099. }
  1100. if (r_valid) {
  1101. *r_valid = true;
  1102. }
  1103. return E->get();
  1104. }
  1105. #ifdef DEBUG_METHODS_ENABLED
  1106. #define bind_method(m_type, m_method, m_arg_names, m_default_args) \
  1107. METHOD_CLASS(m_type, m_method, &m_type::m_method); \
  1108. register_builtin_method<Method_##m_type##_##m_method>(m_arg_names, m_default_args);
  1109. #else
  1110. #define bind_method(m_type, m_method, m_arg_names, m_default_args) \
  1111. METHOD_CLASS(m_type, m_method, &m_type ::m_method); \
  1112. register_builtin_method<Method_##m_type##_##m_method>(sarray(), m_default_args);
  1113. #endif
  1114. #ifdef DEBUG_METHODS_ENABLED
  1115. #define bind_static_method(m_type, m_method, m_arg_names, m_default_args) \
  1116. STATIC_METHOD_CLASS(m_type, m_method, m_type::m_method); \
  1117. register_builtin_method<Method_##m_type##_##m_method>(m_arg_names, m_default_args);
  1118. #else
  1119. #define bind_static_method(m_type, m_method, m_arg_names, m_default_args) \
  1120. STATIC_METHOD_CLASS(m_type, m_method, m_type ::m_method); \
  1121. register_builtin_method<Method_##m_type##_##m_method>(sarray(), m_default_args);
  1122. #endif
  1123. #ifdef DEBUG_METHODS_ENABLED
  1124. #define bind_methodv(m_type, m_name, m_method, m_arg_names, m_default_args) \
  1125. METHOD_CLASS(m_type, m_name, m_method); \
  1126. register_builtin_method<Method_##m_type##_##m_name>(m_arg_names, m_default_args);
  1127. #else
  1128. #define bind_methodv(m_type, m_name, m_method, m_arg_names, m_default_args) \
  1129. METHOD_CLASS(m_type, m_name, m_method); \
  1130. register_builtin_method<Method_##m_type##_##m_name>(sarray(), m_default_args);
  1131. #endif
  1132. #ifdef DEBUG_METHODS_ENABLED
  1133. #define bind_function(m_type, m_name, m_method, m_arg_names, m_default_args) \
  1134. FUNCTION_CLASS(m_type, m_name, m_method, true); \
  1135. register_builtin_method<Method_##m_type##_##m_name>(m_arg_names, m_default_args);
  1136. #else
  1137. #define bind_function(m_type, m_name, m_method, m_arg_names, m_default_args) \
  1138. FUNCTION_CLASS(m_type, m_name, m_method, true); \
  1139. register_builtin_method<Method_##m_type##_##m_name>(sarray(), m_default_args);
  1140. #endif
  1141. #ifdef DEBUG_METHODS_ENABLED
  1142. #define bind_functionnc(m_type, m_name, m_method, m_arg_names, m_default_args) \
  1143. FUNCTION_CLASS(m_type, m_name, m_method, false); \
  1144. register_builtin_method<Method_##m_type##_##m_name>(m_arg_names, m_default_args);
  1145. #else
  1146. #define bind_functionnc(m_type, m_name, m_method, m_arg_names, m_default_args) \
  1147. FUNCTION_CLASS(m_type, m_name, m_method, false); \
  1148. register_builtin_method<Method_##m_type##_##m_name>(sarray(), m_default_args);
  1149. #endif
  1150. #define bind_custom(m_type, m_name, m_method, m_has_return, m_ret_type) \
  1151. VARARG_CLASS(m_type, m_name, m_method, m_has_return, m_ret_type) \
  1152. register_builtin_method<Method_##m_type##_##m_name>(sarray(), Vector<Variant>());
  1153. #define bind_custom1(m_type, m_name, m_method, m_arg_type, m_arg_name) \
  1154. VARARG_CLASS1(m_type, m_name, m_method, m_arg_type) \
  1155. register_builtin_method<Method_##m_type##_##m_name>(sarray(m_arg_name), Vector<Variant>());
  1156. static void _register_variant_builtin_methods() {
  1157. _VariantCall::constant_data = memnew_arr(_VariantCall::ConstantData, Variant::VARIANT_MAX);
  1158. builtin_method_info = memnew_arr(BuiltinMethodMap, Variant::VARIANT_MAX);
  1159. builtin_method_names = memnew_arr(List<StringName>, Variant::VARIANT_MAX);
  1160. /* String */
  1161. bind_method(String, casecmp_to, sarray("to"), varray());
  1162. bind_method(String, nocasecmp_to, sarray("to"), varray());
  1163. bind_method(String, naturalnocasecmp_to, sarray("to"), varray());
  1164. bind_method(String, length, sarray(), varray());
  1165. bind_method(String, substr, sarray("from", "len"), varray(-1));
  1166. bind_methodv(String, find, static_cast<int (String::*)(const String &, int) const>(&String::find), sarray("what", "from"), varray(0));
  1167. bind_method(String, count, sarray("what", "from", "to"), varray(0, 0));
  1168. bind_method(String, countn, sarray("what", "from", "to"), varray(0, 0));
  1169. bind_method(String, findn, sarray("what", "from"), varray(0));
  1170. bind_method(String, rfind, sarray("what", "from"), varray(-1));
  1171. bind_method(String, rfindn, sarray("what", "from"), varray(-1));
  1172. bind_method(String, match, sarray("expr"), varray());
  1173. bind_method(String, matchn, sarray("expr"), varray());
  1174. bind_methodv(String, begins_with, static_cast<bool (String::*)(const String &) const>(&String::begins_with), sarray("text"), varray());
  1175. bind_method(String, ends_with, sarray("text"), varray());
  1176. bind_method(String, is_subsequence_of, sarray("text"), varray());
  1177. bind_method(String, is_subsequence_ofi, sarray("text"), varray());
  1178. bind_method(String, bigrams, sarray(), varray());
  1179. bind_method(String, similarity, sarray("text"), varray());
  1180. bind_method(String, format, sarray("values", "placeholder"), varray("{_}"));
  1181. bind_methodv(String, replace, static_cast<String (String::*)(const String &, const String &) const>(&String::replace), sarray("what", "forwhat"), varray());
  1182. bind_method(String, replacen, sarray("what", "forwhat"), varray());
  1183. bind_method(String, repeat, sarray("count"), varray());
  1184. bind_method(String, insert, sarray("position", "what"), varray());
  1185. bind_method(String, capitalize, sarray(), varray());
  1186. bind_method(String, split, sarray("delimiter", "allow_empty", "maxsplit"), varray(true, 0));
  1187. bind_method(String, rsplit, sarray("delimiter", "allow_empty", "maxsplit"), varray(true, 0));
  1188. bind_method(String, split_floats, sarray("delimiter", "allow_empty"), varray(true));
  1189. bind_method(String, join, sarray("parts"), varray());
  1190. bind_method(String, to_upper, sarray(), varray());
  1191. bind_method(String, to_lower, sarray(), varray());
  1192. bind_method(String, left, sarray("position"), varray());
  1193. bind_method(String, right, sarray("position"), varray());
  1194. bind_method(String, strip_edges, sarray("left", "right"), varray(true, true));
  1195. bind_method(String, strip_escapes, sarray(), varray());
  1196. bind_method(String, lstrip, sarray("chars"), varray());
  1197. bind_method(String, rstrip, sarray("chars"), varray());
  1198. bind_method(String, get_extension, sarray(), varray());
  1199. bind_method(String, get_basename, sarray(), varray());
  1200. bind_method(String, plus_file, sarray("file"), varray());
  1201. bind_method(String, unicode_at, sarray("at"), varray());
  1202. bind_method(String, dedent, sarray(), varray());
  1203. // FIXME: String needs to be immutable when binding
  1204. //bind_method(String, erase, sarray("position", "chars"), varray());
  1205. bind_method(String, hash, sarray(), varray());
  1206. bind_method(String, md5_text, sarray(), varray());
  1207. bind_method(String, sha1_text, sarray(), varray());
  1208. bind_method(String, sha256_text, sarray(), varray());
  1209. bind_method(String, md5_buffer, sarray(), varray());
  1210. bind_method(String, sha1_buffer, sarray(), varray());
  1211. bind_method(String, sha256_buffer, sarray(), varray());
  1212. bind_method(String, is_empty, sarray(), varray());
  1213. // FIXME: Static function, not sure how to bind
  1214. //bind_method(String, humanize_size, sarray("size"), varray());
  1215. bind_method(String, is_absolute_path, sarray(), varray());
  1216. bind_method(String, is_rel_path, sarray(), varray());
  1217. bind_method(String, get_base_dir, sarray(), varray());
  1218. bind_method(String, get_file, sarray(), varray());
  1219. bind_method(String, xml_escape, sarray("escape_quotes"), varray(false));
  1220. bind_method(String, xml_unescape, sarray(), varray());
  1221. bind_method(String, uri_encode, sarray(), varray());
  1222. bind_method(String, uri_decode, sarray(), varray());
  1223. bind_method(String, c_escape, sarray(), varray());
  1224. bind_method(String, c_unescape, sarray(), varray());
  1225. bind_method(String, json_escape, sarray(), varray());
  1226. bind_method(String, validate_node_name, sarray(), varray());
  1227. bind_method(String, is_valid_identifier, sarray(), varray());
  1228. bind_method(String, is_valid_int, sarray(), varray());
  1229. bind_method(String, is_valid_float, sarray(), varray());
  1230. bind_method(String, is_valid_hex_number, sarray("with_prefix"), varray(false));
  1231. bind_method(String, is_valid_html_color, sarray(), varray());
  1232. bind_method(String, is_valid_ip_address, sarray(), varray());
  1233. bind_method(String, is_valid_filename, sarray(), varray());
  1234. bind_method(String, to_int, sarray(), varray());
  1235. bind_method(String, to_float, sarray(), varray());
  1236. bind_method(String, hex_to_int, sarray(), varray());
  1237. bind_method(String, bin_to_int, sarray(), varray());
  1238. bind_method(String, lpad, sarray("min_length", "character"), varray(" "));
  1239. bind_method(String, rpad, sarray("min_length", "character"), varray(" "));
  1240. bind_method(String, pad_decimals, sarray("digits"), varray());
  1241. bind_method(String, pad_zeros, sarray("digits"), varray());
  1242. bind_method(String, trim_prefix, sarray("prefix"), varray());
  1243. bind_method(String, trim_suffix, sarray("suffix"), varray());
  1244. bind_method(String, to_ascii_buffer, sarray(), varray());
  1245. bind_method(String, to_utf8_buffer, sarray(), varray());
  1246. bind_method(String, to_utf16_buffer, sarray(), varray());
  1247. bind_method(String, to_utf32_buffer, sarray(), varray());
  1248. bind_static_method(String, num_scientific, sarray("number"), varray());
  1249. bind_static_method(String, num, sarray("number", "decimals"), varray(-1));
  1250. bind_static_method(String, chr, sarray("char"), varray());
  1251. bind_static_method(String, humanize_size, sarray("size"), varray());
  1252. /* Vector2 */
  1253. bind_method(Vector2, angle, sarray(), varray());
  1254. bind_method(Vector2, angle_to, sarray("to"), varray());
  1255. bind_method(Vector2, angle_to_point, sarray("to"), varray());
  1256. bind_method(Vector2, direction_to, sarray("b"), varray());
  1257. bind_method(Vector2, distance_to, sarray("to"), varray());
  1258. bind_method(Vector2, distance_squared_to, sarray("to"), varray());
  1259. bind_method(Vector2, length, sarray(), varray());
  1260. bind_method(Vector2, length_squared, sarray(), varray());
  1261. bind_method(Vector2, limit_length, sarray("length"), varray(1.0));
  1262. bind_method(Vector2, normalized, sarray(), varray());
  1263. bind_method(Vector2, is_normalized, sarray(), varray());
  1264. bind_method(Vector2, is_equal_approx, sarray("to"), varray());
  1265. bind_method(Vector2, posmod, sarray("mod"), varray());
  1266. bind_method(Vector2, posmodv, sarray("modv"), varray());
  1267. bind_method(Vector2, project, sarray("b"), varray());
  1268. bind_method(Vector2, lerp, sarray("to", "weight"), varray());
  1269. bind_method(Vector2, slerp, sarray("to", "weight"), varray());
  1270. bind_method(Vector2, cubic_interpolate, sarray("b", "pre_a", "post_b", "weight"), varray());
  1271. bind_method(Vector2, move_toward, sarray("to", "delta"), varray());
  1272. bind_method(Vector2, rotated, sarray("phi"), varray());
  1273. bind_method(Vector2, orthogonal, sarray(), varray());
  1274. bind_method(Vector2, floor, sarray(), varray());
  1275. bind_method(Vector2, ceil, sarray(), varray());
  1276. bind_method(Vector2, round, sarray(), varray());
  1277. bind_method(Vector2, aspect, sarray(), varray());
  1278. bind_method(Vector2, dot, sarray("with"), varray());
  1279. bind_method(Vector2, slide, sarray("n"), varray());
  1280. bind_method(Vector2, bounce, sarray("n"), varray());
  1281. bind_method(Vector2, reflect, sarray("n"), varray());
  1282. bind_method(Vector2, cross, sarray("with"), varray());
  1283. bind_method(Vector2, abs, sarray(), varray());
  1284. bind_method(Vector2, sign, sarray(), varray());
  1285. bind_method(Vector2, clamp, sarray("min", "max"), varray());
  1286. bind_method(Vector2, snapped, sarray("step"), varray());
  1287. /* Vector2i */
  1288. bind_method(Vector2i, aspect, sarray(), varray());
  1289. bind_method(Vector2i, sign, sarray(), varray());
  1290. bind_method(Vector2i, abs, sarray(), varray());
  1291. bind_method(Vector2i, clamp, sarray("min", "max"), varray());
  1292. /* Rect2 */
  1293. bind_method(Rect2, get_area, sarray(), varray());
  1294. bind_method(Rect2, has_no_area, sarray(), varray());
  1295. bind_method(Rect2, has_point, sarray("point"), varray());
  1296. bind_method(Rect2, is_equal_approx, sarray("rect"), varray());
  1297. bind_method(Rect2, intersects, sarray("b", "include_borders"), varray(false));
  1298. bind_method(Rect2, encloses, sarray("b"), varray());
  1299. bind_method(Rect2, intersection, sarray("b"), varray());
  1300. bind_method(Rect2, merge, sarray("b"), varray());
  1301. bind_method(Rect2, expand, sarray("to"), varray());
  1302. bind_method(Rect2, grow, sarray("amount"), varray());
  1303. bind_methodv(Rect2, grow_side, &Rect2::grow_side_bind, sarray("side", "amount"), varray());
  1304. bind_method(Rect2, grow_individual, sarray("left", "top", "right", "bottom"), varray());
  1305. bind_method(Rect2, abs, sarray(), varray());
  1306. /* Rect2i */
  1307. bind_method(Rect2i, get_area, sarray(), varray());
  1308. bind_method(Rect2i, has_no_area, sarray(), varray());
  1309. bind_method(Rect2i, has_point, sarray("point"), varray());
  1310. bind_method(Rect2i, intersects, sarray("b"), varray());
  1311. bind_method(Rect2i, encloses, sarray("b"), varray());
  1312. bind_method(Rect2i, intersection, sarray("b"), varray());
  1313. bind_method(Rect2i, merge, sarray("b"), varray());
  1314. bind_method(Rect2i, expand, sarray("to"), varray());
  1315. bind_method(Rect2i, grow, sarray("amount"), varray());
  1316. bind_methodv(Rect2i, grow_side, &Rect2i::grow_side_bind, sarray("side", "amount"), varray());
  1317. bind_method(Rect2i, grow_individual, sarray("left", "top", "right", "bottom"), varray());
  1318. bind_method(Rect2i, abs, sarray(), varray());
  1319. /* Vector3 */
  1320. bind_method(Vector3, min_axis, sarray(), varray());
  1321. bind_method(Vector3, max_axis, sarray(), varray());
  1322. bind_method(Vector3, angle_to, sarray("to"), varray());
  1323. bind_method(Vector3, signed_angle_to, sarray("to", "axis"), varray());
  1324. bind_method(Vector3, direction_to, sarray("b"), varray());
  1325. bind_method(Vector3, distance_to, sarray("b"), varray());
  1326. bind_method(Vector3, distance_squared_to, sarray("b"), varray());
  1327. bind_method(Vector3, length, sarray(), varray());
  1328. bind_method(Vector3, length_squared, sarray(), varray());
  1329. bind_method(Vector3, limit_length, sarray("length"), varray(1.0));
  1330. bind_method(Vector3, normalized, sarray(), varray());
  1331. bind_method(Vector3, is_normalized, sarray(), varray());
  1332. bind_method(Vector3, is_equal_approx, sarray("to"), varray());
  1333. bind_method(Vector3, inverse, sarray(), varray());
  1334. bind_method(Vector3, clamp, sarray("min", "max"), varray());
  1335. bind_method(Vector3, snapped, sarray("step"), varray());
  1336. bind_method(Vector3, rotated, sarray("by_axis", "phi"), varray());
  1337. bind_method(Vector3, lerp, sarray("to", "weight"), varray());
  1338. bind_method(Vector3, slerp, sarray("to", "weight"), varray());
  1339. bind_method(Vector3, cubic_interpolate, sarray("b", "pre_a", "post_b", "weight"), varray());
  1340. bind_method(Vector3, move_toward, sarray("to", "delta"), varray());
  1341. bind_method(Vector3, dot, sarray("with"), varray());
  1342. bind_method(Vector3, cross, sarray("with"), varray());
  1343. bind_method(Vector3, outer, sarray("with"), varray());
  1344. bind_method(Vector3, to_diagonal_matrix, sarray(), varray());
  1345. bind_method(Vector3, abs, sarray(), varray());
  1346. bind_method(Vector3, floor, sarray(), varray());
  1347. bind_method(Vector3, ceil, sarray(), varray());
  1348. bind_method(Vector3, round, sarray(), varray());
  1349. bind_method(Vector3, posmod, sarray("mod"), varray());
  1350. bind_method(Vector3, posmodv, sarray("modv"), varray());
  1351. bind_method(Vector3, project, sarray("b"), varray());
  1352. bind_method(Vector3, slide, sarray("n"), varray());
  1353. bind_method(Vector3, bounce, sarray("n"), varray());
  1354. bind_method(Vector3, reflect, sarray("n"), varray());
  1355. bind_method(Vector3, sign, sarray(), varray());
  1356. /* Vector3i */
  1357. bind_method(Vector3i, min_axis, sarray(), varray());
  1358. bind_method(Vector3i, max_axis, sarray(), varray());
  1359. bind_method(Vector3i, sign, sarray(), varray());
  1360. bind_method(Vector3i, abs, sarray(), varray());
  1361. bind_method(Vector3i, clamp, sarray("min", "max"), varray());
  1362. /* Plane */
  1363. bind_method(Plane, normalized, sarray(), varray());
  1364. bind_method(Plane, center, sarray(), varray());
  1365. bind_method(Plane, is_equal_approx, sarray("to_plane"), varray());
  1366. bind_method(Plane, is_point_over, sarray("plane"), varray());
  1367. bind_method(Plane, distance_to, sarray("point"), varray());
  1368. bind_method(Plane, has_point, sarray("point", "epsilon"), varray(CMP_EPSILON));
  1369. bind_method(Plane, project, sarray("point"), varray());
  1370. bind_methodv(Plane, intersect_3, &Plane::intersect_3_bind, sarray("b", "c"), varray());
  1371. bind_methodv(Plane, intersects_ray, &Plane::intersects_ray_bind, sarray("from", "dir"), varray());
  1372. bind_methodv(Plane, intersects_segment, &Plane::intersects_segment_bind, sarray("from", "to"), varray());
  1373. /* Quaternion */
  1374. bind_method(Quaternion, length, sarray(), varray());
  1375. bind_method(Quaternion, length_squared, sarray(), varray());
  1376. bind_method(Quaternion, normalized, sarray(), varray());
  1377. bind_method(Quaternion, is_normalized, sarray(), varray());
  1378. bind_method(Quaternion, is_equal_approx, sarray("to"), varray());
  1379. bind_method(Quaternion, inverse, sarray(), varray());
  1380. bind_method(Quaternion, angle_to, sarray("to"), varray());
  1381. bind_method(Quaternion, dot, sarray("with"), varray());
  1382. bind_method(Quaternion, slerp, sarray("to", "weight"), varray());
  1383. bind_method(Quaternion, slerpni, sarray("to", "weight"), varray());
  1384. bind_method(Quaternion, cubic_slerp, sarray("b", "pre_a", "post_b", "weight"), varray());
  1385. bind_method(Quaternion, get_euler, sarray(), varray());
  1386. /* Color */
  1387. bind_method(Color, to_argb32, sarray(), varray());
  1388. bind_method(Color, to_abgr32, sarray(), varray());
  1389. bind_method(Color, to_rgba32, sarray(), varray());
  1390. bind_method(Color, to_argb64, sarray(), varray());
  1391. bind_method(Color, to_abgr64, sarray(), varray());
  1392. bind_method(Color, to_rgba64, sarray(), varray());
  1393. bind_method(Color, clamp, sarray("min", "max"), varray(Color(0, 0, 0, 0), Color(1, 1, 1, 1)));
  1394. bind_method(Color, inverted, sarray(), varray());
  1395. bind_method(Color, lerp, sarray("to", "weight"), varray());
  1396. bind_method(Color, lightened, sarray("amount"), varray());
  1397. bind_method(Color, darkened, sarray("amount"), varray());
  1398. bind_method(Color, to_html, sarray("with_alpha"), varray(true));
  1399. bind_method(Color, blend, sarray("over"), varray());
  1400. // FIXME: Color is immutable, need to probably find a way to do this via constructor
  1401. //ADDFUNC4R(COLOR, COLOR, Color, from_hsv, FLOAT, "h", FLOAT, "s", FLOAT, "v", FLOAT, "a", varray(1.0));
  1402. bind_method(Color, is_equal_approx, sarray("to"), varray());
  1403. bind_static_method(Color, hex, sarray("hex"), varray());
  1404. bind_static_method(Color, hex64, sarray("hex"), varray());
  1405. bind_static_method(Color, html, sarray("rgba"), varray());
  1406. bind_static_method(Color, html_is_valid, sarray("color"), varray());
  1407. bind_static_method(Color, find_named_color, sarray("name"), varray());
  1408. bind_static_method(Color, get_named_color_count, sarray(), varray());
  1409. bind_static_method(Color, get_named_color_name, sarray("idx"), varray());
  1410. bind_static_method(Color, get_named_color, sarray("idx"), varray());
  1411. bind_static_method(Color, from_string, sarray("str", "default"), varray());
  1412. bind_static_method(Color, from_rgbe9995, sarray("rgbe"), varray());
  1413. /* RID */
  1414. bind_method(RID, get_id, sarray(), varray());
  1415. /* NodePath */
  1416. bind_method(NodePath, is_absolute, sarray(), varray());
  1417. bind_method(NodePath, get_name_count, sarray(), varray());
  1418. bind_method(NodePath, get_name, sarray("idx"), varray());
  1419. bind_method(NodePath, get_subname_count, sarray(), varray());
  1420. bind_method(NodePath, get_subname, sarray("idx"), varray());
  1421. bind_method(NodePath, get_concatenated_subnames, sarray(), varray());
  1422. bind_method(NodePath, get_as_property_path, sarray(), varray());
  1423. bind_method(NodePath, is_empty, sarray(), varray());
  1424. /* Callable */
  1425. bind_method(Callable, is_null, sarray(), varray());
  1426. bind_method(Callable, is_custom, sarray(), varray());
  1427. bind_method(Callable, is_standard, sarray(), varray());
  1428. bind_method(Callable, is_valid, sarray(), varray());
  1429. bind_method(Callable, get_object, sarray(), varray());
  1430. bind_method(Callable, get_object_id, sarray(), varray());
  1431. bind_method(Callable, get_method, sarray(), varray());
  1432. bind_method(Callable, hash, sarray(), varray());
  1433. bind_method(Callable, unbind, sarray("argcount"), varray());
  1434. bind_custom(Callable, call, _VariantCall::func_Callable_call, true, Variant);
  1435. bind_custom(Callable, call_deferred, _VariantCall::func_Callable_call_deferred, false, Variant);
  1436. bind_custom(Callable, rpc, _VariantCall::func_Callable_rpc, false, Variant);
  1437. bind_custom1(Callable, rpc_id, _VariantCall::func_Callable_rpc_id, Variant::INT, "peer_id");
  1438. bind_custom(Callable, bind, _VariantCall::func_Callable_bind, true, Callable);
  1439. /* Signal */
  1440. bind_method(Signal, is_null, sarray(), varray());
  1441. bind_method(Signal, get_object, sarray(), varray());
  1442. bind_method(Signal, get_object_id, sarray(), varray());
  1443. bind_method(Signal, get_name, sarray(), varray());
  1444. bind_method(Signal, connect, sarray("callable", "binds", "flags"), varray(Array(), 0));
  1445. bind_method(Signal, disconnect, sarray("callable"), varray());
  1446. bind_method(Signal, is_connected, sarray("callable"), varray());
  1447. bind_method(Signal, get_connections, sarray(), varray());
  1448. bind_custom(Signal, emit, _VariantCall::func_Signal_emit, false, Variant);
  1449. /* Transform2D */
  1450. bind_method(Transform2D, inverse, sarray(), varray());
  1451. bind_method(Transform2D, affine_inverse, sarray(), varray());
  1452. bind_method(Transform2D, get_rotation, sarray(), varray());
  1453. bind_method(Transform2D, get_origin, sarray(), varray());
  1454. bind_method(Transform2D, get_scale, sarray(), varray());
  1455. bind_method(Transform2D, orthonormalized, sarray(), varray());
  1456. bind_method(Transform2D, rotated, sarray("phi"), varray());
  1457. bind_method(Transform2D, scaled, sarray("scale"), varray());
  1458. bind_method(Transform2D, translated, sarray("offset"), varray());
  1459. bind_method(Transform2D, basis_xform, sarray("v"), varray());
  1460. bind_method(Transform2D, basis_xform_inv, sarray("v"), varray());
  1461. bind_method(Transform2D, interpolate_with, sarray("xform", "weight"), varray());
  1462. bind_method(Transform2D, is_equal_approx, sarray("xform"), varray());
  1463. bind_method(Transform2D, set_rotation, sarray("rotation"), varray());
  1464. bind_method(Transform2D, looking_at, sarray("target"), varray(Transform2D()));
  1465. /* Basis */
  1466. bind_method(Basis, inverse, sarray(), varray());
  1467. bind_method(Basis, transposed, sarray(), varray());
  1468. bind_method(Basis, orthonormalized, sarray(), varray());
  1469. bind_method(Basis, determinant, sarray(), varray());
  1470. bind_methodv(Basis, rotated, static_cast<Basis (Basis::*)(const Vector3 &, real_t) const>(&Basis::rotated), sarray("axis", "phi"), varray());
  1471. bind_method(Basis, scaled, sarray("scale"), varray());
  1472. bind_method(Basis, get_scale, sarray(), varray());
  1473. bind_method(Basis, get_euler, sarray(), varray());
  1474. bind_method(Basis, tdotx, sarray("with"), varray());
  1475. bind_method(Basis, tdoty, sarray("with"), varray());
  1476. bind_method(Basis, tdotz, sarray("with"), varray());
  1477. bind_method(Basis, get_orthogonal_index, sarray(), varray());
  1478. bind_method(Basis, slerp, sarray("to", "weight"), varray());
  1479. bind_method(Basis, is_equal_approx, sarray("b"), varray());
  1480. bind_method(Basis, get_rotation_quaternion, sarray(), varray());
  1481. /* AABB */
  1482. bind_method(AABB, abs, sarray(), varray());
  1483. bind_method(AABB, get_area, sarray(), varray());
  1484. bind_method(AABB, has_no_area, sarray(), varray());
  1485. bind_method(AABB, has_no_surface, sarray(), varray());
  1486. bind_method(AABB, has_point, sarray("point"), varray());
  1487. bind_method(AABB, is_equal_approx, sarray("aabb"), varray());
  1488. bind_method(AABB, intersects, sarray("with"), varray());
  1489. bind_method(AABB, encloses, sarray("with"), varray());
  1490. bind_method(AABB, intersects_plane, sarray("plane"), varray());
  1491. bind_method(AABB, intersection, sarray("with"), varray());
  1492. bind_method(AABB, merge, sarray("with"), varray());
  1493. bind_method(AABB, expand, sarray("to_point"), varray());
  1494. bind_method(AABB, grow, sarray("by"), varray());
  1495. bind_method(AABB, get_support, sarray("dir"), varray());
  1496. bind_method(AABB, get_longest_axis, sarray(), varray());
  1497. bind_method(AABB, get_longest_axis_index, sarray(), varray());
  1498. bind_method(AABB, get_longest_axis_size, sarray(), varray());
  1499. bind_method(AABB, get_shortest_axis, sarray(), varray());
  1500. bind_method(AABB, get_shortest_axis_index, sarray(), varray());
  1501. bind_method(AABB, get_shortest_axis_size, sarray(), varray());
  1502. bind_method(AABB, get_endpoint, sarray("idx"), varray());
  1503. bind_methodv(AABB, intersects_segment, &AABB::intersects_segment_bind, sarray("from", "to"), varray());
  1504. bind_methodv(AABB, intersects_ray, &AABB::intersects_ray_bind, sarray("from", "dir"), varray());
  1505. /* Transform3D */
  1506. bind_method(Transform3D, inverse, sarray(), varray());
  1507. bind_method(Transform3D, affine_inverse, sarray(), varray());
  1508. bind_method(Transform3D, orthonormalized, sarray(), varray());
  1509. bind_method(Transform3D, rotated, sarray("axis", "phi"), varray());
  1510. bind_method(Transform3D, scaled, sarray("scale"), varray());
  1511. bind_method(Transform3D, translated, sarray("offset"), varray());
  1512. bind_method(Transform3D, looking_at, sarray("target", "up"), varray(Vector3(0, 1, 0)));
  1513. bind_method(Transform3D, interpolate_with, sarray("xform", "weight"), varray());
  1514. bind_method(Transform3D, is_equal_approx, sarray("xform"), varray());
  1515. /* Dictionary */
  1516. bind_method(Dictionary, size, sarray(), varray());
  1517. bind_method(Dictionary, is_empty, sarray(), varray());
  1518. bind_method(Dictionary, clear, sarray(), varray());
  1519. bind_method(Dictionary, has, sarray("key"), varray());
  1520. bind_method(Dictionary, has_all, sarray("keys"), varray());
  1521. bind_method(Dictionary, erase, sarray("key"), varray());
  1522. bind_method(Dictionary, hash, sarray(), varray());
  1523. bind_method(Dictionary, keys, sarray(), varray());
  1524. bind_method(Dictionary, values, sarray(), varray());
  1525. bind_method(Dictionary, duplicate, sarray("deep"), varray(false));
  1526. bind_method(Dictionary, get, sarray("key", "default"), varray(Variant()));
  1527. /* Array */
  1528. bind_method(Array, size, sarray(), varray());
  1529. bind_method(Array, is_empty, sarray(), varray());
  1530. bind_method(Array, clear, sarray(), varray());
  1531. bind_method(Array, hash, sarray(), varray());
  1532. bind_method(Array, push_back, sarray("value"), varray());
  1533. bind_method(Array, push_front, sarray("value"), varray());
  1534. bind_method(Array, append, sarray("value"), varray());
  1535. bind_method(Array, append_array, sarray("array"), varray());
  1536. bind_method(Array, resize, sarray("size"), varray());
  1537. bind_method(Array, insert, sarray("position", "value"), varray());
  1538. bind_method(Array, remove, sarray("position"), varray());
  1539. bind_method(Array, fill, sarray("value"), varray());
  1540. bind_method(Array, erase, sarray("value"), varray());
  1541. bind_method(Array, front, sarray(), varray());
  1542. bind_method(Array, back, sarray(), varray());
  1543. bind_method(Array, find, sarray("what", "from"), varray(0));
  1544. bind_method(Array, rfind, sarray("what", "from"), varray(-1));
  1545. bind_method(Array, find_last, sarray("value"), varray());
  1546. bind_method(Array, count, sarray("value"), varray());
  1547. bind_method(Array, has, sarray("value"), varray());
  1548. bind_method(Array, pop_back, sarray(), varray());
  1549. bind_method(Array, pop_front, sarray(), varray());
  1550. bind_method(Array, sort, sarray(), varray());
  1551. bind_method(Array, sort_custom, sarray("func"), varray());
  1552. bind_method(Array, shuffle, sarray(), varray());
  1553. bind_method(Array, bsearch, sarray("value", "before"), varray(true));
  1554. bind_method(Array, bsearch_custom, sarray("value", "func", "before"), varray(true));
  1555. bind_method(Array, reverse, sarray(), varray());
  1556. bind_method(Array, duplicate, sarray("deep"), varray(false));
  1557. bind_method(Array, slice, sarray("begin", "end", "step", "deep"), varray(1, false));
  1558. bind_method(Array, filter, sarray("method"), varray());
  1559. bind_method(Array, map, sarray("method"), varray());
  1560. bind_method(Array, reduce, sarray("method", "accum"), varray(Variant()));
  1561. bind_method(Array, max, sarray(), varray());
  1562. bind_method(Array, min, sarray(), varray());
  1563. /* Byte Array */
  1564. bind_method(PackedByteArray, size, sarray(), varray());
  1565. bind_method(PackedByteArray, is_empty, sarray(), varray());
  1566. bind_method(PackedByteArray, set, sarray("index", "value"), varray());
  1567. bind_method(PackedByteArray, push_back, sarray("value"), varray());
  1568. bind_method(PackedByteArray, append, sarray("value"), varray());
  1569. bind_method(PackedByteArray, append_array, sarray("array"), varray());
  1570. bind_method(PackedByteArray, remove, sarray("index"), varray());
  1571. bind_method(PackedByteArray, insert, sarray("at_index", "value"), varray());
  1572. bind_method(PackedByteArray, fill, sarray("value"), varray());
  1573. bind_method(PackedByteArray, resize, sarray("new_size"), varray());
  1574. bind_method(PackedByteArray, has, sarray("value"), varray());
  1575. bind_method(PackedByteArray, reverse, sarray(), varray());
  1576. bind_method(PackedByteArray, subarray, sarray("from", "to"), varray());
  1577. bind_method(PackedByteArray, sort, sarray(), varray());
  1578. bind_method(PackedByteArray, duplicate, sarray(), varray());
  1579. bind_function(PackedByteArray, get_string_from_ascii, _VariantCall::func_PackedByteArray_get_string_from_ascii, sarray(), varray());
  1580. bind_function(PackedByteArray, get_string_from_utf8, _VariantCall::func_PackedByteArray_get_string_from_utf8, sarray(), varray());
  1581. bind_function(PackedByteArray, get_string_from_utf16, _VariantCall::func_PackedByteArray_get_string_from_utf16, sarray(), varray());
  1582. bind_function(PackedByteArray, get_string_from_utf32, _VariantCall::func_PackedByteArray_get_string_from_utf32, sarray(), varray());
  1583. bind_function(PackedByteArray, hex_encode, _VariantCall::func_PackedByteArray_hex_encode, sarray(), varray());
  1584. bind_function(PackedByteArray, compress, _VariantCall::func_PackedByteArray_compress, sarray("compression_mode"), varray(0));
  1585. bind_function(PackedByteArray, decompress, _VariantCall::func_PackedByteArray_decompress, sarray("buffer_size", "compression_mode"), varray(0));
  1586. bind_function(PackedByteArray, decompress_dynamic, _VariantCall::func_PackedByteArray_decompress_dynamic, sarray("max_output_size", "compression_mode"), varray(0));
  1587. bind_function(PackedByteArray, decode_u8, _VariantCall::func_PackedByteArray_decode_u8, sarray("byte_offset"), varray());
  1588. bind_function(PackedByteArray, decode_s8, _VariantCall::func_PackedByteArray_decode_s8, sarray("byte_offset"), varray());
  1589. bind_function(PackedByteArray, decode_u16, _VariantCall::func_PackedByteArray_decode_u16, sarray("byte_offset"), varray());
  1590. bind_function(PackedByteArray, decode_s16, _VariantCall::func_PackedByteArray_decode_s16, sarray("byte_offset"), varray());
  1591. bind_function(PackedByteArray, decode_u32, _VariantCall::func_PackedByteArray_decode_u32, sarray("byte_offset"), varray());
  1592. bind_function(PackedByteArray, decode_s32, _VariantCall::func_PackedByteArray_decode_s32, sarray("byte_offset"), varray());
  1593. bind_function(PackedByteArray, decode_u64, _VariantCall::func_PackedByteArray_decode_u64, sarray("byte_offset"), varray());
  1594. bind_function(PackedByteArray, decode_s64, _VariantCall::func_PackedByteArray_decode_s64, sarray("byte_offset"), varray());
  1595. bind_function(PackedByteArray, decode_half, _VariantCall::func_PackedByteArray_decode_half, sarray("byte_offset"), varray());
  1596. bind_function(PackedByteArray, decode_float, _VariantCall::func_PackedByteArray_decode_float, sarray("byte_offset"), varray());
  1597. bind_function(PackedByteArray, decode_double, _VariantCall::func_PackedByteArray_decode_double, sarray("byte_offset"), varray());
  1598. bind_function(PackedByteArray, has_encoded_var, _VariantCall::func_PackedByteArray_has_encoded_var, sarray("byte_offset", "allow_objects"), varray(false));
  1599. bind_function(PackedByteArray, decode_var, _VariantCall::func_PackedByteArray_decode_var, sarray("byte_offset", "allow_objects"), varray(false));
  1600. bind_function(PackedByteArray, decode_var_size, _VariantCall::func_PackedByteArray_decode_var_size, sarray("byte_offset", "allow_objects"), varray(false));
  1601. bind_functionnc(PackedByteArray, encode_u8, _VariantCall::func_PackedByteArray_encode_u8, sarray("byte_offset", "value"), varray());
  1602. bind_functionnc(PackedByteArray, encode_s8, _VariantCall::func_PackedByteArray_encode_s8, sarray("byte_offset", "value"), varray());
  1603. bind_functionnc(PackedByteArray, encode_u16, _VariantCall::func_PackedByteArray_encode_u16, sarray("byte_offset", "value"), varray());
  1604. bind_functionnc(PackedByteArray, encode_s16, _VariantCall::func_PackedByteArray_encode_s16, sarray("byte_offset", "value"), varray());
  1605. bind_functionnc(PackedByteArray, encode_u32, _VariantCall::func_PackedByteArray_encode_u32, sarray("byte_offset", "value"), varray());
  1606. bind_functionnc(PackedByteArray, encode_s32, _VariantCall::func_PackedByteArray_encode_s32, sarray("byte_offset", "value"), varray());
  1607. bind_functionnc(PackedByteArray, encode_u64, _VariantCall::func_PackedByteArray_encode_u64, sarray("byte_offset", "value"), varray());
  1608. bind_functionnc(PackedByteArray, encode_s64, _VariantCall::func_PackedByteArray_encode_s64, sarray("byte_offset", "value"), varray());
  1609. bind_functionnc(PackedByteArray, encode_half, _VariantCall::func_PackedByteArray_encode_half, sarray("byte_offset", "value"), varray());
  1610. bind_functionnc(PackedByteArray, encode_float, _VariantCall::func_PackedByteArray_encode_float, sarray("byte_offset", "value"), varray());
  1611. bind_functionnc(PackedByteArray, encode_double, _VariantCall::func_PackedByteArray_encode_double, sarray("byte_offset", "value"), varray());
  1612. bind_functionnc(PackedByteArray, encode_var, _VariantCall::func_PackedByteArray_encode_var, sarray("byte_offset", "value", "allow_objects"), varray(false));
  1613. /* Int32 Array */
  1614. bind_method(PackedInt32Array, size, sarray(), varray());
  1615. bind_method(PackedInt32Array, is_empty, sarray(), varray());
  1616. bind_method(PackedInt32Array, set, sarray("index", "value"), varray());
  1617. bind_method(PackedInt32Array, push_back, sarray("value"), varray());
  1618. bind_method(PackedInt32Array, append, sarray("value"), varray());
  1619. bind_method(PackedInt32Array, append_array, sarray("array"), varray());
  1620. bind_method(PackedInt32Array, remove, sarray("index"), varray());
  1621. bind_method(PackedInt32Array, insert, sarray("at_index", "value"), varray());
  1622. bind_method(PackedInt32Array, fill, sarray("value"), varray());
  1623. bind_method(PackedInt32Array, resize, sarray("new_size"), varray());
  1624. bind_method(PackedInt32Array, has, sarray("value"), varray());
  1625. bind_method(PackedInt32Array, reverse, sarray(), varray());
  1626. bind_method(PackedInt32Array, subarray, sarray("from", "to"), varray());
  1627. bind_method(PackedInt32Array, to_byte_array, sarray(), varray());
  1628. bind_method(PackedInt32Array, sort, sarray(), varray());
  1629. bind_method(PackedInt32Array, duplicate, sarray(), varray());
  1630. /* Int64 Array */
  1631. bind_method(PackedInt64Array, size, sarray(), varray());
  1632. bind_method(PackedInt64Array, is_empty, sarray(), varray());
  1633. bind_method(PackedInt64Array, set, sarray("index", "value"), varray());
  1634. bind_method(PackedInt64Array, push_back, sarray("value"), varray());
  1635. bind_method(PackedInt64Array, append, sarray("value"), varray());
  1636. bind_method(PackedInt64Array, append_array, sarray("array"), varray());
  1637. bind_method(PackedInt64Array, remove, sarray("index"), varray());
  1638. bind_method(PackedInt64Array, insert, sarray("at_index", "value"), varray());
  1639. bind_method(PackedInt64Array, fill, sarray("value"), varray());
  1640. bind_method(PackedInt64Array, resize, sarray("new_size"), varray());
  1641. bind_method(PackedInt64Array, has, sarray("value"), varray());
  1642. bind_method(PackedInt64Array, reverse, sarray(), varray());
  1643. bind_method(PackedInt64Array, subarray, sarray("from", "to"), varray());
  1644. bind_method(PackedInt64Array, to_byte_array, sarray(), varray());
  1645. bind_method(PackedInt64Array, sort, sarray(), varray());
  1646. bind_method(PackedInt64Array, duplicate, sarray(), varray());
  1647. /* Float32 Array */
  1648. bind_method(PackedFloat32Array, size, sarray(), varray());
  1649. bind_method(PackedFloat32Array, is_empty, sarray(), varray());
  1650. bind_method(PackedFloat32Array, set, sarray("index", "value"), varray());
  1651. bind_method(PackedFloat32Array, push_back, sarray("value"), varray());
  1652. bind_method(PackedFloat32Array, append, sarray("value"), varray());
  1653. bind_method(PackedFloat32Array, append_array, sarray("array"), varray());
  1654. bind_method(PackedFloat32Array, remove, sarray("index"), varray());
  1655. bind_method(PackedFloat32Array, insert, sarray("at_index", "value"), varray());
  1656. bind_method(PackedFloat32Array, fill, sarray("value"), varray());
  1657. bind_method(PackedFloat32Array, resize, sarray("new_size"), varray());
  1658. bind_method(PackedFloat32Array, has, sarray("value"), varray());
  1659. bind_method(PackedFloat32Array, reverse, sarray(), varray());
  1660. bind_method(PackedFloat32Array, subarray, sarray("from", "to"), varray());
  1661. bind_method(PackedFloat32Array, to_byte_array, sarray(), varray());
  1662. bind_method(PackedFloat32Array, sort, sarray(), varray());
  1663. bind_method(PackedFloat32Array, duplicate, sarray(), varray());
  1664. /* Float64 Array */
  1665. bind_method(PackedFloat64Array, size, sarray(), varray());
  1666. bind_method(PackedFloat64Array, is_empty, sarray(), varray());
  1667. bind_method(PackedFloat64Array, set, sarray("index", "value"), varray());
  1668. bind_method(PackedFloat64Array, push_back, sarray("value"), varray());
  1669. bind_method(PackedFloat64Array, append, sarray("value"), varray());
  1670. bind_method(PackedFloat64Array, append_array, sarray("array"), varray());
  1671. bind_method(PackedFloat64Array, remove, sarray("index"), varray());
  1672. bind_method(PackedFloat64Array, insert, sarray("at_index", "value"), varray());
  1673. bind_method(PackedFloat64Array, fill, sarray("value"), varray());
  1674. bind_method(PackedFloat64Array, resize, sarray("new_size"), varray());
  1675. bind_method(PackedFloat64Array, has, sarray("value"), varray());
  1676. bind_method(PackedFloat64Array, reverse, sarray(), varray());
  1677. bind_method(PackedFloat64Array, subarray, sarray("from", "to"), varray());
  1678. bind_method(PackedFloat64Array, to_byte_array, sarray(), varray());
  1679. bind_method(PackedFloat64Array, sort, sarray(), varray());
  1680. bind_method(PackedFloat64Array, duplicate, sarray(), varray());
  1681. /* String Array */
  1682. bind_method(PackedStringArray, size, sarray(), varray());
  1683. bind_method(PackedStringArray, is_empty, sarray(), varray());
  1684. bind_method(PackedStringArray, set, sarray("index", "value"), varray());
  1685. bind_method(PackedStringArray, push_back, sarray("value"), varray());
  1686. bind_method(PackedStringArray, append, sarray("value"), varray());
  1687. bind_method(PackedStringArray, append_array, sarray("array"), varray());
  1688. bind_method(PackedStringArray, remove, sarray("index"), varray());
  1689. bind_method(PackedStringArray, insert, sarray("at_index", "value"), varray());
  1690. bind_method(PackedStringArray, fill, sarray("value"), varray());
  1691. bind_method(PackedStringArray, resize, sarray("new_size"), varray());
  1692. bind_method(PackedStringArray, has, sarray("value"), varray());
  1693. bind_method(PackedStringArray, reverse, sarray(), varray());
  1694. bind_method(PackedStringArray, subarray, sarray("from", "to"), varray());
  1695. bind_method(PackedStringArray, to_byte_array, sarray(), varray());
  1696. bind_method(PackedStringArray, sort, sarray(), varray());
  1697. bind_method(PackedStringArray, duplicate, sarray(), varray());
  1698. /* Vector2 Array */
  1699. bind_method(PackedVector2Array, size, sarray(), varray());
  1700. bind_method(PackedVector2Array, is_empty, sarray(), varray());
  1701. bind_method(PackedVector2Array, set, sarray("index", "value"), varray());
  1702. bind_method(PackedVector2Array, push_back, sarray("value"), varray());
  1703. bind_method(PackedVector2Array, append, sarray("value"), varray());
  1704. bind_method(PackedVector2Array, append_array, sarray("array"), varray());
  1705. bind_method(PackedVector2Array, remove, sarray("index"), varray());
  1706. bind_method(PackedVector2Array, insert, sarray("at_index", "value"), varray());
  1707. bind_method(PackedVector2Array, fill, sarray("value"), varray());
  1708. bind_method(PackedVector2Array, resize, sarray("new_size"), varray());
  1709. bind_method(PackedVector2Array, has, sarray("value"), varray());
  1710. bind_method(PackedVector2Array, reverse, sarray(), varray());
  1711. bind_method(PackedVector2Array, subarray, sarray("from", "to"), varray());
  1712. bind_method(PackedVector2Array, to_byte_array, sarray(), varray());
  1713. bind_method(PackedVector2Array, sort, sarray(), varray());
  1714. bind_method(PackedVector2Array, duplicate, sarray(), varray());
  1715. /* Vector3 Array */
  1716. bind_method(PackedVector3Array, size, sarray(), varray());
  1717. bind_method(PackedVector3Array, is_empty, sarray(), varray());
  1718. bind_method(PackedVector3Array, set, sarray("index", "value"), varray());
  1719. bind_method(PackedVector3Array, push_back, sarray("value"), varray());
  1720. bind_method(PackedVector3Array, append, sarray("value"), varray());
  1721. bind_method(PackedVector3Array, append_array, sarray("array"), varray());
  1722. bind_method(PackedVector3Array, remove, sarray("index"), varray());
  1723. bind_method(PackedVector3Array, insert, sarray("at_index", "value"), varray());
  1724. bind_method(PackedVector3Array, fill, sarray("value"), varray());
  1725. bind_method(PackedVector3Array, resize, sarray("new_size"), varray());
  1726. bind_method(PackedVector3Array, has, sarray("value"), varray());
  1727. bind_method(PackedVector3Array, reverse, sarray(), varray());
  1728. bind_method(PackedVector3Array, subarray, sarray("from", "to"), varray());
  1729. bind_method(PackedVector3Array, to_byte_array, sarray(), varray());
  1730. bind_method(PackedVector3Array, sort, sarray(), varray());
  1731. bind_method(PackedVector3Array, duplicate, sarray(), varray());
  1732. /* Color Array */
  1733. bind_method(PackedColorArray, size, sarray(), varray());
  1734. bind_method(PackedColorArray, is_empty, sarray(), varray());
  1735. bind_method(PackedColorArray, set, sarray("index", "value"), varray());
  1736. bind_method(PackedColorArray, push_back, sarray("value"), varray());
  1737. bind_method(PackedColorArray, append, sarray("value"), varray());
  1738. bind_method(PackedColorArray, append_array, sarray("array"), varray());
  1739. bind_method(PackedColorArray, remove, sarray("index"), varray());
  1740. bind_method(PackedColorArray, insert, sarray("at_index", "value"), varray());
  1741. bind_method(PackedColorArray, fill, sarray("value"), varray());
  1742. bind_method(PackedColorArray, resize, sarray("new_size"), varray());
  1743. bind_method(PackedColorArray, has, sarray("value"), varray());
  1744. bind_method(PackedColorArray, reverse, sarray(), varray());
  1745. bind_method(PackedColorArray, subarray, sarray("from", "to"), varray());
  1746. bind_method(PackedColorArray, to_byte_array, sarray(), varray());
  1747. bind_method(PackedColorArray, sort, sarray(), varray());
  1748. bind_method(PackedColorArray, duplicate, sarray(), varray());
  1749. /* Register constants */
  1750. int ncc = Color::get_named_color_count();
  1751. for (int i = 0; i < ncc; i++) {
  1752. _VariantCall::add_variant_constant(Variant::COLOR, Color::get_named_color_name(i), Color::get_named_color(i));
  1753. }
  1754. _VariantCall::add_constant(Variant::VECTOR3, "AXIS_X", Vector3::AXIS_X);
  1755. _VariantCall::add_constant(Variant::VECTOR3, "AXIS_Y", Vector3::AXIS_Y);
  1756. _VariantCall::add_constant(Variant::VECTOR3, "AXIS_Z", Vector3::AXIS_Z);
  1757. _VariantCall::add_variant_constant(Variant::VECTOR3, "ZERO", Vector3(0, 0, 0));
  1758. _VariantCall::add_variant_constant(Variant::VECTOR3, "ONE", Vector3(1, 1, 1));
  1759. _VariantCall::add_variant_constant(Variant::VECTOR3, "INF", Vector3(INFINITY, INFINITY, INFINITY));
  1760. _VariantCall::add_variant_constant(Variant::VECTOR3, "LEFT", Vector3(-1, 0, 0));
  1761. _VariantCall::add_variant_constant(Variant::VECTOR3, "RIGHT", Vector3(1, 0, 0));
  1762. _VariantCall::add_variant_constant(Variant::VECTOR3, "UP", Vector3(0, 1, 0));
  1763. _VariantCall::add_variant_constant(Variant::VECTOR3, "DOWN", Vector3(0, -1, 0));
  1764. _VariantCall::add_variant_constant(Variant::VECTOR3, "FORWARD", Vector3(0, 0, -1));
  1765. _VariantCall::add_variant_constant(Variant::VECTOR3, "BACK", Vector3(0, 0, 1));
  1766. _VariantCall::add_constant(Variant::VECTOR3I, "AXIS_X", Vector3i::AXIS_X);
  1767. _VariantCall::add_constant(Variant::VECTOR3I, "AXIS_Y", Vector3i::AXIS_Y);
  1768. _VariantCall::add_constant(Variant::VECTOR3I, "AXIS_Z", Vector3i::AXIS_Z);
  1769. _VariantCall::add_variant_constant(Variant::VECTOR3I, "ZERO", Vector3i(0, 0, 0));
  1770. _VariantCall::add_variant_constant(Variant::VECTOR3I, "ONE", Vector3i(1, 1, 1));
  1771. _VariantCall::add_variant_constant(Variant::VECTOR3I, "LEFT", Vector3i(-1, 0, 0));
  1772. _VariantCall::add_variant_constant(Variant::VECTOR3I, "RIGHT", Vector3i(1, 0, 0));
  1773. _VariantCall::add_variant_constant(Variant::VECTOR3I, "UP", Vector3i(0, 1, 0));
  1774. _VariantCall::add_variant_constant(Variant::VECTOR3I, "DOWN", Vector3i(0, -1, 0));
  1775. _VariantCall::add_variant_constant(Variant::VECTOR3I, "FORWARD", Vector3i(0, 0, -1));
  1776. _VariantCall::add_variant_constant(Variant::VECTOR3I, "BACK", Vector3i(0, 0, 1));
  1777. _VariantCall::add_constant(Variant::VECTOR2, "AXIS_X", Vector2::AXIS_X);
  1778. _VariantCall::add_constant(Variant::VECTOR2, "AXIS_Y", Vector2::AXIS_Y);
  1779. _VariantCall::add_constant(Variant::VECTOR2I, "AXIS_X", Vector2i::AXIS_X);
  1780. _VariantCall::add_constant(Variant::VECTOR2I, "AXIS_Y", Vector2i::AXIS_Y);
  1781. _VariantCall::add_variant_constant(Variant::VECTOR2, "ZERO", Vector2(0, 0));
  1782. _VariantCall::add_variant_constant(Variant::VECTOR2, "ONE", Vector2(1, 1));
  1783. _VariantCall::add_variant_constant(Variant::VECTOR2, "INF", Vector2(INFINITY, INFINITY));
  1784. _VariantCall::add_variant_constant(Variant::VECTOR2, "LEFT", Vector2(-1, 0));
  1785. _VariantCall::add_variant_constant(Variant::VECTOR2, "RIGHT", Vector2(1, 0));
  1786. _VariantCall::add_variant_constant(Variant::VECTOR2, "UP", Vector2(0, -1));
  1787. _VariantCall::add_variant_constant(Variant::VECTOR2, "DOWN", Vector2(0, 1));
  1788. _VariantCall::add_variant_constant(Variant::VECTOR2I, "ZERO", Vector2i(0, 0));
  1789. _VariantCall::add_variant_constant(Variant::VECTOR2I, "ONE", Vector2i(1, 1));
  1790. _VariantCall::add_variant_constant(Variant::VECTOR2I, "LEFT", Vector2i(-1, 0));
  1791. _VariantCall::add_variant_constant(Variant::VECTOR2I, "RIGHT", Vector2i(1, 0));
  1792. _VariantCall::add_variant_constant(Variant::VECTOR2I, "UP", Vector2i(0, -1));
  1793. _VariantCall::add_variant_constant(Variant::VECTOR2I, "DOWN", Vector2i(0, 1));
  1794. _VariantCall::add_variant_constant(Variant::TRANSFORM2D, "IDENTITY", Transform2D());
  1795. _VariantCall::add_variant_constant(Variant::TRANSFORM2D, "FLIP_X", Transform2D(-1, 0, 0, 1, 0, 0));
  1796. _VariantCall::add_variant_constant(Variant::TRANSFORM2D, "FLIP_Y", Transform2D(1, 0, 0, -1, 0, 0));
  1797. Transform3D identity_transform = Transform3D();
  1798. Transform3D flip_x_transform = Transform3D(-1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0);
  1799. Transform3D flip_y_transform = Transform3D(1, 0, 0, 0, -1, 0, 0, 0, 1, 0, 0, 0);
  1800. Transform3D flip_z_transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 0);
  1801. _VariantCall::add_variant_constant(Variant::TRANSFORM3D, "IDENTITY", identity_transform);
  1802. _VariantCall::add_variant_constant(Variant::TRANSFORM3D, "FLIP_X", flip_x_transform);
  1803. _VariantCall::add_variant_constant(Variant::TRANSFORM3D, "FLIP_Y", flip_y_transform);
  1804. _VariantCall::add_variant_constant(Variant::TRANSFORM3D, "FLIP_Z", flip_z_transform);
  1805. Basis identity_basis = Basis();
  1806. Basis flip_x_basis = Basis(-1, 0, 0, 0, 1, 0, 0, 0, 1);
  1807. Basis flip_y_basis = Basis(1, 0, 0, 0, -1, 0, 0, 0, 1);
  1808. Basis flip_z_basis = Basis(1, 0, 0, 0, 1, 0, 0, 0, -1);
  1809. _VariantCall::add_variant_constant(Variant::BASIS, "IDENTITY", identity_basis);
  1810. _VariantCall::add_variant_constant(Variant::BASIS, "FLIP_X", flip_x_basis);
  1811. _VariantCall::add_variant_constant(Variant::BASIS, "FLIP_Y", flip_y_basis);
  1812. _VariantCall::add_variant_constant(Variant::BASIS, "FLIP_Z", flip_z_basis);
  1813. _VariantCall::add_variant_constant(Variant::PLANE, "PLANE_YZ", Plane(Vector3(1, 0, 0), 0));
  1814. _VariantCall::add_variant_constant(Variant::PLANE, "PLANE_XZ", Plane(Vector3(0, 1, 0), 0));
  1815. _VariantCall::add_variant_constant(Variant::PLANE, "PLANE_XY", Plane(Vector3(0, 0, 1), 0));
  1816. _VariantCall::add_variant_constant(Variant::QUATERNION, "IDENTITY", Quaternion(0, 0, 0, 1));
  1817. }
  1818. void Variant::_register_variant_methods() {
  1819. _register_variant_builtin_methods(); //needs to be out due to namespace
  1820. }
  1821. void Variant::_unregister_variant_methods() {
  1822. //clear methods
  1823. memdelete_arr(builtin_method_names);
  1824. memdelete_arr(builtin_method_info);
  1825. memdelete_arr(_VariantCall::constant_data);
  1826. }