variant_call.cpp 166 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827
  1. /**************************************************************************/
  2. /* variant_call.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "variant.h"
  31. #include "core/crypto/crypto_core.h"
  32. #include "core/debugger/engine_debugger.h"
  33. #include "core/io/compression.h"
  34. #include "core/io/marshalls.h"
  35. #include "core/object/class_db.h"
  36. #include "core/os/os.h"
  37. #include "core/templates/local_vector.h"
  38. #include "core/templates/oa_hash_map.h"
  39. typedef void (*VariantFunc)(Variant &r_ret, Variant &p_self, const Variant **p_args);
  40. typedef void (*VariantConstructFunc)(Variant &r_ret, const Variant **p_args);
  41. template <typename R, typename... P>
  42. 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) {
  43. call_with_variant_args_static_ret_dv(method, p_args, p_argcount, r_ret, r_error, p_defvals);
  44. }
  45. template <typename... P>
  46. 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) {
  47. call_with_variant_args_static_dv(method, p_args, p_argcount, r_error, p_defvals);
  48. }
  49. template <typename R, typename T, typename... P>
  50. 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) {
  51. call_with_variant_args_ret_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_ret, r_error, p_defvals);
  52. }
  53. template <typename R, typename T, typename... P>
  54. 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) {
  55. call_with_variant_args_retc_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_ret, r_error, p_defvals);
  56. }
  57. template <typename T, typename... P>
  58. 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) {
  59. VariantInternal::clear(&r_ret);
  60. call_with_variant_args_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_error, p_defvals);
  61. }
  62. template <typename T, typename... 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. VariantInternal::clear(&r_ret);
  65. call_with_variant_argsc_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_error, p_defvals);
  66. }
  67. template <typename From, typename R, typename T, typename... P>
  68. static _FORCE_INLINE_ void vc_convert_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) {
  69. T converted(static_cast<T>(*VariantGetInternalPtr<From>::get_ptr(base)));
  70. call_with_variant_args_ret_dv(&converted, method, p_args, p_argcount, r_ret, r_error, p_defvals);
  71. }
  72. template <typename From, typename R, typename T, typename... P>
  73. static _FORCE_INLINE_ void vc_convert_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) {
  74. T converted(static_cast<T>(*VariantGetInternalPtr<From>::get_ptr(base)));
  75. call_with_variant_args_retc_dv(&converted, method, p_args, p_argcount, r_ret, r_error, p_defvals);
  76. }
  77. template <typename From, typename T, typename... P>
  78. static _FORCE_INLINE_ void vc_convert_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) {
  79. T converted(static_cast<T>(*VariantGetInternalPtr<From>::get_ptr(base)));
  80. call_with_variant_args_dv(&converted, method, p_args, p_argcount, r_error, p_defvals);
  81. }
  82. template <typename From, typename T, typename... P>
  83. static _FORCE_INLINE_ void vc_convert_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) {
  84. T converted(static_cast<T>(*VariantGetInternalPtr<From>::get_ptr(base)));
  85. call_with_variant_argsc_dv(&converted, method, p_args, p_argcount, r_error, p_defvals);
  86. }
  87. template <typename R, typename T, typename... P>
  88. 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) {
  89. call_with_variant_args_retc_static_helper_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_ret, p_defvals, r_error);
  90. }
  91. template <typename T, typename... P>
  92. 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) {
  93. call_with_variant_args_static_helper_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, p_defvals, r_error);
  94. }
  95. template <typename R, typename T, typename... P>
  96. static _FORCE_INLINE_ void vc_validated_call(R (T::*method)(P...), Variant *base, const Variant **p_args, Variant *r_ret) {
  97. call_with_validated_variant_args_ret(base, method, p_args, r_ret);
  98. }
  99. template <typename R, typename T, typename... P>
  100. static _FORCE_INLINE_ void vc_validated_call(R (T::*method)(P...) const, Variant *base, const Variant **p_args, Variant *r_ret) {
  101. call_with_validated_variant_args_retc(base, method, p_args, r_ret);
  102. }
  103. template <typename T, typename... P>
  104. static _FORCE_INLINE_ void vc_validated_call(void (T::*method)(P...), Variant *base, const Variant **p_args, Variant *r_ret) {
  105. call_with_validated_variant_args(base, method, p_args);
  106. }
  107. template <typename T, typename... P>
  108. static _FORCE_INLINE_ void vc_validated_call(void (T::*method)(P...) const, Variant *base, const Variant **p_args, Variant *r_ret) {
  109. call_with_validated_variant_argsc(base, method, p_args);
  110. }
  111. template <typename From, typename R, typename T, typename... P>
  112. static _FORCE_INLINE_ void vc_convert_validated_call(R (T::*method)(P...), Variant *base, const Variant **p_args, Variant *r_ret) {
  113. T converted(static_cast<T>(*VariantGetInternalPtr<From>::get_ptr(base)));
  114. call_with_validated_variant_args_ret_helper<T, R, P...>(&converted, method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{});
  115. }
  116. template <typename From, typename R, typename T, typename... P>
  117. static _FORCE_INLINE_ void vc_convert_validated_call(R (T::*method)(P...) const, Variant *base, const Variant **p_args, Variant *r_ret) {
  118. T converted(static_cast<T>(*VariantGetInternalPtr<From>::get_ptr(base)));
  119. call_with_validated_variant_args_retc_helper<T, R, P...>(&converted, method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{});
  120. }
  121. template <typename From, typename T, typename... P>
  122. static _FORCE_INLINE_ void vc_convert_validated_call(void (T::*method)(P...), Variant *base, const Variant **p_args, Variant *r_ret) {
  123. T converted(static_cast<T>(*VariantGetInternalPtr<From>::get_ptr(base)));
  124. call_with_validated_variant_args_helper<T, P...>(&converted, method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{});
  125. }
  126. template <typename From, typename T, typename... P>
  127. static _FORCE_INLINE_ void vc_convert_validated_call(void (T::*method)(P...) const, Variant *base, const Variant **p_args, Variant *r_ret) {
  128. T converted(static_cast<T>(*VariantGetInternalPtr<From>::get_ptr(base)));
  129. call_with_validated_variant_argsc_helper<T, P...>(&converted, method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{});
  130. }
  131. template <typename R, typename T, typename... P>
  132. static _FORCE_INLINE_ void vc_validated_call_static(R (*method)(T *, P...), Variant *base, const Variant **p_args, Variant *r_ret) {
  133. call_with_validated_variant_args_static_retc(base, method, p_args, r_ret);
  134. }
  135. template <typename T, typename... P>
  136. static _FORCE_INLINE_ void vc_validated_call_static(void (*method)(T *, P...), Variant *base, const Variant **p_args, Variant *r_ret) {
  137. call_with_validated_variant_args_static(base, method, p_args);
  138. }
  139. template <typename R, typename... P>
  140. static _FORCE_INLINE_ void vc_validated_static_call(R (*method)(P...), const Variant **p_args, Variant *r_ret) {
  141. call_with_validated_variant_args_static_method_ret(method, p_args, r_ret);
  142. }
  143. template <typename... P>
  144. static _FORCE_INLINE_ void vc_validated_static_call(void (*method)(P...), const Variant **p_args, Variant *r_ret) {
  145. call_with_validated_variant_args_static_method(method, p_args);
  146. }
  147. template <typename R, typename T, typename... P>
  148. static _FORCE_INLINE_ void vc_ptrcall(R (T::*method)(P...), void *p_base, const void **p_args, void *r_ret) {
  149. call_with_ptr_args_ret(reinterpret_cast<T *>(p_base), method, p_args, r_ret);
  150. }
  151. template <typename R, typename T, typename... P>
  152. static _FORCE_INLINE_ void vc_ptrcall(R (T::*method)(P...) const, void *p_base, const void **p_args, void *r_ret) {
  153. call_with_ptr_args_retc(reinterpret_cast<T *>(p_base), method, p_args, r_ret);
  154. }
  155. template <typename T, typename... P>
  156. static _FORCE_INLINE_ void vc_ptrcall(void (T::*method)(P...), void *p_base, const void **p_args, void *r_ret) {
  157. call_with_ptr_args(reinterpret_cast<T *>(p_base), method, p_args);
  158. }
  159. template <typename T, typename... P>
  160. static _FORCE_INLINE_ void vc_ptrcall(void (T::*method)(P...) const, void *p_base, const void **p_args, void *r_ret) {
  161. call_with_ptr_argsc(reinterpret_cast<T *>(p_base), method, p_args);
  162. }
  163. template <typename From, typename R, typename T, typename... P>
  164. static _FORCE_INLINE_ void vc_convert_ptrcall(R (T::*method)(P...), void *p_base, const void **p_args, void *r_ret) {
  165. T converted(*reinterpret_cast<From *>(p_base));
  166. call_with_ptr_args_ret(&converted, method, p_args, r_ret);
  167. }
  168. template <typename From, typename R, typename T, typename... P>
  169. static _FORCE_INLINE_ void vc_convert_ptrcall(R (T::*method)(P...) const, void *p_base, const void **p_args, void *r_ret) {
  170. T converted(*reinterpret_cast<From *>(p_base));
  171. call_with_ptr_args_retc(&converted, method, p_args, r_ret);
  172. }
  173. template <typename From, typename T, typename... P>
  174. static _FORCE_INLINE_ void vc_convert_ptrcall(void (T::*method)(P...), void *p_base, const void **p_args, void *r_ret) {
  175. T converted(*reinterpret_cast<From *>(p_base));
  176. call_with_ptr_args(&converted, method, p_args);
  177. }
  178. template <typename From, typename T, typename... P>
  179. static _FORCE_INLINE_ void vc_convert_ptrcall(void (T::*method)(P...) const, void *p_base, const void **p_args, void *r_ret) {
  180. T converted(*reinterpret_cast<From *>(p_base));
  181. call_with_ptr_argsc(&converted, method, p_args);
  182. }
  183. template <typename R, typename T, typename... P>
  184. static _FORCE_INLINE_ int vc_get_argument_count(R (T::*method)(P...)) {
  185. return sizeof...(P);
  186. }
  187. template <typename R, typename T, typename... P>
  188. static _FORCE_INLINE_ int vc_get_argument_count(R (T::*method)(P...) const) {
  189. return sizeof...(P);
  190. }
  191. template <typename T, typename... P>
  192. static _FORCE_INLINE_ int vc_get_argument_count(void (T::*method)(P...)) {
  193. return sizeof...(P);
  194. }
  195. template <typename T, typename... P>
  196. static _FORCE_INLINE_ int vc_get_argument_count(void (T::*method)(P...) const) {
  197. return sizeof...(P);
  198. }
  199. template <typename R, typename T, typename... P>
  200. static _FORCE_INLINE_ int vc_get_argument_count(R (*method)(T *, P...)) {
  201. return sizeof...(P);
  202. }
  203. template <typename R, typename... P>
  204. static _FORCE_INLINE_ int vc_get_argument_count_static(R (*method)(P...)) {
  205. return sizeof...(P);
  206. }
  207. template <typename R, typename T, typename... P>
  208. static _FORCE_INLINE_ Variant::Type vc_get_argument_type(R (T::*method)(P...), int p_arg) {
  209. return call_get_argument_type<P...>(p_arg);
  210. }
  211. template <typename R, typename T, typename... P>
  212. static _FORCE_INLINE_ Variant::Type vc_get_argument_type(R (T::*method)(P...) const, int p_arg) {
  213. return call_get_argument_type<P...>(p_arg);
  214. }
  215. template <typename T, typename... P>
  216. static _FORCE_INLINE_ Variant::Type vc_get_argument_type(void (T::*method)(P...), int p_arg) {
  217. return call_get_argument_type<P...>(p_arg);
  218. }
  219. template <typename T, typename... P>
  220. static _FORCE_INLINE_ Variant::Type vc_get_argument_type(void (T::*method)(P...) const, int p_arg) {
  221. return call_get_argument_type<P...>(p_arg);
  222. }
  223. template <typename R, typename T, typename... P>
  224. static _FORCE_INLINE_ Variant::Type vc_get_argument_type(R (*method)(T *, P...), int p_arg) {
  225. return call_get_argument_type<P...>(p_arg);
  226. }
  227. template <typename R, typename... P>
  228. static _FORCE_INLINE_ Variant::Type vc_get_argument_type_static(R (*method)(P...), int p_arg) {
  229. return call_get_argument_type<P...>(p_arg);
  230. }
  231. template <typename R, typename T, typename... P>
  232. static _FORCE_INLINE_ Variant::Type vc_get_return_type(R (T::*method)(P...)) {
  233. return GetTypeInfo<R>::VARIANT_TYPE;
  234. }
  235. template <typename R, typename T, typename... P>
  236. static _FORCE_INLINE_ Variant::Type vc_get_return_type(R (T::*method)(P...) const) {
  237. return GetTypeInfo<R>::VARIANT_TYPE;
  238. }
  239. template <typename T, typename... P>
  240. static _FORCE_INLINE_ Variant::Type vc_get_return_type(void (T::*method)(P...)) {
  241. return Variant::NIL;
  242. }
  243. template <typename T, typename... P>
  244. static _FORCE_INLINE_ Variant::Type vc_get_return_type(void (T::*method)(P...) const) {
  245. return Variant::NIL;
  246. }
  247. template <typename R, typename... P>
  248. static _FORCE_INLINE_ Variant::Type vc_get_return_type(R (*method)(P...)) {
  249. return GetTypeInfo<R>::VARIANT_TYPE;
  250. }
  251. template <typename... P>
  252. static _FORCE_INLINE_ Variant::Type vc_get_return_type(void (*method)(P...)) {
  253. return Variant::NIL;
  254. }
  255. template <typename R, typename T, typename... P>
  256. static _FORCE_INLINE_ bool vc_has_return_type(R (T::*method)(P...)) {
  257. return true;
  258. }
  259. template <typename R, typename T, typename... P>
  260. static _FORCE_INLINE_ bool vc_has_return_type(R (T::*method)(P...) const) {
  261. return true;
  262. }
  263. template <typename T, typename... P>
  264. static _FORCE_INLINE_ bool vc_has_return_type(void (T::*method)(P...)) {
  265. return false;
  266. }
  267. template <typename T, typename... P>
  268. static _FORCE_INLINE_ bool vc_has_return_type(void (T::*method)(P...) const) {
  269. return false;
  270. }
  271. template <typename... P>
  272. static _FORCE_INLINE_ bool vc_has_return_type_static(void (*method)(P...)) {
  273. return false;
  274. }
  275. template <typename R, typename... P>
  276. static _FORCE_INLINE_ bool vc_has_return_type_static(R (*method)(P...)) {
  277. return true;
  278. }
  279. template <typename R, typename T, typename... P>
  280. static _FORCE_INLINE_ bool vc_is_const(R (T::*method)(P...)) {
  281. return false;
  282. }
  283. template <typename R, typename T, typename... P>
  284. static _FORCE_INLINE_ bool vc_is_const(R (T::*method)(P...) const) {
  285. return true;
  286. }
  287. template <typename T, typename... P>
  288. static _FORCE_INLINE_ bool vc_is_const(void (T::*method)(P...)) {
  289. return false;
  290. }
  291. template <typename T, typename... P>
  292. static _FORCE_INLINE_ bool vc_is_const(void (T::*method)(P...) const) {
  293. return true;
  294. }
  295. template <typename R, typename T, typename... P>
  296. static _FORCE_INLINE_ Variant::Type vc_get_base_type(R (T::*method)(P...)) {
  297. return GetTypeInfo<T>::VARIANT_TYPE;
  298. }
  299. template <typename R, typename T, typename... P>
  300. static _FORCE_INLINE_ Variant::Type vc_get_base_type(R (T::*method)(P...) const) {
  301. return GetTypeInfo<T>::VARIANT_TYPE;
  302. }
  303. template <typename T, typename... P>
  304. static _FORCE_INLINE_ Variant::Type vc_get_base_type(void (T::*method)(P...)) {
  305. return GetTypeInfo<T>::VARIANT_TYPE;
  306. }
  307. template <typename T, typename... P>
  308. static _FORCE_INLINE_ Variant::Type vc_get_base_type(void (T::*method)(P...) const) {
  309. return GetTypeInfo<T>::VARIANT_TYPE;
  310. }
  311. #define METHOD_CLASS(m_class, m_method_name, m_method_ptr) \
  312. struct Method_##m_class##_##m_method_name { \
  313. static void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { \
  314. vc_method_call(m_method_ptr, base, p_args, p_argcount, r_ret, p_defvals, r_error); \
  315. } \
  316. static void validated_call(Variant *base, const Variant **p_args, int p_argcount, Variant *r_ret) { \
  317. vc_validated_call(m_method_ptr, base, p_args, r_ret); \
  318. } \
  319. static void ptrcall(void *p_base, const void **p_args, void *r_ret, int p_argcount) { \
  320. vc_ptrcall(m_method_ptr, p_base, p_args, r_ret); \
  321. } \
  322. static int get_argument_count() { \
  323. return vc_get_argument_count(m_method_ptr); \
  324. } \
  325. static Variant::Type get_argument_type(int p_arg) { \
  326. return vc_get_argument_type(m_method_ptr, p_arg); \
  327. } \
  328. static Variant::Type get_return_type() { \
  329. return vc_get_return_type(m_method_ptr); \
  330. } \
  331. static bool has_return_type() { \
  332. return vc_has_return_type(m_method_ptr); \
  333. } \
  334. static bool is_const() { \
  335. return vc_is_const(m_method_ptr); \
  336. } \
  337. static bool is_static() { \
  338. return false; \
  339. } \
  340. static bool is_vararg() { \
  341. return false; \
  342. } \
  343. static Variant::Type get_base_type() { \
  344. return vc_get_base_type(m_method_ptr); \
  345. } \
  346. static StringName get_name() { \
  347. return #m_method_name; \
  348. } \
  349. };
  350. #define CONVERT_METHOD_CLASS(m_class, m_method_name, m_method_ptr) \
  351. struct Method_##m_class##_##m_method_name { \
  352. static void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { \
  353. vc_convert_method_call<m_class>(m_method_ptr, base, p_args, p_argcount, r_ret, p_defvals, r_error); \
  354. } \
  355. static void validated_call(Variant *base, const Variant **p_args, int p_argcount, Variant *r_ret) { \
  356. vc_convert_validated_call<m_class>(m_method_ptr, base, p_args, r_ret); \
  357. } \
  358. static void ptrcall(void *p_base, const void **p_args, void *r_ret, int p_argcount) { \
  359. vc_convert_ptrcall<m_class>(m_method_ptr, p_base, p_args, r_ret); \
  360. } \
  361. static int get_argument_count() { \
  362. return vc_get_argument_count(m_method_ptr); \
  363. } \
  364. static Variant::Type get_argument_type(int p_arg) { \
  365. return vc_get_argument_type(m_method_ptr, p_arg); \
  366. } \
  367. static Variant::Type get_return_type() { \
  368. return vc_get_return_type(m_method_ptr); \
  369. } \
  370. static bool has_return_type() { \
  371. return vc_has_return_type(m_method_ptr); \
  372. } \
  373. static bool is_const() { \
  374. return vc_is_const(m_method_ptr); \
  375. } \
  376. static bool is_static() { \
  377. return false; \
  378. } \
  379. static bool is_vararg() { \
  380. return false; \
  381. } \
  382. static Variant::Type get_base_type() { \
  383. return GetTypeInfo<m_class>::VARIANT_TYPE; \
  384. } \
  385. static StringName get_name() { \
  386. return #m_method_name; \
  387. } \
  388. };
  389. template <typename R, typename... P>
  390. static _FORCE_INLINE_ void vc_static_ptrcall(R (*method)(P...), const void **p_args, void *r_ret) {
  391. call_with_ptr_args_static_method_ret<R, P...>(method, p_args, r_ret);
  392. }
  393. template <typename... P>
  394. static _FORCE_INLINE_ void vc_static_ptrcall(void (*method)(P...), const void **p_args, void *r_ret) {
  395. call_with_ptr_args_static_method<P...>(method, p_args);
  396. }
  397. #define STATIC_METHOD_CLASS(m_class, m_method_name, m_method_ptr) \
  398. struct Method_##m_class##_##m_method_name { \
  399. static void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { \
  400. vc_static_method_call(m_method_ptr, p_args, p_argcount, r_ret, p_defvals, r_error); \
  401. } \
  402. static void validated_call(Variant *base, const Variant **p_args, int p_argcount, Variant *r_ret) { \
  403. vc_validated_static_call(m_method_ptr, p_args, r_ret); \
  404. } \
  405. static void ptrcall(void *p_base, const void **p_args, void *r_ret, int p_argcount) { \
  406. vc_static_ptrcall(m_method_ptr, p_args, r_ret); \
  407. } \
  408. static int get_argument_count() { \
  409. return vc_get_argument_count_static(m_method_ptr); \
  410. } \
  411. static Variant::Type get_argument_type(int p_arg) { \
  412. return vc_get_argument_type_static(m_method_ptr, p_arg); \
  413. } \
  414. static Variant::Type get_return_type() { \
  415. return vc_get_return_type(m_method_ptr); \
  416. } \
  417. static bool has_return_type() { \
  418. return vc_has_return_type_static(m_method_ptr); \
  419. } \
  420. static bool is_const() { \
  421. return false; \
  422. } \
  423. static bool is_static() { \
  424. return true; \
  425. } \
  426. static bool is_vararg() { \
  427. return false; \
  428. } \
  429. static Variant::Type get_base_type() { \
  430. return GetTypeInfo<m_class>::VARIANT_TYPE; \
  431. } \
  432. static StringName get_name() { \
  433. return #m_method_name; \
  434. } \
  435. };
  436. template <typename R, typename T, typename... P>
  437. static _FORCE_INLINE_ void vc_ptrcall(R (*method)(T *, P...), void *p_base, const void **p_args, void *r_ret) {
  438. call_with_ptr_args_static_retc<T, R, P...>(reinterpret_cast<T *>(p_base), method, p_args, r_ret);
  439. }
  440. template <typename T, typename... P>
  441. static _FORCE_INLINE_ void vc_ptrcall(void (*method)(T *, P...), void *p_base, const void **p_args, void *r_ret) {
  442. call_with_ptr_args_static<T, P...>(reinterpret_cast<T *>(p_base), method, p_args);
  443. }
  444. #define FUNCTION_CLASS(m_class, m_method_name, m_method_ptr, m_const) \
  445. struct Method_##m_class##_##m_method_name { \
  446. static void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { \
  447. vc_method_call_static(m_method_ptr, base, p_args, p_argcount, r_ret, p_defvals, r_error); \
  448. } \
  449. static void validated_call(Variant *base, const Variant **p_args, int p_argcount, Variant *r_ret) { \
  450. vc_validated_call_static(m_method_ptr, base, p_args, r_ret); \
  451. } \
  452. static void ptrcall(void *p_base, const void **p_args, void *r_ret, int p_argcount) { \
  453. vc_ptrcall(m_method_ptr, p_base, p_args, r_ret); \
  454. } \
  455. static int get_argument_count() { \
  456. return vc_get_argument_count(m_method_ptr); \
  457. } \
  458. static Variant::Type get_argument_type(int p_arg) { \
  459. return vc_get_argument_type(m_method_ptr, p_arg); \
  460. } \
  461. static Variant::Type get_return_type() { \
  462. return vc_get_return_type(m_method_ptr); \
  463. } \
  464. static bool has_return_type() { \
  465. return vc_has_return_type_static(m_method_ptr); \
  466. } \
  467. static bool is_const() { \
  468. return m_const; \
  469. } \
  470. static bool is_static() { \
  471. return false; \
  472. } \
  473. static bool is_vararg() { \
  474. return false; \
  475. } \
  476. static Variant::Type get_base_type() { \
  477. return GetTypeInfo<m_class>::VARIANT_TYPE; \
  478. } \
  479. static StringName get_name() { \
  480. return #m_method_name; \
  481. } \
  482. };
  483. #define VARARG_CLASS(m_class, m_method_name, m_method_ptr, m_has_return, m_return_type) \
  484. struct Method_##m_class##_##m_method_name { \
  485. static void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { \
  486. m_method_ptr(base, p_args, p_argcount, r_ret, r_error); \
  487. } \
  488. static void validated_call(Variant *base, const Variant **p_args, int p_argcount, Variant *r_ret) { \
  489. Callable::CallError ce; \
  490. m_method_ptr(base, p_args, p_argcount, *r_ret, ce); \
  491. } \
  492. static void ptrcall(void *p_base, const void **p_args, void *r_ret, int p_argcount) { \
  493. LocalVector<Variant> vars; \
  494. LocalVector<const Variant *> vars_ptrs; \
  495. vars.resize(p_argcount); \
  496. vars_ptrs.resize(p_argcount); \
  497. for (int i = 0; i < p_argcount; i++) { \
  498. vars[i] = PtrToArg<Variant>::convert(p_args[i]); \
  499. vars_ptrs[i] = &vars[i]; \
  500. } \
  501. Variant base = PtrToArg<m_class>::convert(p_base); \
  502. Variant ret; \
  503. Callable::CallError ce; \
  504. m_method_ptr(&base, vars_ptrs.ptr(), p_argcount, ret, ce); \
  505. if (m_has_return) { \
  506. m_return_type r = ret; \
  507. PtrToArg<m_return_type>::encode(ret, r_ret); \
  508. } \
  509. } \
  510. static int get_argument_count() { \
  511. return 0; \
  512. } \
  513. static Variant::Type get_argument_type(int p_arg) { \
  514. return Variant::NIL; \
  515. } \
  516. static Variant::Type get_return_type() { \
  517. return GetTypeInfo<m_return_type>::VARIANT_TYPE; \
  518. } \
  519. static bool has_return_type() { \
  520. return m_has_return; \
  521. } \
  522. static bool is_const() { \
  523. return true; \
  524. } \
  525. static bool is_static() { \
  526. return false; \
  527. } \
  528. static bool is_vararg() { \
  529. return true; \
  530. } \
  531. static Variant::Type get_base_type() { \
  532. return GetTypeInfo<m_class>::VARIANT_TYPE; \
  533. } \
  534. static StringName get_name() { \
  535. return #m_method_name; \
  536. } \
  537. };
  538. #define VARARG_CLASS1(m_class, m_method_name, m_method_ptr, m_arg_type) \
  539. struct Method_##m_class##_##m_method_name { \
  540. static void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { \
  541. m_method_ptr(base, p_args, p_argcount, r_ret, r_error); \
  542. } \
  543. static void validated_call(Variant *base, const Variant **p_args, int p_argcount, Variant *r_ret) { \
  544. Callable::CallError ce; \
  545. m_method_ptr(base, p_args, p_argcount, *r_ret, ce); \
  546. } \
  547. static void ptrcall(void *p_base, const void **p_args, void *r_ret, int p_argcount) { \
  548. LocalVector<Variant> vars; \
  549. LocalVector<const Variant *> vars_ptrs; \
  550. vars.resize(p_argcount); \
  551. vars_ptrs.resize(p_argcount); \
  552. for (int i = 0; i < p_argcount; i++) { \
  553. vars[i] = PtrToArg<Variant>::convert(p_args[i]); \
  554. vars_ptrs[i] = &vars[i]; \
  555. } \
  556. Variant base = PtrToArg<m_class>::convert(p_base); \
  557. Variant ret; \
  558. Callable::CallError ce; \
  559. m_method_ptr(&base, vars_ptrs.ptr(), p_argcount, ret, ce); \
  560. } \
  561. static int get_argument_count() { \
  562. return 1; \
  563. } \
  564. static Variant::Type get_argument_type(int p_arg) { \
  565. return m_arg_type; \
  566. } \
  567. static Variant::Type get_return_type() { \
  568. return Variant::NIL; \
  569. } \
  570. static bool has_return_type() { \
  571. return false; \
  572. } \
  573. static bool is_const() { \
  574. return true; \
  575. } \
  576. static bool is_static() { \
  577. return false; \
  578. } \
  579. static bool is_vararg() { \
  580. return true; \
  581. } \
  582. static Variant::Type get_base_type() { \
  583. return GetTypeInfo<m_class>::VARIANT_TYPE; \
  584. } \
  585. static StringName get_name() { \
  586. return #m_method_name; \
  587. } \
  588. };
  589. #define VARCALL_PACKED_GETTER(m_packed_type, m_return_type) \
  590. static m_return_type func_##m_packed_type##_get(m_packed_type *p_instance, int64_t p_index) { \
  591. return p_instance->get(p_index); \
  592. }
  593. struct _VariantCall {
  594. VARCALL_PACKED_GETTER(PackedByteArray, uint8_t)
  595. VARCALL_PACKED_GETTER(PackedColorArray, Color)
  596. VARCALL_PACKED_GETTER(PackedFloat32Array, float)
  597. VARCALL_PACKED_GETTER(PackedFloat64Array, double)
  598. VARCALL_PACKED_GETTER(PackedInt32Array, int32_t)
  599. VARCALL_PACKED_GETTER(PackedInt64Array, int64_t)
  600. VARCALL_PACKED_GETTER(PackedStringArray, String)
  601. VARCALL_PACKED_GETTER(PackedVector2Array, Vector2)
  602. VARCALL_PACKED_GETTER(PackedVector3Array, Vector3)
  603. VARCALL_PACKED_GETTER(PackedVector4Array, Vector4)
  604. static String func_PackedByteArray_get_string_from_ascii(PackedByteArray *p_instance) {
  605. String s;
  606. if (p_instance->size() > 0) {
  607. const uint8_t *r = p_instance->ptr();
  608. CharString cs;
  609. cs.resize(p_instance->size() + 1);
  610. memcpy(cs.ptrw(), r, p_instance->size());
  611. cs[(int)p_instance->size()] = 0;
  612. s = cs.get_data();
  613. }
  614. return s;
  615. }
  616. static String func_PackedByteArray_get_string_from_utf8(PackedByteArray *p_instance) {
  617. String s;
  618. if (p_instance->size() > 0) {
  619. const uint8_t *r = p_instance->ptr();
  620. s.parse_utf8((const char *)r, p_instance->size());
  621. }
  622. return s;
  623. }
  624. static String func_PackedByteArray_get_string_from_utf16(PackedByteArray *p_instance) {
  625. String s;
  626. if (p_instance->size() > 0) {
  627. const uint8_t *r = p_instance->ptr();
  628. s.parse_utf16((const char16_t *)r, floor((double)p_instance->size() / (double)sizeof(char16_t)));
  629. }
  630. return s;
  631. }
  632. static String func_PackedByteArray_get_string_from_utf32(PackedByteArray *p_instance) {
  633. String s;
  634. if (p_instance->size() > 0) {
  635. const uint8_t *r = p_instance->ptr();
  636. s = String((const char32_t *)r, floor((double)p_instance->size() / (double)sizeof(char32_t)));
  637. }
  638. return s;
  639. }
  640. static String func_PackedByteArray_get_string_from_wchar(PackedByteArray *p_instance) {
  641. String s;
  642. if (p_instance->size() > 0) {
  643. const uint8_t *r = p_instance->ptr();
  644. #ifdef WINDOWS_ENABLED
  645. s.parse_utf16((const char16_t *)r, floor((double)p_instance->size() / (double)sizeof(char16_t)));
  646. #else
  647. s = String((const char32_t *)r, floor((double)p_instance->size() / (double)sizeof(char32_t)));
  648. #endif
  649. }
  650. return s;
  651. }
  652. static PackedByteArray func_PackedByteArray_compress(PackedByteArray *p_instance, int p_mode) {
  653. PackedByteArray compressed;
  654. if (p_instance->size() > 0) {
  655. Compression::Mode mode = (Compression::Mode)(p_mode);
  656. compressed.resize(Compression::get_max_compressed_buffer_size(p_instance->size(), mode));
  657. int result = Compression::compress(compressed.ptrw(), p_instance->ptr(), p_instance->size(), mode);
  658. result = result >= 0 ? result : 0;
  659. compressed.resize(result);
  660. }
  661. return compressed;
  662. }
  663. static PackedByteArray func_PackedByteArray_decompress(PackedByteArray *p_instance, int64_t p_buffer_size, int p_mode) {
  664. PackedByteArray decompressed;
  665. Compression::Mode mode = (Compression::Mode)(p_mode);
  666. int64_t buffer_size = p_buffer_size;
  667. if (buffer_size <= 0) {
  668. ERR_FAIL_V_MSG(decompressed, "Decompression buffer size must be greater than zero.");
  669. }
  670. if (p_instance->size() == 0) {
  671. ERR_FAIL_V_MSG(decompressed, "Compressed buffer size must be greater than zero.");
  672. }
  673. decompressed.resize(buffer_size);
  674. int result = Compression::decompress(decompressed.ptrw(), buffer_size, p_instance->ptr(), p_instance->size(), mode);
  675. result = result >= 0 ? result : 0;
  676. decompressed.resize(result);
  677. return decompressed;
  678. }
  679. static PackedByteArray func_PackedByteArray_decompress_dynamic(PackedByteArray *p_instance, int64_t p_buffer_size, int p_mode) {
  680. PackedByteArray decompressed;
  681. int64_t max_output_size = p_buffer_size;
  682. Compression::Mode mode = (Compression::Mode)(p_mode);
  683. int result = Compression::decompress_dynamic(&decompressed, max_output_size, p_instance->ptr(), p_instance->size(), mode);
  684. if (result == OK) {
  685. return decompressed;
  686. } else {
  687. decompressed.clear();
  688. ERR_FAIL_V_MSG(decompressed, "Decompression failed.");
  689. }
  690. }
  691. static String func_PackedByteArray_hex_encode(PackedByteArray *p_instance) {
  692. if (p_instance->size() == 0) {
  693. return String();
  694. }
  695. const uint8_t *r = p_instance->ptr();
  696. String s = String::hex_encode_buffer(&r[0], p_instance->size());
  697. return s;
  698. }
  699. static int64_t func_PackedByteArray_decode_u8(PackedByteArray *p_instance, int64_t p_offset) {
  700. uint64_t size = p_instance->size();
  701. ERR_FAIL_COND_V(p_offset < 0 || p_offset > int64_t(size) - 1, 0);
  702. const uint8_t *r = p_instance->ptr();
  703. return r[p_offset];
  704. }
  705. static int64_t func_PackedByteArray_decode_s8(PackedByteArray *p_instance, int64_t p_offset) {
  706. uint64_t size = p_instance->size();
  707. ERR_FAIL_COND_V(p_offset < 0 || p_offset > int64_t(size) - 1, 0);
  708. const uint8_t *r = p_instance->ptr();
  709. return *((const int8_t *)&r[p_offset]);
  710. }
  711. static int64_t func_PackedByteArray_decode_u16(PackedByteArray *p_instance, int64_t p_offset) {
  712. uint64_t size = p_instance->size();
  713. ERR_FAIL_COND_V(p_offset < 0 || p_offset > (int64_t(size) - 2), 0);
  714. const uint8_t *r = p_instance->ptr();
  715. return decode_uint16(&r[p_offset]);
  716. }
  717. static int64_t func_PackedByteArray_decode_s16(PackedByteArray *p_instance, int64_t p_offset) {
  718. uint64_t size = p_instance->size();
  719. ERR_FAIL_COND_V(p_offset < 0 || p_offset > (int64_t(size) - 2), 0);
  720. const uint8_t *r = p_instance->ptr();
  721. return (int16_t)decode_uint16(&r[p_offset]);
  722. }
  723. static int64_t func_PackedByteArray_decode_u32(PackedByteArray *p_instance, int64_t p_offset) {
  724. uint64_t size = p_instance->size();
  725. ERR_FAIL_COND_V(p_offset < 0 || p_offset > (int64_t(size) - 4), 0);
  726. const uint8_t *r = p_instance->ptr();
  727. return decode_uint32(&r[p_offset]);
  728. }
  729. static int64_t func_PackedByteArray_decode_s32(PackedByteArray *p_instance, int64_t p_offset) {
  730. uint64_t size = p_instance->size();
  731. ERR_FAIL_COND_V(p_offset < 0 || p_offset > (int64_t(size) - 4), 0);
  732. const uint8_t *r = p_instance->ptr();
  733. return (int32_t)decode_uint32(&r[p_offset]);
  734. }
  735. static int64_t func_PackedByteArray_decode_u64(PackedByteArray *p_instance, int64_t p_offset) {
  736. uint64_t size = p_instance->size();
  737. ERR_FAIL_COND_V(p_offset < 0 || p_offset > (int64_t(size) - 8), 0);
  738. const uint8_t *r = p_instance->ptr();
  739. return (int64_t)decode_uint64(&r[p_offset]);
  740. }
  741. static int64_t func_PackedByteArray_decode_s64(PackedByteArray *p_instance, int64_t p_offset) {
  742. uint64_t size = p_instance->size();
  743. ERR_FAIL_COND_V(p_offset < 0 || p_offset > (int64_t(size) - 8), 0);
  744. const uint8_t *r = p_instance->ptr();
  745. return (int64_t)decode_uint64(&r[p_offset]);
  746. }
  747. static double func_PackedByteArray_decode_half(PackedByteArray *p_instance, int64_t p_offset) {
  748. uint64_t size = p_instance->size();
  749. ERR_FAIL_COND_V(p_offset < 0 || p_offset > (int64_t(size) - 2), 0);
  750. const uint8_t *r = p_instance->ptr();
  751. return Math::half_to_float(decode_uint16(&r[p_offset]));
  752. }
  753. static double func_PackedByteArray_decode_float(PackedByteArray *p_instance, int64_t p_offset) {
  754. uint64_t size = p_instance->size();
  755. ERR_FAIL_COND_V(p_offset < 0 || p_offset > (int64_t(size) - 4), 0);
  756. const uint8_t *r = p_instance->ptr();
  757. return decode_float(&r[p_offset]);
  758. }
  759. static double func_PackedByteArray_decode_double(PackedByteArray *p_instance, int64_t p_offset) {
  760. uint64_t size = p_instance->size();
  761. ERR_FAIL_COND_V(p_offset < 0 || p_offset > (int64_t(size) - 8), 0);
  762. const uint8_t *r = p_instance->ptr();
  763. return decode_double(&r[p_offset]);
  764. }
  765. static bool func_PackedByteArray_has_encoded_var(PackedByteArray *p_instance, int64_t p_offset, bool p_allow_objects) {
  766. uint64_t size = p_instance->size();
  767. ERR_FAIL_COND_V(p_offset < 0, false);
  768. const uint8_t *r = p_instance->ptr();
  769. Variant ret;
  770. Error err = decode_variant(ret, r + p_offset, size - p_offset, nullptr, p_allow_objects);
  771. return err == OK;
  772. }
  773. static Variant func_PackedByteArray_decode_var(PackedByteArray *p_instance, int64_t p_offset, bool p_allow_objects) {
  774. uint64_t size = p_instance->size();
  775. ERR_FAIL_COND_V(p_offset < 0, Variant());
  776. const uint8_t *r = p_instance->ptr();
  777. Variant ret;
  778. Error err = decode_variant(ret, r + p_offset, size - p_offset, nullptr, p_allow_objects);
  779. if (err != OK) {
  780. ret = Variant();
  781. }
  782. return ret;
  783. }
  784. static int64_t func_PackedByteArray_decode_var_size(PackedByteArray *p_instance, int64_t p_offset, bool p_allow_objects) {
  785. uint64_t size = p_instance->size();
  786. ERR_FAIL_COND_V(p_offset < 0, 0);
  787. const uint8_t *r = p_instance->ptr();
  788. Variant ret;
  789. int r_size;
  790. Error err = decode_variant(ret, r + p_offset, size - p_offset, &r_size, p_allow_objects);
  791. if (err == OK) {
  792. return r_size;
  793. }
  794. return 0;
  795. }
  796. static PackedInt32Array func_PackedByteArray_decode_s32_array(PackedByteArray *p_instance) {
  797. uint64_t size = p_instance->size();
  798. PackedInt32Array dest;
  799. if (size == 0) {
  800. return dest;
  801. }
  802. ERR_FAIL_COND_V_MSG(size % sizeof(int32_t), dest, "PackedByteArray size must be a multiple of 4 (size of 32-bit integer) to convert to PackedInt32Array.");
  803. const uint8_t *r = p_instance->ptr();
  804. dest.resize(size / sizeof(int32_t));
  805. ERR_FAIL_COND_V(dest.is_empty(), dest); // Avoid UB in case resize failed.
  806. memcpy(dest.ptrw(), r, dest.size() * sizeof(int32_t));
  807. return dest;
  808. }
  809. static PackedInt64Array func_PackedByteArray_decode_s64_array(PackedByteArray *p_instance) {
  810. uint64_t size = p_instance->size();
  811. PackedInt64Array dest;
  812. if (size == 0) {
  813. return dest;
  814. }
  815. ERR_FAIL_COND_V_MSG(size % sizeof(int64_t), dest, "PackedByteArray size must be a multiple of 8 (size of 64-bit integer) to convert to PackedInt64Array.");
  816. const uint8_t *r = p_instance->ptr();
  817. dest.resize(size / sizeof(int64_t));
  818. ERR_FAIL_COND_V(dest.is_empty(), dest); // Avoid UB in case resize failed.
  819. memcpy(dest.ptrw(), r, dest.size() * sizeof(int64_t));
  820. return dest;
  821. }
  822. static PackedFloat32Array func_PackedByteArray_decode_float_array(PackedByteArray *p_instance) {
  823. uint64_t size = p_instance->size();
  824. PackedFloat32Array dest;
  825. if (size == 0) {
  826. return dest;
  827. }
  828. ERR_FAIL_COND_V_MSG(size % sizeof(float), dest, "PackedByteArray size must be a multiple of 4 (size of 32-bit float) to convert to PackedFloat32Array.");
  829. const uint8_t *r = p_instance->ptr();
  830. dest.resize(size / sizeof(float));
  831. ERR_FAIL_COND_V(dest.is_empty(), dest); // Avoid UB in case resize failed.
  832. memcpy(dest.ptrw(), r, dest.size() * sizeof(float));
  833. return dest;
  834. }
  835. static PackedFloat64Array func_PackedByteArray_decode_double_array(PackedByteArray *p_instance) {
  836. uint64_t size = p_instance->size();
  837. PackedFloat64Array dest;
  838. if (size == 0) {
  839. return dest;
  840. }
  841. ERR_FAIL_COND_V_MSG(size % sizeof(double), dest, "PackedByteArray size must be a multiple of 8 (size of 64-bit double) to convert to PackedFloat64Array.");
  842. const uint8_t *r = p_instance->ptr();
  843. dest.resize(size / sizeof(double));
  844. ERR_FAIL_COND_V(dest.is_empty(), dest); // Avoid UB in case resize failed.
  845. memcpy(dest.ptrw(), r, dest.size() * sizeof(double));
  846. return dest;
  847. }
  848. static void func_PackedByteArray_encode_u8(PackedByteArray *p_instance, int64_t p_offset, int64_t p_value) {
  849. uint64_t size = p_instance->size();
  850. ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 1);
  851. uint8_t *w = p_instance->ptrw();
  852. *((uint8_t *)&w[p_offset]) = p_value;
  853. }
  854. static void func_PackedByteArray_encode_s8(PackedByteArray *p_instance, int64_t p_offset, int64_t p_value) {
  855. uint64_t size = p_instance->size();
  856. ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 1);
  857. uint8_t *w = p_instance->ptrw();
  858. *((int8_t *)&w[p_offset]) = p_value;
  859. }
  860. static void func_PackedByteArray_encode_u16(PackedByteArray *p_instance, int64_t p_offset, int64_t p_value) {
  861. uint64_t size = p_instance->size();
  862. ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 2);
  863. uint8_t *w = p_instance->ptrw();
  864. encode_uint16((uint16_t)p_value, &w[p_offset]);
  865. }
  866. static void func_PackedByteArray_encode_s16(PackedByteArray *p_instance, int64_t p_offset, int64_t p_value) {
  867. uint64_t size = p_instance->size();
  868. ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 2);
  869. uint8_t *w = p_instance->ptrw();
  870. encode_uint16((int16_t)p_value, &w[p_offset]);
  871. }
  872. static void func_PackedByteArray_encode_u32(PackedByteArray *p_instance, int64_t p_offset, int64_t p_value) {
  873. uint64_t size = p_instance->size();
  874. ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 4);
  875. uint8_t *w = p_instance->ptrw();
  876. encode_uint32((uint32_t)p_value, &w[p_offset]);
  877. }
  878. static void func_PackedByteArray_encode_s32(PackedByteArray *p_instance, int64_t p_offset, int64_t p_value) {
  879. uint64_t size = p_instance->size();
  880. ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 4);
  881. uint8_t *w = p_instance->ptrw();
  882. encode_uint32((int32_t)p_value, &w[p_offset]);
  883. }
  884. static void func_PackedByteArray_encode_u64(PackedByteArray *p_instance, int64_t p_offset, int64_t p_value) {
  885. uint64_t size = p_instance->size();
  886. ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 8);
  887. uint8_t *w = p_instance->ptrw();
  888. encode_uint64((uint64_t)p_value, &w[p_offset]);
  889. }
  890. static void func_PackedByteArray_encode_s64(PackedByteArray *p_instance, int64_t p_offset, int64_t p_value) {
  891. uint64_t size = p_instance->size();
  892. ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 8);
  893. uint8_t *w = p_instance->ptrw();
  894. encode_uint64((int64_t)p_value, &w[p_offset]);
  895. }
  896. static void func_PackedByteArray_encode_half(PackedByteArray *p_instance, int64_t p_offset, double p_value) {
  897. uint64_t size = p_instance->size();
  898. ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 2);
  899. uint8_t *w = p_instance->ptrw();
  900. encode_uint16(Math::make_half_float(p_value), &w[p_offset]);
  901. }
  902. static void func_PackedByteArray_encode_float(PackedByteArray *p_instance, int64_t p_offset, double p_value) {
  903. uint64_t size = p_instance->size();
  904. ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 4);
  905. uint8_t *w = p_instance->ptrw();
  906. encode_float(p_value, &w[p_offset]);
  907. }
  908. static void func_PackedByteArray_encode_double(PackedByteArray *p_instance, int64_t p_offset, double p_value) {
  909. uint64_t size = p_instance->size();
  910. ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(size) - 8);
  911. uint8_t *w = p_instance->ptrw();
  912. encode_double(p_value, &w[p_offset]);
  913. }
  914. static int64_t func_PackedByteArray_encode_var(PackedByteArray *p_instance, int64_t p_offset, const Variant &p_value, bool p_allow_objects) {
  915. uint64_t size = p_instance->size();
  916. ERR_FAIL_COND_V(p_offset < 0, -1);
  917. uint8_t *w = p_instance->ptrw();
  918. int len;
  919. Error err = encode_variant(p_value, nullptr, len, p_allow_objects);
  920. if (err != OK) {
  921. return -1;
  922. }
  923. if (uint64_t(p_offset + len) > size) {
  924. return -1; // did not fit
  925. }
  926. encode_variant(p_value, w + p_offset, len, p_allow_objects);
  927. return len;
  928. }
  929. static void func_Callable_call(Variant *v, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
  930. Callable *callable = VariantGetInternalPtr<Callable>::get_ptr(v);
  931. callable->callp(p_args, p_argcount, r_ret, r_error);
  932. }
  933. static void func_Callable_call_deferred(Variant *v, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
  934. Callable *callable = VariantGetInternalPtr<Callable>::get_ptr(v);
  935. callable->call_deferredp(p_args, p_argcount);
  936. }
  937. static void func_Callable_rpc(Variant *v, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
  938. Callable *callable = VariantGetInternalPtr<Callable>::get_ptr(v);
  939. callable->rpcp(0, p_args, p_argcount, r_error);
  940. }
  941. static void func_Callable_rpc_id(Variant *v, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
  942. if (p_argcount == 0) {
  943. r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  944. r_error.expected = 1;
  945. } else if (p_args[0]->get_type() != Variant::INT) {
  946. r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
  947. r_error.argument = 0;
  948. r_error.expected = Variant::INT;
  949. } else {
  950. Callable *callable = VariantGetInternalPtr<Callable>::get_ptr(v);
  951. callable->rpcp(*p_args[0], &p_args[1], p_argcount - 1, r_error);
  952. }
  953. }
  954. static void func_Callable_bind(Variant *v, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
  955. Callable *callable = VariantGetInternalPtr<Callable>::get_ptr(v);
  956. r_ret = callable->bindp(p_args, p_argcount);
  957. }
  958. static int func_Callable_get_argument_count(Callable *p_callable) {
  959. return p_callable->get_argument_count();
  960. }
  961. static void func_Signal_emit(Variant *v, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
  962. Signal *signal = VariantGetInternalPtr<Signal>::get_ptr(v);
  963. signal->emit(p_args, p_argcount);
  964. }
  965. struct ConstantData {
  966. HashMap<StringName, int64_t> value;
  967. #ifdef DEBUG_ENABLED
  968. List<StringName> value_ordered;
  969. #endif
  970. HashMap<StringName, Variant> variant_value;
  971. #ifdef DEBUG_ENABLED
  972. List<StringName> variant_value_ordered;
  973. #endif
  974. };
  975. static ConstantData *constant_data;
  976. static void add_constant(int p_type, const StringName &p_constant_name, int64_t p_constant_value) {
  977. constant_data[p_type].value[p_constant_name] = p_constant_value;
  978. #ifdef DEBUG_ENABLED
  979. constant_data[p_type].value_ordered.push_back(p_constant_name);
  980. #endif
  981. }
  982. static void add_variant_constant(int p_type, const StringName &p_constant_name, const Variant &p_constant_value) {
  983. constant_data[p_type].variant_value[p_constant_name] = p_constant_value;
  984. #ifdef DEBUG_ENABLED
  985. constant_data[p_type].variant_value_ordered.push_back(p_constant_name);
  986. #endif
  987. }
  988. struct EnumData {
  989. HashMap<StringName, HashMap<StringName, int>> value;
  990. };
  991. static EnumData *enum_data;
  992. static void add_enum_constant(int p_type, const StringName &p_enum_type_name, const StringName &p_enumeration_name, int p_enum_value) {
  993. enum_data[p_type].value[p_enum_type_name][p_enumeration_name] = p_enum_value;
  994. }
  995. };
  996. _VariantCall::ConstantData *_VariantCall::constant_data = nullptr;
  997. _VariantCall::EnumData *_VariantCall::enum_data = nullptr;
  998. struct VariantBuiltInMethodInfo {
  999. void (*call)(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) = nullptr;
  1000. Variant::ValidatedBuiltInMethod validated_call = nullptr;
  1001. Variant::PTRBuiltInMethod ptrcall = nullptr;
  1002. Vector<Variant> default_arguments;
  1003. Vector<String> argument_names;
  1004. bool is_const = false;
  1005. bool is_static = false;
  1006. bool has_return_type = false;
  1007. bool is_vararg = false;
  1008. Variant::Type return_type;
  1009. int argument_count = 0;
  1010. Variant::Type (*get_argument_type)(int p_arg) = nullptr;
  1011. MethodInfo get_method_info(const StringName &p_name) const {
  1012. MethodInfo mi;
  1013. mi.name = p_name;
  1014. if (has_return_type) {
  1015. mi.return_val.type = return_type;
  1016. if (mi.return_val.type == Variant::NIL) {
  1017. mi.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
  1018. }
  1019. }
  1020. if (is_const) {
  1021. mi.flags |= METHOD_FLAG_CONST;
  1022. }
  1023. if (is_vararg) {
  1024. mi.flags |= METHOD_FLAG_VARARG;
  1025. }
  1026. if (is_static) {
  1027. mi.flags |= METHOD_FLAG_STATIC;
  1028. }
  1029. for (int i = 0; i < argument_count; i++) {
  1030. PropertyInfo pi;
  1031. #ifdef DEBUG_METHODS_ENABLED
  1032. pi.name = argument_names[i];
  1033. #else
  1034. pi.name = "arg" + itos(i + 1);
  1035. #endif
  1036. pi.type = (*get_argument_type)(i);
  1037. if (pi.type == Variant::NIL) {
  1038. pi.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
  1039. }
  1040. mi.arguments.push_back(pi);
  1041. }
  1042. mi.default_arguments = default_arguments;
  1043. return mi;
  1044. }
  1045. };
  1046. typedef OAHashMap<StringName, VariantBuiltInMethodInfo> BuiltinMethodMap;
  1047. static BuiltinMethodMap *builtin_method_info;
  1048. static List<StringName> *builtin_method_names;
  1049. template <typename T>
  1050. static void register_builtin_method(const Vector<String> &p_argnames, const Vector<Variant> &p_def_args) {
  1051. StringName name = T::get_name();
  1052. ERR_FAIL_COND(builtin_method_info[T::get_base_type()].has(name));
  1053. VariantBuiltInMethodInfo imi;
  1054. imi.call = T::call;
  1055. imi.validated_call = T::validated_call;
  1056. imi.ptrcall = T::ptrcall;
  1057. imi.default_arguments = p_def_args;
  1058. imi.argument_names = p_argnames;
  1059. imi.is_const = T::is_const();
  1060. imi.is_static = T::is_static();
  1061. imi.is_vararg = T::is_vararg();
  1062. imi.has_return_type = T::has_return_type();
  1063. imi.return_type = T::get_return_type();
  1064. imi.argument_count = T::get_argument_count();
  1065. imi.get_argument_type = T::get_argument_type;
  1066. #ifdef DEBUG_METHODS_ENABLED
  1067. ERR_FAIL_COND(!imi.is_vararg && imi.argument_count != imi.argument_names.size());
  1068. #endif
  1069. builtin_method_info[T::get_base_type()].insert(name, imi);
  1070. builtin_method_names[T::get_base_type()].push_back(name);
  1071. }
  1072. void Variant::callp(const StringName &p_method, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
  1073. if (type == Variant::OBJECT) {
  1074. //call object
  1075. Object *obj = _get_obj().obj;
  1076. if (!obj) {
  1077. r_error.error = Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL;
  1078. return;
  1079. }
  1080. #ifdef DEBUG_ENABLED
  1081. if (EngineDebugger::is_active() && !_get_obj().id.is_ref_counted() && ObjectDB::get_instance(_get_obj().id) == nullptr) {
  1082. r_error.error = Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL;
  1083. return;
  1084. }
  1085. #endif
  1086. r_ret = _get_obj().obj->callp(p_method, p_args, p_argcount, r_error);
  1087. } else {
  1088. r_error.error = Callable::CallError::CALL_OK;
  1089. const VariantBuiltInMethodInfo *imf = builtin_method_info[type].lookup_ptr(p_method);
  1090. if (!imf) {
  1091. r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
  1092. return;
  1093. }
  1094. imf->call(this, p_args, p_argcount, r_ret, imf->default_arguments, r_error);
  1095. }
  1096. }
  1097. void Variant::call_const(const StringName &p_method, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
  1098. if (type == Variant::OBJECT) {
  1099. //call object
  1100. Object *obj = _get_obj().obj;
  1101. if (!obj) {
  1102. r_error.error = Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL;
  1103. return;
  1104. }
  1105. #ifdef DEBUG_ENABLED
  1106. if (EngineDebugger::is_active() && !_get_obj().id.is_ref_counted() && ObjectDB::get_instance(_get_obj().id) == nullptr) {
  1107. r_error.error = Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL;
  1108. return;
  1109. }
  1110. #endif
  1111. r_ret = _get_obj().obj->call_const(p_method, p_args, p_argcount, r_error);
  1112. //else if (type==Variant::METHOD) {
  1113. } else {
  1114. r_error.error = Callable::CallError::CALL_OK;
  1115. const VariantBuiltInMethodInfo *imf = builtin_method_info[type].lookup_ptr(p_method);
  1116. if (!imf) {
  1117. r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
  1118. return;
  1119. }
  1120. if (!imf->is_const) {
  1121. r_error.error = Callable::CallError::CALL_ERROR_METHOD_NOT_CONST;
  1122. return;
  1123. }
  1124. imf->call(this, p_args, p_argcount, r_ret, imf->default_arguments, r_error);
  1125. }
  1126. }
  1127. 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) {
  1128. r_error.error = Callable::CallError::CALL_OK;
  1129. const VariantBuiltInMethodInfo *imf = builtin_method_info[p_type].lookup_ptr(p_method);
  1130. if (!imf) {
  1131. r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
  1132. return;
  1133. }
  1134. if (!imf->is_static) {
  1135. r_error.error = Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL;
  1136. return;
  1137. }
  1138. imf->call(nullptr, p_args, p_argcount, r_ret, imf->default_arguments, r_error);
  1139. }
  1140. bool Variant::has_method(const StringName &p_method) const {
  1141. if (type == OBJECT) {
  1142. Object *obj = get_validated_object();
  1143. if (!obj) {
  1144. return false;
  1145. }
  1146. return obj->has_method(p_method);
  1147. }
  1148. return builtin_method_info[type].has(p_method);
  1149. }
  1150. bool Variant::has_builtin_method(Variant::Type p_type, const StringName &p_method) {
  1151. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, false);
  1152. return builtin_method_info[p_type].has(p_method);
  1153. }
  1154. Variant::ValidatedBuiltInMethod Variant::get_validated_builtin_method(Variant::Type p_type, const StringName &p_method) {
  1155. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, nullptr);
  1156. const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
  1157. ERR_FAIL_NULL_V(method, nullptr);
  1158. return method->validated_call;
  1159. }
  1160. Variant::PTRBuiltInMethod Variant::get_ptr_builtin_method(Variant::Type p_type, const StringName &p_method) {
  1161. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, nullptr);
  1162. const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
  1163. ERR_FAIL_NULL_V(method, nullptr);
  1164. return method->ptrcall;
  1165. }
  1166. MethodInfo Variant::get_builtin_method_info(Variant::Type p_type, const StringName &p_method) {
  1167. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, MethodInfo());
  1168. const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
  1169. ERR_FAIL_NULL_V(method, MethodInfo());
  1170. return method->get_method_info(p_method);
  1171. }
  1172. int Variant::get_builtin_method_argument_count(Variant::Type p_type, const StringName &p_method) {
  1173. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, 0);
  1174. const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
  1175. ERR_FAIL_NULL_V(method, 0);
  1176. return method->argument_count;
  1177. }
  1178. Variant::Type Variant::get_builtin_method_argument_type(Variant::Type p_type, const StringName &p_method, int p_argument) {
  1179. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, Variant::NIL);
  1180. const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
  1181. ERR_FAIL_NULL_V(method, Variant::NIL);
  1182. ERR_FAIL_INDEX_V(p_argument, method->argument_count, Variant::NIL);
  1183. return method->get_argument_type(p_argument);
  1184. }
  1185. String Variant::get_builtin_method_argument_name(Variant::Type p_type, const StringName &p_method, int p_argument) {
  1186. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, String());
  1187. const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
  1188. ERR_FAIL_NULL_V(method, String());
  1189. #ifdef DEBUG_METHODS_ENABLED
  1190. ERR_FAIL_INDEX_V(p_argument, method->argument_count, String());
  1191. return method->argument_names[p_argument];
  1192. #else
  1193. return "arg" + itos(p_argument + 1);
  1194. #endif
  1195. }
  1196. Vector<Variant> Variant::get_builtin_method_default_arguments(Variant::Type p_type, const StringName &p_method) {
  1197. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, Vector<Variant>());
  1198. const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
  1199. ERR_FAIL_NULL_V(method, Vector<Variant>());
  1200. return method->default_arguments;
  1201. }
  1202. bool Variant::has_builtin_method_return_value(Variant::Type p_type, const StringName &p_method) {
  1203. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, false);
  1204. const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
  1205. ERR_FAIL_NULL_V(method, false);
  1206. return method->has_return_type;
  1207. }
  1208. void Variant::get_builtin_method_list(Variant::Type p_type, List<StringName> *p_list) {
  1209. ERR_FAIL_INDEX(p_type, Variant::VARIANT_MAX);
  1210. for (const StringName &E : builtin_method_names[p_type]) {
  1211. p_list->push_back(E);
  1212. }
  1213. }
  1214. int Variant::get_builtin_method_count(Variant::Type p_type) {
  1215. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, -1);
  1216. return builtin_method_names[p_type].size();
  1217. }
  1218. Variant::Type Variant::get_builtin_method_return_type(Variant::Type p_type, const StringName &p_method) {
  1219. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, Variant::NIL);
  1220. const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
  1221. ERR_FAIL_NULL_V(method, Variant::NIL);
  1222. return method->return_type;
  1223. }
  1224. bool Variant::is_builtin_method_const(Variant::Type p_type, const StringName &p_method) {
  1225. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, false);
  1226. const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
  1227. ERR_FAIL_NULL_V(method, false);
  1228. return method->is_const;
  1229. }
  1230. bool Variant::is_builtin_method_static(Variant::Type p_type, const StringName &p_method) {
  1231. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, false);
  1232. const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
  1233. ERR_FAIL_NULL_V(method, false);
  1234. return method->is_static;
  1235. }
  1236. bool Variant::is_builtin_method_vararg(Variant::Type p_type, const StringName &p_method) {
  1237. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, false);
  1238. const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
  1239. ERR_FAIL_NULL_V(method, false);
  1240. return method->is_vararg;
  1241. }
  1242. uint32_t Variant::get_builtin_method_hash(Variant::Type p_type, const StringName &p_method) {
  1243. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, 0);
  1244. const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method);
  1245. ERR_FAIL_NULL_V(method, 0);
  1246. uint32_t hash = hash_murmur3_one_32(method->is_const);
  1247. hash = hash_murmur3_one_32(method->is_static, hash);
  1248. hash = hash_murmur3_one_32(method->is_vararg, hash);
  1249. hash = hash_murmur3_one_32(method->has_return_type, hash);
  1250. if (method->has_return_type) {
  1251. hash = hash_murmur3_one_32(method->return_type, hash);
  1252. }
  1253. hash = hash_murmur3_one_32(method->argument_count, hash);
  1254. for (int i = 0; i < method->argument_count; i++) {
  1255. hash = hash_murmur3_one_32(method->get_argument_type(i), hash);
  1256. }
  1257. return hash_fmix32(hash);
  1258. }
  1259. void Variant::get_method_list(List<MethodInfo> *p_list) const {
  1260. if (type == OBJECT) {
  1261. Object *obj = get_validated_object();
  1262. if (obj) {
  1263. obj->get_method_list(p_list);
  1264. }
  1265. } else {
  1266. for (const StringName &E : builtin_method_names[type]) {
  1267. const VariantBuiltInMethodInfo *method = builtin_method_info[type].lookup_ptr(E);
  1268. ERR_CONTINUE(!method);
  1269. p_list->push_back(method->get_method_info(E));
  1270. }
  1271. }
  1272. }
  1273. void Variant::get_constants_for_type(Variant::Type p_type, List<StringName> *p_constants) {
  1274. ERR_FAIL_INDEX(p_type, Variant::VARIANT_MAX);
  1275. const _VariantCall::ConstantData &cd = _VariantCall::constant_data[p_type];
  1276. #ifdef DEBUG_ENABLED
  1277. for (const List<StringName>::Element *E = cd.value_ordered.front(); E; E = E->next()) {
  1278. p_constants->push_back(E->get());
  1279. #else
  1280. for (const KeyValue<StringName, int64_t> &E : cd.value) {
  1281. p_constants->push_back(E.key);
  1282. #endif
  1283. }
  1284. #ifdef DEBUG_ENABLED
  1285. for (const List<StringName>::Element *E = cd.variant_value_ordered.front(); E; E = E->next()) {
  1286. p_constants->push_back(E->get());
  1287. #else
  1288. for (const KeyValue<StringName, Variant> &E : cd.variant_value) {
  1289. p_constants->push_back(E.key);
  1290. #endif
  1291. }
  1292. }
  1293. int Variant::get_constants_count_for_type(Variant::Type p_type) {
  1294. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, -1);
  1295. _VariantCall::ConstantData &cd = _VariantCall::constant_data[p_type];
  1296. return cd.value.size() + cd.variant_value.size();
  1297. }
  1298. bool Variant::has_constant(Variant::Type p_type, const StringName &p_value) {
  1299. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, false);
  1300. _VariantCall::ConstantData &cd = _VariantCall::constant_data[p_type];
  1301. return cd.value.has(p_value) || cd.variant_value.has(p_value);
  1302. }
  1303. Variant Variant::get_constant_value(Variant::Type p_type, const StringName &p_value, bool *r_valid) {
  1304. if (r_valid) {
  1305. *r_valid = false;
  1306. }
  1307. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, 0);
  1308. _VariantCall::ConstantData &cd = _VariantCall::constant_data[p_type];
  1309. HashMap<StringName, int64_t>::Iterator E = cd.value.find(p_value);
  1310. if (!E) {
  1311. HashMap<StringName, Variant>::Iterator F = cd.variant_value.find(p_value);
  1312. if (F) {
  1313. if (r_valid) {
  1314. *r_valid = true;
  1315. }
  1316. return F->value;
  1317. } else {
  1318. return -1;
  1319. }
  1320. }
  1321. if (r_valid) {
  1322. *r_valid = true;
  1323. }
  1324. return E->value;
  1325. }
  1326. void Variant::get_enums_for_type(Variant::Type p_type, List<StringName> *p_enums) {
  1327. ERR_FAIL_INDEX(p_type, Variant::VARIANT_MAX);
  1328. _VariantCall::EnumData &enum_data = _VariantCall::enum_data[p_type];
  1329. for (const KeyValue<StringName, HashMap<StringName, int>> &E : enum_data.value) {
  1330. p_enums->push_back(E.key);
  1331. }
  1332. }
  1333. void Variant::get_enumerations_for_enum(Variant::Type p_type, const StringName &p_enum_name, List<StringName> *p_enumerations) {
  1334. ERR_FAIL_INDEX(p_type, Variant::VARIANT_MAX);
  1335. _VariantCall::EnumData &enum_data = _VariantCall::enum_data[p_type];
  1336. for (const KeyValue<StringName, HashMap<StringName, int>> &E : enum_data.value) {
  1337. for (const KeyValue<StringName, int> &V : E.value) {
  1338. p_enumerations->push_back(V.key);
  1339. }
  1340. }
  1341. }
  1342. int Variant::get_enum_value(Variant::Type p_type, const StringName &p_enum_name, const StringName &p_enumeration, bool *r_valid) {
  1343. if (r_valid) {
  1344. *r_valid = false;
  1345. }
  1346. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, -1);
  1347. _VariantCall::EnumData &enum_data = _VariantCall::enum_data[p_type];
  1348. HashMap<StringName, HashMap<StringName, int>>::Iterator E = enum_data.value.find(p_enum_name);
  1349. if (!E) {
  1350. return -1;
  1351. }
  1352. HashMap<StringName, int>::Iterator V = E->value.find(p_enumeration);
  1353. if (!V) {
  1354. return -1;
  1355. }
  1356. if (r_valid) {
  1357. *r_valid = true;
  1358. }
  1359. return V->value;
  1360. }
  1361. #ifdef DEBUG_METHODS_ENABLED
  1362. #define bind_method(m_type, m_method, m_arg_names, m_default_args) \
  1363. METHOD_CLASS(m_type, m_method, &m_type::m_method); \
  1364. register_builtin_method<Method_##m_type##_##m_method>(m_arg_names, m_default_args);
  1365. #else
  1366. #define bind_method(m_type, m_method, m_arg_names, m_default_args) \
  1367. METHOD_CLASS(m_type, m_method, &m_type ::m_method); \
  1368. register_builtin_method<Method_##m_type##_##m_method>(sarray(), m_default_args);
  1369. #endif
  1370. #ifdef DEBUG_METHODS_ENABLED
  1371. #define bind_convert_method(m_type_from, m_type_to, m_method, m_arg_names, m_default_args) \
  1372. CONVERT_METHOD_CLASS(m_type_from, m_method, &m_type_to::m_method); \
  1373. register_builtin_method<Method_##m_type_from##_##m_method>(m_arg_names, m_default_args);
  1374. #else
  1375. #define bind_convert_method(m_type_from, m_type_to, m_method, m_arg_names, m_default_args) \
  1376. CONVERT_METHOD_CLASS(m_type_from, m_method, &m_type_to ::m_method); \
  1377. register_builtin_method<Method_##m_type_from##_##m_method>(sarray(), m_default_args);
  1378. #endif
  1379. #ifdef DEBUG_METHODS_ENABLED
  1380. #define bind_static_method(m_type, m_method, m_arg_names, m_default_args) \
  1381. STATIC_METHOD_CLASS(m_type, m_method, m_type::m_method); \
  1382. register_builtin_method<Method_##m_type##_##m_method>(m_arg_names, m_default_args);
  1383. #else
  1384. #define bind_static_method(m_type, m_method, m_arg_names, m_default_args) \
  1385. STATIC_METHOD_CLASS(m_type, m_method, m_type ::m_method); \
  1386. register_builtin_method<Method_##m_type##_##m_method>(sarray(), m_default_args);
  1387. #endif
  1388. #ifdef DEBUG_METHODS_ENABLED
  1389. #define bind_methodv(m_type, m_name, m_method, m_arg_names, m_default_args) \
  1390. METHOD_CLASS(m_type, m_name, m_method); \
  1391. register_builtin_method<Method_##m_type##_##m_name>(m_arg_names, m_default_args);
  1392. #else
  1393. #define bind_methodv(m_type, m_name, m_method, m_arg_names, m_default_args) \
  1394. METHOD_CLASS(m_type, m_name, m_method); \
  1395. register_builtin_method<Method_##m_type##_##m_name>(sarray(), m_default_args);
  1396. #endif
  1397. #ifdef DEBUG_METHODS_ENABLED
  1398. #define bind_convert_methodv(m_type_from, m_type_to, m_name, m_method, m_arg_names, m_default_args) \
  1399. CONVERT_METHOD_CLASS(m_type_from, m_name, m_method); \
  1400. register_builtin_method<Method_##m_type_from##_##m_name>(m_arg_names, m_default_args);
  1401. #else
  1402. #define bind_convert_methodv(m_type_from, m_type_to, m_name, m_method, m_arg_names, m_default_args) \
  1403. CONVERT_METHOD_CLASS(m_type_from, m_name, m_method); \
  1404. register_builtin_method<Method_##m_type_from##_##m_name>(sarray(), m_default_args);
  1405. #endif
  1406. #ifdef DEBUG_METHODS_ENABLED
  1407. #define bind_function(m_type, m_name, m_method, m_arg_names, m_default_args) \
  1408. FUNCTION_CLASS(m_type, m_name, m_method, true); \
  1409. register_builtin_method<Method_##m_type##_##m_name>(m_arg_names, m_default_args);
  1410. #else
  1411. #define bind_function(m_type, m_name, m_method, m_arg_names, m_default_args) \
  1412. FUNCTION_CLASS(m_type, m_name, m_method, true); \
  1413. register_builtin_method<Method_##m_type##_##m_name>(sarray(), m_default_args);
  1414. #endif
  1415. #ifdef DEBUG_METHODS_ENABLED
  1416. #define bind_functionnc(m_type, m_name, m_method, m_arg_names, m_default_args) \
  1417. FUNCTION_CLASS(m_type, m_name, m_method, false); \
  1418. register_builtin_method<Method_##m_type##_##m_name>(m_arg_names, m_default_args);
  1419. #else
  1420. #define bind_functionnc(m_type, m_name, m_method, m_arg_names, m_default_args) \
  1421. FUNCTION_CLASS(m_type, m_name, m_method, false); \
  1422. register_builtin_method<Method_##m_type##_##m_name>(sarray(), m_default_args);
  1423. #endif
  1424. #define bind_string_method(m_method, m_arg_names, m_default_args) \
  1425. bind_method(String, m_method, m_arg_names, m_default_args); \
  1426. bind_convert_method(StringName, String, m_method, m_arg_names, m_default_args);
  1427. #define bind_string_methodv(m_name, m_method, m_arg_names, m_default_args) \
  1428. bind_methodv(String, m_name, m_method, m_arg_names, m_default_args); \
  1429. bind_convert_methodv(StringName, String, m_name, m_method, m_arg_names, m_default_args);
  1430. #define bind_custom(m_type, m_name, m_method, m_has_return, m_ret_type) \
  1431. VARARG_CLASS(m_type, m_name, m_method, m_has_return, m_ret_type) \
  1432. register_builtin_method<Method_##m_type##_##m_name>(sarray(), Vector<Variant>());
  1433. #define bind_custom1(m_type, m_name, m_method, m_arg_type, m_arg_name) \
  1434. VARARG_CLASS1(m_type, m_name, m_method, m_arg_type) \
  1435. register_builtin_method<Method_##m_type##_##m_name>(sarray(m_arg_name), Vector<Variant>());
  1436. static void _register_variant_builtin_methods_string() {
  1437. _VariantCall::constant_data = memnew_arr(_VariantCall::ConstantData, Variant::VARIANT_MAX);
  1438. _VariantCall::enum_data = memnew_arr(_VariantCall::EnumData, Variant::VARIANT_MAX);
  1439. builtin_method_info = memnew_arr(BuiltinMethodMap, Variant::VARIANT_MAX);
  1440. builtin_method_names = memnew_arr(List<StringName>, Variant::VARIANT_MAX);
  1441. /* String */
  1442. bind_string_method(casecmp_to, sarray("to"), varray());
  1443. bind_string_method(nocasecmp_to, sarray("to"), varray());
  1444. bind_string_method(naturalcasecmp_to, sarray("to"), varray());
  1445. bind_string_method(naturalnocasecmp_to, sarray("to"), varray());
  1446. bind_string_method(filecasecmp_to, sarray("to"), varray());
  1447. bind_string_method(filenocasecmp_to, sarray("to"), varray());
  1448. bind_string_method(length, sarray(), varray());
  1449. bind_string_method(substr, sarray("from", "len"), varray(-1));
  1450. bind_string_methodv(get_slice, static_cast<String (String::*)(const String &, int) const>(&String::get_slice), sarray("delimiter", "slice"), varray());
  1451. bind_string_method(get_slicec, sarray("delimiter", "slice"), varray());
  1452. bind_string_methodv(get_slice_count, static_cast<int (String::*)(const String &) const>(&String::get_slice_count), sarray("delimiter"), varray());
  1453. bind_string_methodv(find, static_cast<int (String::*)(const String &, int) const>(&String::find), sarray("what", "from"), varray(0));
  1454. bind_string_methodv(findn, static_cast<int (String::*)(const String &, int) const>(&String::findn), sarray("what", "from"), varray(0));
  1455. bind_string_methodv(count, static_cast<int (String::*)(const String &, int, int) const>(&String::count), sarray("what", "from", "to"), varray(0, 0));
  1456. bind_string_methodv(countn, static_cast<int (String::*)(const String &, int, int) const>(&String::countn), sarray("what", "from", "to"), varray(0, 0));
  1457. bind_string_methodv(rfind, static_cast<int (String::*)(const String &, int) const>(&String::rfind), sarray("what", "from"), varray(-1));
  1458. bind_string_methodv(rfindn, static_cast<int (String::*)(const String &, int) const>(&String::rfindn), sarray("what", "from"), varray(-1));
  1459. bind_string_method(match, sarray("expr"), varray());
  1460. bind_string_method(matchn, sarray("expr"), varray());
  1461. bind_string_methodv(begins_with, static_cast<bool (String::*)(const String &) const>(&String::begins_with), sarray("text"), varray());
  1462. bind_string_methodv(ends_with, static_cast<bool (String::*)(const String &) const>(&String::ends_with), sarray("text"), varray());
  1463. bind_string_method(is_subsequence_of, sarray("text"), varray());
  1464. bind_string_method(is_subsequence_ofn, sarray("text"), varray());
  1465. bind_string_method(bigrams, sarray(), varray());
  1466. bind_string_method(similarity, sarray("text"), varray());
  1467. bind_string_method(format, sarray("values", "placeholder"), varray("{_}"));
  1468. bind_string_methodv(replace, static_cast<String (String::*)(const String &, const String &) const>(&String::replace), sarray("what", "forwhat"), varray());
  1469. bind_string_methodv(replacen, static_cast<String (String::*)(const String &, const String &) const>(&String::replacen), sarray("what", "forwhat"), varray());
  1470. bind_string_method(repeat, sarray("count"), varray());
  1471. bind_string_method(reverse, sarray(), varray());
  1472. bind_string_method(insert, sarray("position", "what"), varray());
  1473. bind_string_method(erase, sarray("position", "chars"), varray(1));
  1474. bind_string_method(capitalize, sarray(), varray());
  1475. bind_string_method(to_camel_case, sarray(), varray());
  1476. bind_string_method(to_pascal_case, sarray(), varray());
  1477. bind_string_method(to_snake_case, sarray(), varray());
  1478. bind_string_methodv(split, static_cast<Vector<String> (String::*)(const String &, bool, int) const>(&String::split), sarray("delimiter", "allow_empty", "maxsplit"), varray("", true, 0));
  1479. bind_string_methodv(rsplit, static_cast<Vector<String> (String::*)(const String &, bool, int) const>(&String::rsplit), sarray("delimiter", "allow_empty", "maxsplit"), varray("", true, 0));
  1480. bind_string_method(split_floats, sarray("delimiter", "allow_empty"), varray(true));
  1481. bind_string_method(join, sarray("parts"), varray());
  1482. bind_string_method(to_upper, sarray(), varray());
  1483. bind_string_method(to_lower, sarray(), varray());
  1484. bind_string_method(left, sarray("length"), varray());
  1485. bind_string_method(right, sarray("length"), varray());
  1486. bind_string_method(strip_edges, sarray("left", "right"), varray(true, true));
  1487. bind_string_method(strip_escapes, sarray(), varray());
  1488. bind_string_method(lstrip, sarray("chars"), varray());
  1489. bind_string_method(rstrip, sarray("chars"), varray());
  1490. bind_string_method(get_extension, sarray(), varray());
  1491. bind_string_method(get_basename, sarray(), varray());
  1492. bind_string_method(path_join, sarray("file"), varray());
  1493. bind_string_method(unicode_at, sarray("at"), varray());
  1494. bind_string_method(indent, sarray("prefix"), varray());
  1495. bind_string_method(dedent, sarray(), varray());
  1496. bind_method(String, hash, sarray(), varray());
  1497. bind_string_method(md5_text, sarray(), varray());
  1498. bind_string_method(sha1_text, sarray(), varray());
  1499. bind_string_method(sha256_text, sarray(), varray());
  1500. bind_string_method(md5_buffer, sarray(), varray());
  1501. bind_string_method(sha1_buffer, sarray(), varray());
  1502. bind_string_method(sha256_buffer, sarray(), varray());
  1503. bind_string_method(is_empty, sarray(), varray());
  1504. bind_string_methodv(contains, static_cast<bool (String::*)(const String &) const>(&String::contains), sarray("what"), varray());
  1505. bind_string_methodv(containsn, static_cast<bool (String::*)(const String &) const>(&String::containsn), sarray("what"), varray());
  1506. bind_string_method(is_absolute_path, sarray(), varray());
  1507. bind_string_method(is_relative_path, sarray(), varray());
  1508. bind_string_method(simplify_path, sarray(), varray());
  1509. bind_string_method(get_base_dir, sarray(), varray());
  1510. bind_string_method(get_file, sarray(), varray());
  1511. bind_string_method(xml_escape, sarray("escape_quotes"), varray(false));
  1512. bind_string_method(xml_unescape, sarray(), varray());
  1513. bind_string_method(uri_encode, sarray(), varray());
  1514. bind_string_method(uri_decode, sarray(), varray());
  1515. bind_string_method(c_escape, sarray(), varray());
  1516. bind_string_method(c_unescape, sarray(), varray());
  1517. bind_string_method(json_escape, sarray(), varray());
  1518. bind_string_method(validate_node_name, sarray(), varray());
  1519. bind_string_method(validate_filename, sarray(), varray());
  1520. bind_string_method(is_valid_ascii_identifier, sarray(), varray());
  1521. bind_string_method(is_valid_unicode_identifier, sarray(), varray());
  1522. bind_string_method(is_valid_identifier, sarray(), varray());
  1523. bind_string_method(is_valid_int, sarray(), varray());
  1524. bind_string_method(is_valid_float, sarray(), varray());
  1525. bind_string_method(is_valid_hex_number, sarray("with_prefix"), varray(false));
  1526. bind_string_method(is_valid_html_color, sarray(), varray());
  1527. bind_string_method(is_valid_ip_address, sarray(), varray());
  1528. bind_string_method(is_valid_filename, sarray(), varray());
  1529. bind_string_method(to_int, sarray(), varray());
  1530. bind_string_method(to_float, sarray(), varray());
  1531. bind_string_method(hex_to_int, sarray(), varray());
  1532. bind_string_method(bin_to_int, sarray(), varray());
  1533. bind_string_method(lpad, sarray("min_length", "character"), varray(" "));
  1534. bind_string_method(rpad, sarray("min_length", "character"), varray(" "));
  1535. bind_string_method(pad_decimals, sarray("digits"), varray());
  1536. bind_string_method(pad_zeros, sarray("digits"), varray());
  1537. bind_string_methodv(trim_prefix, static_cast<String (String::*)(const String &) const>(&String::trim_prefix), sarray("prefix"), varray());
  1538. bind_string_methodv(trim_suffix, static_cast<String (String::*)(const String &) const>(&String::trim_suffix), sarray("suffix"), varray());
  1539. bind_string_method(to_ascii_buffer, sarray(), varray());
  1540. bind_string_method(to_utf8_buffer, sarray(), varray());
  1541. bind_string_method(to_utf16_buffer, sarray(), varray());
  1542. bind_string_method(to_utf32_buffer, sarray(), varray());
  1543. bind_string_method(hex_decode, sarray(), varray());
  1544. bind_string_method(to_wchar_buffer, sarray(), varray());
  1545. bind_static_method(String, num_scientific, sarray("number"), varray());
  1546. bind_static_method(String, num, sarray("number", "decimals"), varray(-1));
  1547. bind_static_method(String, num_int64, sarray("number", "base", "capitalize_hex"), varray(10, false));
  1548. bind_static_method(String, num_uint64, sarray("number", "base", "capitalize_hex"), varray(10, false));
  1549. bind_static_method(String, chr, sarray("char"), varray());
  1550. bind_static_method(String, humanize_size, sarray("size"), varray());
  1551. /* StringName */
  1552. bind_method(StringName, hash, sarray(), varray());
  1553. }
  1554. static void _register_variant_builtin_methods_math() {
  1555. /* Vector2 */
  1556. bind_method(Vector2, angle, sarray(), varray());
  1557. bind_method(Vector2, angle_to, sarray("to"), varray());
  1558. bind_method(Vector2, angle_to_point, sarray("to"), varray());
  1559. bind_method(Vector2, direction_to, sarray("to"), varray());
  1560. bind_method(Vector2, distance_to, sarray("to"), varray());
  1561. bind_method(Vector2, distance_squared_to, sarray("to"), varray());
  1562. bind_method(Vector2, length, sarray(), varray());
  1563. bind_method(Vector2, length_squared, sarray(), varray());
  1564. bind_method(Vector2, limit_length, sarray("length"), varray(1.0));
  1565. bind_method(Vector2, normalized, sarray(), varray());
  1566. bind_method(Vector2, is_normalized, sarray(), varray());
  1567. bind_method(Vector2, is_equal_approx, sarray("to"), varray());
  1568. bind_method(Vector2, is_zero_approx, sarray(), varray());
  1569. bind_method(Vector2, is_finite, sarray(), varray());
  1570. bind_method(Vector2, posmod, sarray("mod"), varray());
  1571. bind_method(Vector2, posmodv, sarray("modv"), varray());
  1572. bind_method(Vector2, project, sarray("b"), varray());
  1573. bind_method(Vector2, lerp, sarray("to", "weight"), varray());
  1574. bind_method(Vector2, slerp, sarray("to", "weight"), varray());
  1575. bind_method(Vector2, cubic_interpolate, sarray("b", "pre_a", "post_b", "weight"), varray());
  1576. bind_method(Vector2, cubic_interpolate_in_time, sarray("b", "pre_a", "post_b", "weight", "b_t", "pre_a_t", "post_b_t"), varray());
  1577. bind_method(Vector2, bezier_interpolate, sarray("control_1", "control_2", "end", "t"), varray());
  1578. bind_method(Vector2, bezier_derivative, sarray("control_1", "control_2", "end", "t"), varray());
  1579. bind_method(Vector2, max_axis_index, sarray(), varray());
  1580. bind_method(Vector2, min_axis_index, sarray(), varray());
  1581. bind_method(Vector2, move_toward, sarray("to", "delta"), varray());
  1582. bind_method(Vector2, rotated, sarray("angle"), varray());
  1583. bind_method(Vector2, orthogonal, sarray(), varray());
  1584. bind_method(Vector2, floor, sarray(), varray());
  1585. bind_method(Vector2, ceil, sarray(), varray());
  1586. bind_method(Vector2, round, sarray(), varray());
  1587. bind_method(Vector2, aspect, sarray(), varray());
  1588. bind_method(Vector2, dot, sarray("with"), varray());
  1589. bind_method(Vector2, slide, sarray("n"), varray());
  1590. bind_method(Vector2, bounce, sarray("n"), varray());
  1591. bind_method(Vector2, reflect, sarray("line"), varray());
  1592. bind_method(Vector2, cross, sarray("with"), varray());
  1593. bind_method(Vector2, abs, sarray(), varray());
  1594. bind_method(Vector2, sign, sarray(), varray());
  1595. bind_method(Vector2, clamp, sarray("min", "max"), varray());
  1596. bind_method(Vector2, clampf, sarray("min", "max"), varray());
  1597. bind_method(Vector2, snapped, sarray("step"), varray());
  1598. bind_method(Vector2, snappedf, sarray("step"), varray());
  1599. bind_method(Vector2, min, sarray("with"), varray());
  1600. bind_method(Vector2, minf, sarray("with"), varray());
  1601. bind_method(Vector2, max, sarray("with"), varray());
  1602. bind_method(Vector2, maxf, sarray("with"), varray());
  1603. bind_static_method(Vector2, from_angle, sarray("angle"), varray());
  1604. /* Vector2i */
  1605. bind_method(Vector2i, aspect, sarray(), varray());
  1606. bind_method(Vector2i, max_axis_index, sarray(), varray());
  1607. bind_method(Vector2i, min_axis_index, sarray(), varray());
  1608. bind_method(Vector2i, distance_to, sarray("to"), varray());
  1609. bind_method(Vector2i, distance_squared_to, sarray("to"), varray());
  1610. bind_method(Vector2i, length, sarray(), varray());
  1611. bind_method(Vector2i, length_squared, sarray(), varray());
  1612. bind_method(Vector2i, sign, sarray(), varray());
  1613. bind_method(Vector2i, abs, sarray(), varray());
  1614. bind_method(Vector2i, clamp, sarray("min", "max"), varray());
  1615. bind_method(Vector2i, clampi, sarray("min", "max"), varray());
  1616. bind_method(Vector2i, snapped, sarray("step"), varray());
  1617. bind_method(Vector2i, snappedi, sarray("step"), varray());
  1618. bind_method(Vector2i, min, sarray("with"), varray());
  1619. bind_method(Vector2i, mini, sarray("with"), varray());
  1620. bind_method(Vector2i, max, sarray("with"), varray());
  1621. bind_method(Vector2i, maxi, sarray("with"), varray());
  1622. /* Rect2 */
  1623. bind_method(Rect2, get_center, sarray(), varray());
  1624. bind_method(Rect2, get_area, sarray(), varray());
  1625. bind_method(Rect2, has_area, sarray(), varray());
  1626. bind_method(Rect2, has_point, sarray("point"), varray());
  1627. bind_method(Rect2, is_equal_approx, sarray("rect"), varray());
  1628. bind_method(Rect2, is_finite, sarray(), varray());
  1629. bind_method(Rect2, intersects, sarray("b", "include_borders"), varray(false));
  1630. bind_method(Rect2, encloses, sarray("b"), varray());
  1631. bind_method(Rect2, intersection, sarray("b"), varray());
  1632. bind_method(Rect2, merge, sarray("b"), varray());
  1633. bind_method(Rect2, expand, sarray("to"), varray());
  1634. bind_method(Rect2, get_support, sarray("direction"), varray());
  1635. bind_method(Rect2, grow, sarray("amount"), varray());
  1636. bind_methodv(Rect2, grow_side, &Rect2::grow_side_bind, sarray("side", "amount"), varray());
  1637. bind_method(Rect2, grow_individual, sarray("left", "top", "right", "bottom"), varray());
  1638. bind_method(Rect2, abs, sarray(), varray());
  1639. /* Rect2i */
  1640. bind_method(Rect2i, get_center, sarray(), varray());
  1641. bind_method(Rect2i, get_area, sarray(), varray());
  1642. bind_method(Rect2i, has_area, sarray(), varray());
  1643. bind_method(Rect2i, has_point, sarray("point"), varray());
  1644. bind_method(Rect2i, intersects, sarray("b"), varray());
  1645. bind_method(Rect2i, encloses, sarray("b"), varray());
  1646. bind_method(Rect2i, intersection, sarray("b"), varray());
  1647. bind_method(Rect2i, merge, sarray("b"), varray());
  1648. bind_method(Rect2i, expand, sarray("to"), varray());
  1649. bind_method(Rect2i, grow, sarray("amount"), varray());
  1650. bind_methodv(Rect2i, grow_side, &Rect2i::grow_side_bind, sarray("side", "amount"), varray());
  1651. bind_method(Rect2i, grow_individual, sarray("left", "top", "right", "bottom"), varray());
  1652. bind_method(Rect2i, abs, sarray(), varray());
  1653. /* Vector3 */
  1654. bind_method(Vector3, min_axis_index, sarray(), varray());
  1655. bind_method(Vector3, max_axis_index, sarray(), varray());
  1656. bind_method(Vector3, angle_to, sarray("to"), varray());
  1657. bind_method(Vector3, signed_angle_to, sarray("to", "axis"), varray());
  1658. bind_method(Vector3, direction_to, sarray("to"), varray());
  1659. bind_method(Vector3, distance_to, sarray("to"), varray());
  1660. bind_method(Vector3, distance_squared_to, sarray("to"), varray());
  1661. bind_method(Vector3, length, sarray(), varray());
  1662. bind_method(Vector3, length_squared, sarray(), varray());
  1663. bind_method(Vector3, limit_length, sarray("length"), varray(1.0));
  1664. bind_method(Vector3, normalized, sarray(), varray());
  1665. bind_method(Vector3, is_normalized, sarray(), varray());
  1666. bind_method(Vector3, is_equal_approx, sarray("to"), varray());
  1667. bind_method(Vector3, is_zero_approx, sarray(), varray());
  1668. bind_method(Vector3, is_finite, sarray(), varray());
  1669. bind_method(Vector3, inverse, sarray(), varray());
  1670. bind_method(Vector3, clamp, sarray("min", "max"), varray());
  1671. bind_method(Vector3, clampf, sarray("min", "max"), varray());
  1672. bind_method(Vector3, snapped, sarray("step"), varray());
  1673. bind_method(Vector3, snappedf, sarray("step"), varray());
  1674. bind_method(Vector3, rotated, sarray("axis", "angle"), varray());
  1675. bind_method(Vector3, lerp, sarray("to", "weight"), varray());
  1676. bind_method(Vector3, slerp, sarray("to", "weight"), varray());
  1677. bind_method(Vector3, cubic_interpolate, sarray("b", "pre_a", "post_b", "weight"), varray());
  1678. bind_method(Vector3, cubic_interpolate_in_time, sarray("b", "pre_a", "post_b", "weight", "b_t", "pre_a_t", "post_b_t"), varray());
  1679. bind_method(Vector3, bezier_interpolate, sarray("control_1", "control_2", "end", "t"), varray());
  1680. bind_method(Vector3, bezier_derivative, sarray("control_1", "control_2", "end", "t"), varray());
  1681. bind_method(Vector3, move_toward, sarray("to", "delta"), varray());
  1682. bind_method(Vector3, dot, sarray("with"), varray());
  1683. bind_method(Vector3, cross, sarray("with"), varray());
  1684. bind_method(Vector3, outer, sarray("with"), varray());
  1685. bind_method(Vector3, abs, sarray(), varray());
  1686. bind_method(Vector3, floor, sarray(), varray());
  1687. bind_method(Vector3, ceil, sarray(), varray());
  1688. bind_method(Vector3, round, sarray(), varray());
  1689. bind_method(Vector3, posmod, sarray("mod"), varray());
  1690. bind_method(Vector3, posmodv, sarray("modv"), varray());
  1691. bind_method(Vector3, project, sarray("b"), varray());
  1692. bind_method(Vector3, slide, sarray("n"), varray());
  1693. bind_method(Vector3, bounce, sarray("n"), varray());
  1694. bind_method(Vector3, reflect, sarray("n"), varray());
  1695. bind_method(Vector3, sign, sarray(), varray());
  1696. bind_method(Vector3, octahedron_encode, sarray(), varray());
  1697. bind_method(Vector3, min, sarray("with"), varray());
  1698. bind_method(Vector3, minf, sarray("with"), varray());
  1699. bind_method(Vector3, max, sarray("with"), varray());
  1700. bind_method(Vector3, maxf, sarray("with"), varray());
  1701. bind_static_method(Vector3, octahedron_decode, sarray("uv"), varray());
  1702. /* Vector3i */
  1703. bind_method(Vector3i, min_axis_index, sarray(), varray());
  1704. bind_method(Vector3i, max_axis_index, sarray(), varray());
  1705. bind_method(Vector3i, distance_to, sarray("to"), varray());
  1706. bind_method(Vector3i, distance_squared_to, sarray("to"), varray());
  1707. bind_method(Vector3i, length, sarray(), varray());
  1708. bind_method(Vector3i, length_squared, sarray(), varray());
  1709. bind_method(Vector3i, sign, sarray(), varray());
  1710. bind_method(Vector3i, abs, sarray(), varray());
  1711. bind_method(Vector3i, clamp, sarray("min", "max"), varray());
  1712. bind_method(Vector3i, clampi, sarray("min", "max"), varray());
  1713. bind_method(Vector3i, snapped, sarray("step"), varray());
  1714. bind_method(Vector3i, snappedi, sarray("step"), varray());
  1715. bind_method(Vector3i, min, sarray("with"), varray());
  1716. bind_method(Vector3i, mini, sarray("with"), varray());
  1717. bind_method(Vector3i, max, sarray("with"), varray());
  1718. bind_method(Vector3i, maxi, sarray("with"), varray());
  1719. /* Vector4 */
  1720. bind_method(Vector4, min_axis_index, sarray(), varray());
  1721. bind_method(Vector4, max_axis_index, sarray(), varray());
  1722. bind_method(Vector4, length, sarray(), varray());
  1723. bind_method(Vector4, length_squared, sarray(), varray());
  1724. bind_method(Vector4, abs, sarray(), varray());
  1725. bind_method(Vector4, sign, sarray(), varray());
  1726. bind_method(Vector4, floor, sarray(), varray());
  1727. bind_method(Vector4, ceil, sarray(), varray());
  1728. bind_method(Vector4, round, sarray(), varray());
  1729. bind_method(Vector4, lerp, sarray("to", "weight"), varray());
  1730. bind_method(Vector4, cubic_interpolate, sarray("b", "pre_a", "post_b", "weight"), varray());
  1731. bind_method(Vector4, cubic_interpolate_in_time, sarray("b", "pre_a", "post_b", "weight", "b_t", "pre_a_t", "post_b_t"), varray());
  1732. bind_method(Vector4, posmod, sarray("mod"), varray());
  1733. bind_method(Vector4, posmodv, sarray("modv"), varray());
  1734. bind_method(Vector4, snapped, sarray("step"), varray());
  1735. bind_method(Vector4, snappedf, sarray("step"), varray());
  1736. bind_method(Vector4, clamp, sarray("min", "max"), varray());
  1737. bind_method(Vector4, clampf, sarray("min", "max"), varray());
  1738. bind_method(Vector4, normalized, sarray(), varray());
  1739. bind_method(Vector4, is_normalized, sarray(), varray());
  1740. bind_method(Vector4, direction_to, sarray("to"), varray());
  1741. bind_method(Vector4, distance_to, sarray("to"), varray());
  1742. bind_method(Vector4, distance_squared_to, sarray("to"), varray());
  1743. bind_method(Vector4, dot, sarray("with"), varray());
  1744. bind_method(Vector4, inverse, sarray(), varray());
  1745. bind_method(Vector4, is_equal_approx, sarray("to"), varray());
  1746. bind_method(Vector4, is_zero_approx, sarray(), varray());
  1747. bind_method(Vector4, is_finite, sarray(), varray());
  1748. bind_method(Vector4, min, sarray("with"), varray());
  1749. bind_method(Vector4, minf, sarray("with"), varray());
  1750. bind_method(Vector4, max, sarray("with"), varray());
  1751. bind_method(Vector4, maxf, sarray("with"), varray());
  1752. /* Vector4i */
  1753. bind_method(Vector4i, min_axis_index, sarray(), varray());
  1754. bind_method(Vector4i, max_axis_index, sarray(), varray());
  1755. bind_method(Vector4i, length, sarray(), varray());
  1756. bind_method(Vector4i, length_squared, sarray(), varray());
  1757. bind_method(Vector4i, sign, sarray(), varray());
  1758. bind_method(Vector4i, abs, sarray(), varray());
  1759. bind_method(Vector4i, clamp, sarray("min", "max"), varray());
  1760. bind_method(Vector4i, clampi, sarray("min", "max"), varray());
  1761. bind_method(Vector4i, snapped, sarray("step"), varray());
  1762. bind_method(Vector4i, snappedi, sarray("step"), varray());
  1763. bind_method(Vector4i, min, sarray("with"), varray());
  1764. bind_method(Vector4i, mini, sarray("with"), varray());
  1765. bind_method(Vector4i, max, sarray("with"), varray());
  1766. bind_method(Vector4i, maxi, sarray("with"), varray());
  1767. bind_method(Vector4i, distance_to, sarray("to"), varray());
  1768. bind_method(Vector4i, distance_squared_to, sarray("to"), varray());
  1769. /* Plane */
  1770. bind_method(Plane, normalized, sarray(), varray());
  1771. bind_method(Plane, get_center, sarray(), varray());
  1772. bind_method(Plane, is_equal_approx, sarray("to_plane"), varray());
  1773. bind_method(Plane, is_finite, sarray(), varray());
  1774. bind_method(Plane, is_point_over, sarray("point"), varray());
  1775. bind_method(Plane, distance_to, sarray("point"), varray());
  1776. bind_method(Plane, has_point, sarray("point", "tolerance"), varray(CMP_EPSILON));
  1777. bind_method(Plane, project, sarray("point"), varray());
  1778. bind_methodv(Plane, intersect_3, &Plane::intersect_3_bind, sarray("b", "c"), varray());
  1779. bind_methodv(Plane, intersects_ray, &Plane::intersects_ray_bind, sarray("from", "dir"), varray());
  1780. bind_methodv(Plane, intersects_segment, &Plane::intersects_segment_bind, sarray("from", "to"), varray());
  1781. /* Quaternion */
  1782. bind_method(Quaternion, length, sarray(), varray());
  1783. bind_method(Quaternion, length_squared, sarray(), varray());
  1784. bind_method(Quaternion, normalized, sarray(), varray());
  1785. bind_method(Quaternion, is_normalized, sarray(), varray());
  1786. bind_method(Quaternion, is_equal_approx, sarray("to"), varray());
  1787. bind_method(Quaternion, is_finite, sarray(), varray());
  1788. bind_method(Quaternion, inverse, sarray(), varray());
  1789. bind_method(Quaternion, log, sarray(), varray());
  1790. bind_method(Quaternion, exp, sarray(), varray());
  1791. bind_method(Quaternion, angle_to, sarray("to"), varray());
  1792. bind_method(Quaternion, dot, sarray("with"), varray());
  1793. bind_method(Quaternion, slerp, sarray("to", "weight"), varray());
  1794. bind_method(Quaternion, slerpni, sarray("to", "weight"), varray());
  1795. bind_method(Quaternion, spherical_cubic_interpolate, sarray("b", "pre_a", "post_b", "weight"), varray());
  1796. bind_method(Quaternion, spherical_cubic_interpolate_in_time, sarray("b", "pre_a", "post_b", "weight", "b_t", "pre_a_t", "post_b_t"), varray());
  1797. bind_method(Quaternion, get_euler, sarray("order"), varray((int64_t)EulerOrder::YXZ));
  1798. bind_static_method(Quaternion, from_euler, sarray("euler"), varray());
  1799. bind_method(Quaternion, get_axis, sarray(), varray());
  1800. bind_method(Quaternion, get_angle, sarray(), varray());
  1801. /* Color */
  1802. bind_method(Color, to_argb32, sarray(), varray());
  1803. bind_method(Color, to_abgr32, sarray(), varray());
  1804. bind_method(Color, to_rgba32, sarray(), varray());
  1805. bind_method(Color, to_argb64, sarray(), varray());
  1806. bind_method(Color, to_abgr64, sarray(), varray());
  1807. bind_method(Color, to_rgba64, sarray(), varray());
  1808. bind_method(Color, to_html, sarray("with_alpha"), varray(true));
  1809. bind_method(Color, clamp, sarray("min", "max"), varray(Color(0, 0, 0, 0), Color(1, 1, 1, 1)));
  1810. bind_method(Color, inverted, sarray(), varray());
  1811. bind_method(Color, lerp, sarray("to", "weight"), varray());
  1812. bind_method(Color, lightened, sarray("amount"), varray());
  1813. bind_method(Color, darkened, sarray("amount"), varray());
  1814. bind_method(Color, blend, sarray("over"), varray());
  1815. bind_method(Color, get_luminance, sarray(), varray());
  1816. bind_method(Color, srgb_to_linear, sarray(), varray());
  1817. bind_method(Color, linear_to_srgb, sarray(), varray());
  1818. bind_method(Color, is_equal_approx, sarray("to"), varray());
  1819. bind_static_method(Color, hex, sarray("hex"), varray());
  1820. bind_static_method(Color, hex64, sarray("hex"), varray());
  1821. bind_static_method(Color, html, sarray("rgba"), varray());
  1822. bind_static_method(Color, html_is_valid, sarray("color"), varray());
  1823. bind_static_method(Color, from_string, sarray("str", "default"), varray());
  1824. bind_static_method(Color, from_hsv, sarray("h", "s", "v", "alpha"), varray(1.0));
  1825. bind_static_method(Color, from_ok_hsl, sarray("h", "s", "l", "alpha"), varray(1.0));
  1826. bind_static_method(Color, from_rgbe9995, sarray("rgbe"), varray());
  1827. }
  1828. static void _register_variant_builtin_methods_misc() {
  1829. /* RID */
  1830. bind_method(RID, is_valid, sarray(), varray());
  1831. bind_method(RID, get_id, sarray(), varray());
  1832. /* NodePath */
  1833. bind_method(NodePath, is_absolute, sarray(), varray());
  1834. bind_method(NodePath, get_name_count, sarray(), varray());
  1835. bind_method(NodePath, get_name, sarray("idx"), varray());
  1836. bind_method(NodePath, get_subname_count, sarray(), varray());
  1837. bind_method(NodePath, hash, sarray(), varray());
  1838. bind_method(NodePath, get_subname, sarray("idx"), varray());
  1839. bind_method(NodePath, get_concatenated_names, sarray(), varray());
  1840. bind_method(NodePath, get_concatenated_subnames, sarray(), varray());
  1841. bind_method(NodePath, slice, sarray("begin", "end"), varray(INT_MAX));
  1842. bind_method(NodePath, get_as_property_path, sarray(), varray());
  1843. bind_method(NodePath, is_empty, sarray(), varray());
  1844. /* Callable */
  1845. bind_static_method(Callable, create, sarray("variant", "method"), varray());
  1846. bind_method(Callable, callv, sarray("arguments"), varray());
  1847. bind_method(Callable, is_null, sarray(), varray());
  1848. bind_method(Callable, is_custom, sarray(), varray());
  1849. bind_method(Callable, is_standard, sarray(), varray());
  1850. bind_method(Callable, is_valid, sarray(), varray());
  1851. bind_method(Callable, get_object, sarray(), varray());
  1852. bind_method(Callable, get_object_id, sarray(), varray());
  1853. bind_method(Callable, get_method, sarray(), varray());
  1854. bind_function(Callable, get_argument_count, _VariantCall::func_Callable_get_argument_count, sarray(), varray());
  1855. bind_method(Callable, get_bound_arguments_count, sarray(), varray());
  1856. bind_method(Callable, get_bound_arguments, sarray(), varray());
  1857. bind_method(Callable, get_unbound_arguments_count, sarray(), varray());
  1858. bind_method(Callable, hash, sarray(), varray());
  1859. bind_method(Callable, bindv, sarray("arguments"), varray());
  1860. bind_method(Callable, unbind, sarray("argcount"), varray());
  1861. bind_custom(Callable, call, _VariantCall::func_Callable_call, true, Variant);
  1862. bind_custom(Callable, call_deferred, _VariantCall::func_Callable_call_deferred, false, Variant);
  1863. bind_custom(Callable, rpc, _VariantCall::func_Callable_rpc, false, Variant);
  1864. bind_custom1(Callable, rpc_id, _VariantCall::func_Callable_rpc_id, Variant::INT, "peer_id");
  1865. bind_custom(Callable, bind, _VariantCall::func_Callable_bind, true, Callable);
  1866. /* Signal */
  1867. bind_method(Signal, is_null, sarray(), varray());
  1868. bind_method(Signal, get_object, sarray(), varray());
  1869. bind_method(Signal, get_object_id, sarray(), varray());
  1870. bind_method(Signal, get_name, sarray(), varray());
  1871. bind_method(Signal, connect, sarray("callable", "flags"), varray(0));
  1872. bind_method(Signal, disconnect, sarray("callable"), varray());
  1873. bind_method(Signal, is_connected, sarray("callable"), varray());
  1874. bind_method(Signal, get_connections, sarray(), varray());
  1875. bind_method(Signal, has_connections, sarray(), varray());
  1876. bind_custom(Signal, emit, _VariantCall::func_Signal_emit, false, Variant);
  1877. /* Transform2D */
  1878. bind_method(Transform2D, inverse, sarray(), varray());
  1879. bind_method(Transform2D, affine_inverse, sarray(), varray());
  1880. bind_method(Transform2D, get_rotation, sarray(), varray());
  1881. bind_method(Transform2D, get_origin, sarray(), varray());
  1882. bind_method(Transform2D, get_scale, sarray(), varray());
  1883. bind_method(Transform2D, get_skew, sarray(), varray());
  1884. bind_method(Transform2D, orthonormalized, sarray(), varray());
  1885. bind_method(Transform2D, rotated, sarray("angle"), varray());
  1886. bind_method(Transform2D, rotated_local, sarray("angle"), varray());
  1887. bind_method(Transform2D, scaled, sarray("scale"), varray());
  1888. bind_method(Transform2D, scaled_local, sarray("scale"), varray());
  1889. bind_method(Transform2D, translated, sarray("offset"), varray());
  1890. bind_method(Transform2D, translated_local, sarray("offset"), varray());
  1891. bind_method(Transform2D, determinant, sarray(), varray());
  1892. bind_method(Transform2D, basis_xform, sarray("v"), varray());
  1893. bind_method(Transform2D, basis_xform_inv, sarray("v"), varray());
  1894. bind_method(Transform2D, interpolate_with, sarray("xform", "weight"), varray());
  1895. bind_method(Transform2D, is_conformal, sarray(), varray());
  1896. bind_method(Transform2D, is_equal_approx, sarray("xform"), varray());
  1897. bind_method(Transform2D, is_finite, sarray(), varray());
  1898. // Do not bind functions like set_rotation, set_scale, set_skew, etc because this type is immutable and can't be modified.
  1899. bind_method(Transform2D, looking_at, sarray("target"), varray(Vector2()));
  1900. /* Basis */
  1901. bind_method(Basis, inverse, sarray(), varray());
  1902. bind_method(Basis, transposed, sarray(), varray());
  1903. bind_method(Basis, orthonormalized, sarray(), varray());
  1904. bind_method(Basis, determinant, sarray(), varray());
  1905. bind_methodv(Basis, rotated, static_cast<Basis (Basis::*)(const Vector3 &, real_t) const>(&Basis::rotated), sarray("axis", "angle"), varray());
  1906. bind_method(Basis, scaled, sarray("scale"), varray());
  1907. bind_method(Basis, get_scale, sarray(), varray());
  1908. bind_method(Basis, get_euler, sarray("order"), varray((int64_t)EulerOrder::YXZ));
  1909. bind_method(Basis, tdotx, sarray("with"), varray());
  1910. bind_method(Basis, tdoty, sarray("with"), varray());
  1911. bind_method(Basis, tdotz, sarray("with"), varray());
  1912. bind_method(Basis, slerp, sarray("to", "weight"), varray());
  1913. bind_method(Basis, is_conformal, sarray(), varray());
  1914. bind_method(Basis, is_equal_approx, sarray("b"), varray());
  1915. bind_method(Basis, is_finite, sarray(), varray());
  1916. bind_method(Basis, get_rotation_quaternion, sarray(), varray());
  1917. bind_static_method(Basis, looking_at, sarray("target", "up", "use_model_front"), varray(Vector3(0, 1, 0), false));
  1918. bind_static_method(Basis, from_scale, sarray("scale"), varray());
  1919. bind_static_method(Basis, from_euler, sarray("euler", "order"), varray((int64_t)EulerOrder::YXZ));
  1920. /* AABB */
  1921. bind_method(AABB, abs, sarray(), varray());
  1922. bind_method(AABB, get_center, sarray(), varray());
  1923. bind_method(AABB, get_volume, sarray(), varray());
  1924. bind_method(AABB, has_volume, sarray(), varray());
  1925. bind_method(AABB, has_surface, sarray(), varray());
  1926. bind_method(AABB, has_point, sarray("point"), varray());
  1927. bind_method(AABB, is_equal_approx, sarray("aabb"), varray());
  1928. bind_method(AABB, is_finite, sarray(), varray());
  1929. bind_method(AABB, intersects, sarray("with"), varray());
  1930. bind_method(AABB, encloses, sarray("with"), varray());
  1931. bind_method(AABB, intersects_plane, sarray("plane"), varray());
  1932. bind_method(AABB, intersection, sarray("with"), varray());
  1933. bind_method(AABB, merge, sarray("with"), varray());
  1934. bind_method(AABB, expand, sarray("to_point"), varray());
  1935. bind_method(AABB, grow, sarray("by"), varray());
  1936. bind_method(AABB, get_support, sarray("direction"), varray());
  1937. bind_method(AABB, get_longest_axis, sarray(), varray());
  1938. bind_method(AABB, get_longest_axis_index, sarray(), varray());
  1939. bind_method(AABB, get_longest_axis_size, sarray(), varray());
  1940. bind_method(AABB, get_shortest_axis, sarray(), varray());
  1941. bind_method(AABB, get_shortest_axis_index, sarray(), varray());
  1942. bind_method(AABB, get_shortest_axis_size, sarray(), varray());
  1943. bind_method(AABB, get_endpoint, sarray("idx"), varray());
  1944. bind_methodv(AABB, intersects_segment, &AABB::intersects_segment_bind, sarray("from", "to"), varray());
  1945. bind_methodv(AABB, intersects_ray, &AABB::intersects_ray_bind, sarray("from", "dir"), varray());
  1946. /* Transform3D */
  1947. bind_method(Transform3D, inverse, sarray(), varray());
  1948. bind_method(Transform3D, affine_inverse, sarray(), varray());
  1949. bind_method(Transform3D, orthonormalized, sarray(), varray());
  1950. bind_method(Transform3D, rotated, sarray("axis", "angle"), varray());
  1951. bind_method(Transform3D, rotated_local, sarray("axis", "angle"), varray());
  1952. bind_method(Transform3D, scaled, sarray("scale"), varray());
  1953. bind_method(Transform3D, scaled_local, sarray("scale"), varray());
  1954. bind_method(Transform3D, translated, sarray("offset"), varray());
  1955. bind_method(Transform3D, translated_local, sarray("offset"), varray());
  1956. bind_method(Transform3D, looking_at, sarray("target", "up", "use_model_front"), varray(Vector3(0, 1, 0), false));
  1957. bind_method(Transform3D, interpolate_with, sarray("xform", "weight"), varray());
  1958. bind_method(Transform3D, is_equal_approx, sarray("xform"), varray());
  1959. bind_method(Transform3D, is_finite, sarray(), varray());
  1960. /* Projection */
  1961. bind_static_method(Projection, create_depth_correction, sarray("flip_y"), varray());
  1962. bind_static_method(Projection, create_light_atlas_rect, sarray("rect"), varray());
  1963. bind_static_method(Projection, create_perspective, sarray("fovy", "aspect", "z_near", "z_far", "flip_fov"), varray(false));
  1964. bind_static_method(Projection, create_perspective_hmd, sarray("fovy", "aspect", "z_near", "z_far", "flip_fov", "eye", "intraocular_dist", "convergence_dist"), varray());
  1965. bind_static_method(Projection, create_for_hmd, sarray("eye", "aspect", "intraocular_dist", "display_width", "display_to_lens", "oversample", "z_near", "z_far"), varray());
  1966. bind_static_method(Projection, create_orthogonal, sarray("left", "right", "bottom", "top", "z_near", "z_far"), varray());
  1967. bind_static_method(Projection, create_orthogonal_aspect, sarray("size", "aspect", "z_near", "z_far", "flip_fov"), varray(false));
  1968. bind_static_method(Projection, create_frustum, sarray("left", "right", "bottom", "top", "z_near", "z_far"), varray());
  1969. bind_static_method(Projection, create_frustum_aspect, sarray("size", "aspect", "offset", "z_near", "z_far", "flip_fov"), varray(false));
  1970. bind_static_method(Projection, create_fit_aabb, sarray("aabb"), varray());
  1971. bind_method(Projection, determinant, sarray(), varray());
  1972. bind_method(Projection, perspective_znear_adjusted, sarray("new_znear"), varray());
  1973. bind_method(Projection, get_projection_plane, sarray("plane"), varray());
  1974. bind_method(Projection, flipped_y, sarray(), varray());
  1975. bind_method(Projection, jitter_offseted, sarray("offset"), varray());
  1976. bind_static_method(Projection, get_fovy, sarray("fovx", "aspect"), varray());
  1977. bind_method(Projection, get_z_far, sarray(), varray());
  1978. bind_method(Projection, get_z_near, sarray(), varray());
  1979. bind_method(Projection, get_aspect, sarray(), varray());
  1980. bind_method(Projection, get_fov, sarray(), varray());
  1981. bind_method(Projection, is_orthogonal, sarray(), varray());
  1982. bind_method(Projection, get_viewport_half_extents, sarray(), varray());
  1983. bind_method(Projection, get_far_plane_half_extents, sarray(), varray());
  1984. bind_method(Projection, inverse, sarray(), varray());
  1985. bind_method(Projection, get_pixels_per_meter, sarray("for_pixel_width"), varray());
  1986. bind_method(Projection, get_lod_multiplier, sarray(), varray());
  1987. /* Dictionary */
  1988. bind_method(Dictionary, size, sarray(), varray());
  1989. bind_method(Dictionary, is_empty, sarray(), varray());
  1990. bind_method(Dictionary, clear, sarray(), varray());
  1991. bind_method(Dictionary, assign, sarray("dictionary"), varray());
  1992. bind_method(Dictionary, sort, sarray(), varray());
  1993. bind_method(Dictionary, merge, sarray("dictionary", "overwrite"), varray(false));
  1994. bind_method(Dictionary, merged, sarray("dictionary", "overwrite"), varray(false));
  1995. bind_method(Dictionary, has, sarray("key"), varray());
  1996. bind_method(Dictionary, has_all, sarray("keys"), varray());
  1997. bind_method(Dictionary, find_key, sarray("value"), varray());
  1998. bind_method(Dictionary, erase, sarray("key"), varray());
  1999. bind_method(Dictionary, hash, sarray(), varray());
  2000. bind_method(Dictionary, keys, sarray(), varray());
  2001. bind_method(Dictionary, values, sarray(), varray());
  2002. bind_method(Dictionary, duplicate, sarray("deep"), varray(false));
  2003. bind_method(Dictionary, get, sarray("key", "default"), varray(Variant()));
  2004. bind_method(Dictionary, get_or_add, sarray("key", "default"), varray(Variant()));
  2005. bind_method(Dictionary, set, sarray("key", "value"), varray());
  2006. bind_method(Dictionary, is_typed, sarray(), varray());
  2007. bind_method(Dictionary, is_typed_key, sarray(), varray());
  2008. bind_method(Dictionary, is_typed_value, sarray(), varray());
  2009. bind_method(Dictionary, is_same_typed, sarray("dictionary"), varray());
  2010. bind_method(Dictionary, is_same_typed_key, sarray("dictionary"), varray());
  2011. bind_method(Dictionary, is_same_typed_value, sarray("dictionary"), varray());
  2012. bind_method(Dictionary, get_typed_key_builtin, sarray(), varray());
  2013. bind_method(Dictionary, get_typed_value_builtin, sarray(), varray());
  2014. bind_method(Dictionary, get_typed_key_class_name, sarray(), varray());
  2015. bind_method(Dictionary, get_typed_value_class_name, sarray(), varray());
  2016. bind_method(Dictionary, get_typed_key_script, sarray(), varray());
  2017. bind_method(Dictionary, get_typed_value_script, sarray(), varray());
  2018. bind_method(Dictionary, make_read_only, sarray(), varray());
  2019. bind_method(Dictionary, is_read_only, sarray(), varray());
  2020. bind_method(Dictionary, recursive_equal, sarray("dictionary", "recursion_count"), varray());
  2021. }
  2022. static void _register_variant_builtin_methods_array() {
  2023. /* Array */
  2024. bind_method(Array, size, sarray(), varray());
  2025. bind_method(Array, is_empty, sarray(), varray());
  2026. bind_method(Array, clear, sarray(), varray());
  2027. bind_method(Array, hash, sarray(), varray());
  2028. bind_method(Array, assign, sarray("array"), varray());
  2029. bind_method(Array, get, sarray("index"), varray());
  2030. bind_method(Array, set, sarray("index", "value"), varray());
  2031. bind_method(Array, push_back, sarray("value"), varray());
  2032. bind_method(Array, push_front, sarray("value"), varray());
  2033. bind_method(Array, append, sarray("value"), varray());
  2034. bind_method(Array, append_array, sarray("array"), varray());
  2035. bind_method(Array, resize, sarray("size"), varray());
  2036. bind_method(Array, insert, sarray("position", "value"), varray());
  2037. bind_method(Array, remove_at, sarray("position"), varray());
  2038. bind_method(Array, fill, sarray("value"), varray());
  2039. bind_method(Array, erase, sarray("value"), varray());
  2040. bind_method(Array, front, sarray(), varray());
  2041. bind_method(Array, back, sarray(), varray());
  2042. bind_method(Array, pick_random, sarray(), varray());
  2043. bind_method(Array, find, sarray("what", "from"), varray(0));
  2044. bind_method(Array, find_custom, sarray("method", "from"), varray(0));
  2045. bind_method(Array, rfind, sarray("what", "from"), varray(-1));
  2046. bind_method(Array, rfind_custom, sarray("method", "from"), varray(-1));
  2047. bind_method(Array, count, sarray("value"), varray());
  2048. bind_method(Array, has, sarray("value"), varray());
  2049. bind_method(Array, pop_back, sarray(), varray());
  2050. bind_method(Array, pop_front, sarray(), varray());
  2051. bind_method(Array, pop_at, sarray("position"), varray());
  2052. bind_method(Array, sort, sarray(), varray());
  2053. bind_method(Array, sort_custom, sarray("func"), varray());
  2054. bind_method(Array, shuffle, sarray(), varray());
  2055. bind_method(Array, bsearch, sarray("value", "before"), varray(true));
  2056. bind_method(Array, bsearch_custom, sarray("value", "func", "before"), varray(true));
  2057. bind_method(Array, reverse, sarray(), varray());
  2058. bind_method(Array, duplicate, sarray("deep"), varray(false));
  2059. bind_method(Array, slice, sarray("begin", "end", "step", "deep"), varray(INT_MAX, 1, false));
  2060. bind_method(Array, filter, sarray("method"), varray());
  2061. bind_method(Array, map, sarray("method"), varray());
  2062. bind_method(Array, reduce, sarray("method", "accum"), varray(Variant()));
  2063. bind_method(Array, any, sarray("method"), varray());
  2064. bind_method(Array, all, sarray("method"), varray());
  2065. bind_method(Array, max, sarray(), varray());
  2066. bind_method(Array, min, sarray(), varray());
  2067. bind_method(Array, is_typed, sarray(), varray());
  2068. bind_method(Array, is_same_typed, sarray("array"), varray());
  2069. bind_method(Array, get_typed_builtin, sarray(), varray());
  2070. bind_method(Array, get_typed_class_name, sarray(), varray());
  2071. bind_method(Array, get_typed_script, sarray(), varray());
  2072. bind_method(Array, make_read_only, sarray(), varray());
  2073. bind_method(Array, is_read_only, sarray(), varray());
  2074. /* Packed*Array get (see VARCALL_PACKED_GETTER macro) */
  2075. bind_function(PackedByteArray, get, _VariantCall::func_PackedByteArray_get, sarray("index"), varray());
  2076. bind_function(PackedColorArray, get, _VariantCall::func_PackedColorArray_get, sarray("index"), varray());
  2077. bind_function(PackedFloat32Array, get, _VariantCall::func_PackedFloat32Array_get, sarray("index"), varray());
  2078. bind_function(PackedFloat64Array, get, _VariantCall::func_PackedFloat64Array_get, sarray("index"), varray());
  2079. bind_function(PackedInt32Array, get, _VariantCall::func_PackedInt32Array_get, sarray("index"), varray());
  2080. bind_function(PackedInt64Array, get, _VariantCall::func_PackedInt64Array_get, sarray("index"), varray());
  2081. bind_function(PackedStringArray, get, _VariantCall::func_PackedStringArray_get, sarray("index"), varray());
  2082. bind_function(PackedVector2Array, get, _VariantCall::func_PackedVector2Array_get, sarray("index"), varray());
  2083. bind_function(PackedVector3Array, get, _VariantCall::func_PackedVector3Array_get, sarray("index"), varray());
  2084. bind_function(PackedVector4Array, get, _VariantCall::func_PackedVector4Array_get, sarray("index"), varray());
  2085. /* Byte Array */
  2086. bind_method(PackedByteArray, size, sarray(), varray());
  2087. bind_method(PackedByteArray, is_empty, sarray(), varray());
  2088. bind_method(PackedByteArray, set, sarray("index", "value"), varray());
  2089. bind_method(PackedByteArray, push_back, sarray("value"), varray());
  2090. bind_method(PackedByteArray, append, sarray("value"), varray());
  2091. bind_method(PackedByteArray, append_array, sarray("array"), varray());
  2092. bind_method(PackedByteArray, remove_at, sarray("index"), varray());
  2093. bind_method(PackedByteArray, insert, sarray("at_index", "value"), varray());
  2094. bind_method(PackedByteArray, fill, sarray("value"), varray());
  2095. bind_methodv(PackedByteArray, resize, &PackedByteArray::resize_zeroed, sarray("new_size"), varray());
  2096. bind_method(PackedByteArray, clear, sarray(), varray());
  2097. bind_method(PackedByteArray, has, sarray("value"), varray());
  2098. bind_method(PackedByteArray, reverse, sarray(), varray());
  2099. bind_method(PackedByteArray, slice, sarray("begin", "end"), varray(INT_MAX));
  2100. bind_method(PackedByteArray, sort, sarray(), varray());
  2101. bind_method(PackedByteArray, bsearch, sarray("value", "before"), varray(true));
  2102. bind_method(PackedByteArray, duplicate, sarray(), varray());
  2103. bind_method(PackedByteArray, find, sarray("value", "from"), varray(0));
  2104. bind_method(PackedByteArray, rfind, sarray("value", "from"), varray(-1));
  2105. bind_method(PackedByteArray, count, sarray("value"), varray());
  2106. bind_function(PackedByteArray, get_string_from_ascii, _VariantCall::func_PackedByteArray_get_string_from_ascii, sarray(), varray());
  2107. bind_function(PackedByteArray, get_string_from_utf8, _VariantCall::func_PackedByteArray_get_string_from_utf8, sarray(), varray());
  2108. bind_function(PackedByteArray, get_string_from_utf16, _VariantCall::func_PackedByteArray_get_string_from_utf16, sarray(), varray());
  2109. bind_function(PackedByteArray, get_string_from_utf32, _VariantCall::func_PackedByteArray_get_string_from_utf32, sarray(), varray());
  2110. bind_function(PackedByteArray, get_string_from_wchar, _VariantCall::func_PackedByteArray_get_string_from_wchar, sarray(), varray());
  2111. bind_function(PackedByteArray, hex_encode, _VariantCall::func_PackedByteArray_hex_encode, sarray(), varray());
  2112. bind_function(PackedByteArray, compress, _VariantCall::func_PackedByteArray_compress, sarray("compression_mode"), varray(0));
  2113. bind_function(PackedByteArray, decompress, _VariantCall::func_PackedByteArray_decompress, sarray("buffer_size", "compression_mode"), varray(0));
  2114. bind_function(PackedByteArray, decompress_dynamic, _VariantCall::func_PackedByteArray_decompress_dynamic, sarray("max_output_size", "compression_mode"), varray(0));
  2115. bind_function(PackedByteArray, decode_u8, _VariantCall::func_PackedByteArray_decode_u8, sarray("byte_offset"), varray());
  2116. bind_function(PackedByteArray, decode_s8, _VariantCall::func_PackedByteArray_decode_s8, sarray("byte_offset"), varray());
  2117. bind_function(PackedByteArray, decode_u16, _VariantCall::func_PackedByteArray_decode_u16, sarray("byte_offset"), varray());
  2118. bind_function(PackedByteArray, decode_s16, _VariantCall::func_PackedByteArray_decode_s16, sarray("byte_offset"), varray());
  2119. bind_function(PackedByteArray, decode_u32, _VariantCall::func_PackedByteArray_decode_u32, sarray("byte_offset"), varray());
  2120. bind_function(PackedByteArray, decode_s32, _VariantCall::func_PackedByteArray_decode_s32, sarray("byte_offset"), varray());
  2121. bind_function(PackedByteArray, decode_u64, _VariantCall::func_PackedByteArray_decode_u64, sarray("byte_offset"), varray());
  2122. bind_function(PackedByteArray, decode_s64, _VariantCall::func_PackedByteArray_decode_s64, sarray("byte_offset"), varray());
  2123. bind_function(PackedByteArray, decode_half, _VariantCall::func_PackedByteArray_decode_half, sarray("byte_offset"), varray());
  2124. bind_function(PackedByteArray, decode_float, _VariantCall::func_PackedByteArray_decode_float, sarray("byte_offset"), varray());
  2125. bind_function(PackedByteArray, decode_double, _VariantCall::func_PackedByteArray_decode_double, sarray("byte_offset"), varray());
  2126. bind_function(PackedByteArray, has_encoded_var, _VariantCall::func_PackedByteArray_has_encoded_var, sarray("byte_offset", "allow_objects"), varray(false));
  2127. bind_function(PackedByteArray, decode_var, _VariantCall::func_PackedByteArray_decode_var, sarray("byte_offset", "allow_objects"), varray(false));
  2128. bind_function(PackedByteArray, decode_var_size, _VariantCall::func_PackedByteArray_decode_var_size, sarray("byte_offset", "allow_objects"), varray(false));
  2129. bind_function(PackedByteArray, to_int32_array, _VariantCall::func_PackedByteArray_decode_s32_array, sarray(), varray());
  2130. bind_function(PackedByteArray, to_int64_array, _VariantCall::func_PackedByteArray_decode_s64_array, sarray(), varray());
  2131. bind_function(PackedByteArray, to_float32_array, _VariantCall::func_PackedByteArray_decode_float_array, sarray(), varray());
  2132. bind_function(PackedByteArray, to_float64_array, _VariantCall::func_PackedByteArray_decode_double_array, sarray(), varray());
  2133. bind_functionnc(PackedByteArray, encode_u8, _VariantCall::func_PackedByteArray_encode_u8, sarray("byte_offset", "value"), varray());
  2134. bind_functionnc(PackedByteArray, encode_s8, _VariantCall::func_PackedByteArray_encode_s8, sarray("byte_offset", "value"), varray());
  2135. bind_functionnc(PackedByteArray, encode_u16, _VariantCall::func_PackedByteArray_encode_u16, sarray("byte_offset", "value"), varray());
  2136. bind_functionnc(PackedByteArray, encode_s16, _VariantCall::func_PackedByteArray_encode_s16, sarray("byte_offset", "value"), varray());
  2137. bind_functionnc(PackedByteArray, encode_u32, _VariantCall::func_PackedByteArray_encode_u32, sarray("byte_offset", "value"), varray());
  2138. bind_functionnc(PackedByteArray, encode_s32, _VariantCall::func_PackedByteArray_encode_s32, sarray("byte_offset", "value"), varray());
  2139. bind_functionnc(PackedByteArray, encode_u64, _VariantCall::func_PackedByteArray_encode_u64, sarray("byte_offset", "value"), varray());
  2140. bind_functionnc(PackedByteArray, encode_s64, _VariantCall::func_PackedByteArray_encode_s64, sarray("byte_offset", "value"), varray());
  2141. bind_functionnc(PackedByteArray, encode_half, _VariantCall::func_PackedByteArray_encode_half, sarray("byte_offset", "value"), varray());
  2142. bind_functionnc(PackedByteArray, encode_float, _VariantCall::func_PackedByteArray_encode_float, sarray("byte_offset", "value"), varray());
  2143. bind_functionnc(PackedByteArray, encode_double, _VariantCall::func_PackedByteArray_encode_double, sarray("byte_offset", "value"), varray());
  2144. bind_functionnc(PackedByteArray, encode_var, _VariantCall::func_PackedByteArray_encode_var, sarray("byte_offset", "value", "allow_objects"), varray(false));
  2145. /* Int32 Array */
  2146. bind_method(PackedInt32Array, size, sarray(), varray());
  2147. bind_method(PackedInt32Array, is_empty, sarray(), varray());
  2148. bind_method(PackedInt32Array, set, sarray("index", "value"), varray());
  2149. bind_method(PackedInt32Array, push_back, sarray("value"), varray());
  2150. bind_method(PackedInt32Array, append, sarray("value"), varray());
  2151. bind_method(PackedInt32Array, append_array, sarray("array"), varray());
  2152. bind_method(PackedInt32Array, remove_at, sarray("index"), varray());
  2153. bind_method(PackedInt32Array, insert, sarray("at_index", "value"), varray());
  2154. bind_method(PackedInt32Array, fill, sarray("value"), varray());
  2155. bind_methodv(PackedInt32Array, resize, &PackedInt32Array::resize_zeroed, sarray("new_size"), varray());
  2156. bind_method(PackedInt32Array, clear, sarray(), varray());
  2157. bind_method(PackedInt32Array, has, sarray("value"), varray());
  2158. bind_method(PackedInt32Array, reverse, sarray(), varray());
  2159. bind_method(PackedInt32Array, slice, sarray("begin", "end"), varray(INT_MAX));
  2160. bind_method(PackedInt32Array, to_byte_array, sarray(), varray());
  2161. bind_method(PackedInt32Array, sort, sarray(), varray());
  2162. bind_method(PackedInt32Array, bsearch, sarray("value", "before"), varray(true));
  2163. bind_method(PackedInt32Array, duplicate, sarray(), varray());
  2164. bind_method(PackedInt32Array, find, sarray("value", "from"), varray(0));
  2165. bind_method(PackedInt32Array, rfind, sarray("value", "from"), varray(-1));
  2166. bind_method(PackedInt32Array, count, sarray("value"), varray());
  2167. /* Int64 Array */
  2168. bind_method(PackedInt64Array, size, sarray(), varray());
  2169. bind_method(PackedInt64Array, is_empty, sarray(), varray());
  2170. bind_method(PackedInt64Array, set, sarray("index", "value"), varray());
  2171. bind_method(PackedInt64Array, push_back, sarray("value"), varray());
  2172. bind_method(PackedInt64Array, append, sarray("value"), varray());
  2173. bind_method(PackedInt64Array, append_array, sarray("array"), varray());
  2174. bind_method(PackedInt64Array, remove_at, sarray("index"), varray());
  2175. bind_method(PackedInt64Array, insert, sarray("at_index", "value"), varray());
  2176. bind_method(PackedInt64Array, fill, sarray("value"), varray());
  2177. bind_methodv(PackedInt64Array, resize, &PackedInt64Array::resize_zeroed, sarray("new_size"), varray());
  2178. bind_method(PackedInt64Array, clear, sarray(), varray());
  2179. bind_method(PackedInt64Array, has, sarray("value"), varray());
  2180. bind_method(PackedInt64Array, reverse, sarray(), varray());
  2181. bind_method(PackedInt64Array, slice, sarray("begin", "end"), varray(INT_MAX));
  2182. bind_method(PackedInt64Array, to_byte_array, sarray(), varray());
  2183. bind_method(PackedInt64Array, sort, sarray(), varray());
  2184. bind_method(PackedInt64Array, bsearch, sarray("value", "before"), varray(true));
  2185. bind_method(PackedInt64Array, duplicate, sarray(), varray());
  2186. bind_method(PackedInt64Array, find, sarray("value", "from"), varray(0));
  2187. bind_method(PackedInt64Array, rfind, sarray("value", "from"), varray(-1));
  2188. bind_method(PackedInt64Array, count, sarray("value"), varray());
  2189. /* Float32 Array */
  2190. bind_method(PackedFloat32Array, size, sarray(), varray());
  2191. bind_method(PackedFloat32Array, is_empty, sarray(), varray());
  2192. bind_method(PackedFloat32Array, set, sarray("index", "value"), varray());
  2193. bind_method(PackedFloat32Array, push_back, sarray("value"), varray());
  2194. bind_method(PackedFloat32Array, append, sarray("value"), varray());
  2195. bind_method(PackedFloat32Array, append_array, sarray("array"), varray());
  2196. bind_method(PackedFloat32Array, remove_at, sarray("index"), varray());
  2197. bind_method(PackedFloat32Array, insert, sarray("at_index", "value"), varray());
  2198. bind_method(PackedFloat32Array, fill, sarray("value"), varray());
  2199. bind_methodv(PackedFloat32Array, resize, &PackedFloat32Array::resize_zeroed, sarray("new_size"), varray());
  2200. bind_method(PackedFloat32Array, clear, sarray(), varray());
  2201. bind_method(PackedFloat32Array, has, sarray("value"), varray());
  2202. bind_method(PackedFloat32Array, reverse, sarray(), varray());
  2203. bind_method(PackedFloat32Array, slice, sarray("begin", "end"), varray(INT_MAX));
  2204. bind_method(PackedFloat32Array, to_byte_array, sarray(), varray());
  2205. bind_method(PackedFloat32Array, sort, sarray(), varray());
  2206. bind_method(PackedFloat32Array, bsearch, sarray("value", "before"), varray(true));
  2207. bind_method(PackedFloat32Array, duplicate, sarray(), varray());
  2208. bind_method(PackedFloat32Array, find, sarray("value", "from"), varray(0));
  2209. bind_method(PackedFloat32Array, rfind, sarray("value", "from"), varray(-1));
  2210. bind_method(PackedFloat32Array, count, sarray("value"), varray());
  2211. /* Float64 Array */
  2212. bind_method(PackedFloat64Array, size, sarray(), varray());
  2213. bind_method(PackedFloat64Array, is_empty, sarray(), varray());
  2214. bind_method(PackedFloat64Array, set, sarray("index", "value"), varray());
  2215. bind_method(PackedFloat64Array, push_back, sarray("value"), varray());
  2216. bind_method(PackedFloat64Array, append, sarray("value"), varray());
  2217. bind_method(PackedFloat64Array, append_array, sarray("array"), varray());
  2218. bind_method(PackedFloat64Array, remove_at, sarray("index"), varray());
  2219. bind_method(PackedFloat64Array, insert, sarray("at_index", "value"), varray());
  2220. bind_method(PackedFloat64Array, fill, sarray("value"), varray());
  2221. bind_methodv(PackedFloat64Array, resize, &PackedFloat64Array::resize_zeroed, sarray("new_size"), varray());
  2222. bind_method(PackedFloat64Array, clear, sarray(), varray());
  2223. bind_method(PackedFloat64Array, has, sarray("value"), varray());
  2224. bind_method(PackedFloat64Array, reverse, sarray(), varray());
  2225. bind_method(PackedFloat64Array, slice, sarray("begin", "end"), varray(INT_MAX));
  2226. bind_method(PackedFloat64Array, to_byte_array, sarray(), varray());
  2227. bind_method(PackedFloat64Array, sort, sarray(), varray());
  2228. bind_method(PackedFloat64Array, bsearch, sarray("value", "before"), varray(true));
  2229. bind_method(PackedFloat64Array, duplicate, sarray(), varray());
  2230. bind_method(PackedFloat64Array, find, sarray("value", "from"), varray(0));
  2231. bind_method(PackedFloat64Array, rfind, sarray("value", "from"), varray(-1));
  2232. bind_method(PackedFloat64Array, count, sarray("value"), varray());
  2233. /* String Array */
  2234. bind_method(PackedStringArray, size, sarray(), varray());
  2235. bind_method(PackedStringArray, is_empty, sarray(), varray());
  2236. bind_method(PackedStringArray, set, sarray("index", "value"), varray());
  2237. bind_method(PackedStringArray, push_back, sarray("value"), varray());
  2238. bind_method(PackedStringArray, append, sarray("value"), varray());
  2239. bind_method(PackedStringArray, append_array, sarray("array"), varray());
  2240. bind_method(PackedStringArray, remove_at, sarray("index"), varray());
  2241. bind_method(PackedStringArray, insert, sarray("at_index", "value"), varray());
  2242. bind_method(PackedStringArray, fill, sarray("value"), varray());
  2243. bind_methodv(PackedStringArray, resize, &PackedStringArray::resize_zeroed, sarray("new_size"), varray());
  2244. bind_method(PackedStringArray, clear, sarray(), varray());
  2245. bind_method(PackedStringArray, has, sarray("value"), varray());
  2246. bind_method(PackedStringArray, reverse, sarray(), varray());
  2247. bind_method(PackedStringArray, slice, sarray("begin", "end"), varray(INT_MAX));
  2248. bind_method(PackedStringArray, to_byte_array, sarray(), varray());
  2249. bind_method(PackedStringArray, sort, sarray(), varray());
  2250. bind_method(PackedStringArray, bsearch, sarray("value", "before"), varray(true));
  2251. bind_method(PackedStringArray, duplicate, sarray(), varray());
  2252. bind_method(PackedStringArray, find, sarray("value", "from"), varray(0));
  2253. bind_method(PackedStringArray, rfind, sarray("value", "from"), varray(-1));
  2254. bind_method(PackedStringArray, count, sarray("value"), varray());
  2255. /* Vector2 Array */
  2256. bind_method(PackedVector2Array, size, sarray(), varray());
  2257. bind_method(PackedVector2Array, is_empty, sarray(), varray());
  2258. bind_method(PackedVector2Array, set, sarray("index", "value"), varray());
  2259. bind_method(PackedVector2Array, push_back, sarray("value"), varray());
  2260. bind_method(PackedVector2Array, append, sarray("value"), varray());
  2261. bind_method(PackedVector2Array, append_array, sarray("array"), varray());
  2262. bind_method(PackedVector2Array, remove_at, sarray("index"), varray());
  2263. bind_method(PackedVector2Array, insert, sarray("at_index", "value"), varray());
  2264. bind_method(PackedVector2Array, fill, sarray("value"), varray());
  2265. bind_methodv(PackedVector2Array, resize, &PackedVector2Array::resize_zeroed, sarray("new_size"), varray());
  2266. bind_method(PackedVector2Array, clear, sarray(), varray());
  2267. bind_method(PackedVector2Array, has, sarray("value"), varray());
  2268. bind_method(PackedVector2Array, reverse, sarray(), varray());
  2269. bind_method(PackedVector2Array, slice, sarray("begin", "end"), varray(INT_MAX));
  2270. bind_method(PackedVector2Array, to_byte_array, sarray(), varray());
  2271. bind_method(PackedVector2Array, sort, sarray(), varray());
  2272. bind_method(PackedVector2Array, bsearch, sarray("value", "before"), varray(true));
  2273. bind_method(PackedVector2Array, duplicate, sarray(), varray());
  2274. bind_method(PackedVector2Array, find, sarray("value", "from"), varray(0));
  2275. bind_method(PackedVector2Array, rfind, sarray("value", "from"), varray(-1));
  2276. bind_method(PackedVector2Array, count, sarray("value"), varray());
  2277. /* Vector3 Array */
  2278. bind_method(PackedVector3Array, size, sarray(), varray());
  2279. bind_method(PackedVector3Array, is_empty, sarray(), varray());
  2280. bind_method(PackedVector3Array, set, sarray("index", "value"), varray());
  2281. bind_method(PackedVector3Array, push_back, sarray("value"), varray());
  2282. bind_method(PackedVector3Array, append, sarray("value"), varray());
  2283. bind_method(PackedVector3Array, append_array, sarray("array"), varray());
  2284. bind_method(PackedVector3Array, remove_at, sarray("index"), varray());
  2285. bind_method(PackedVector3Array, insert, sarray("at_index", "value"), varray());
  2286. bind_method(PackedVector3Array, fill, sarray("value"), varray());
  2287. bind_methodv(PackedVector3Array, resize, &PackedVector3Array::resize_zeroed, sarray("new_size"), varray());
  2288. bind_method(PackedVector3Array, clear, sarray(), varray());
  2289. bind_method(PackedVector3Array, has, sarray("value"), varray());
  2290. bind_method(PackedVector3Array, reverse, sarray(), varray());
  2291. bind_method(PackedVector3Array, slice, sarray("begin", "end"), varray(INT_MAX));
  2292. bind_method(PackedVector3Array, to_byte_array, sarray(), varray());
  2293. bind_method(PackedVector3Array, sort, sarray(), varray());
  2294. bind_method(PackedVector3Array, bsearch, sarray("value", "before"), varray(true));
  2295. bind_method(PackedVector3Array, duplicate, sarray(), varray());
  2296. bind_method(PackedVector3Array, find, sarray("value", "from"), varray(0));
  2297. bind_method(PackedVector3Array, rfind, sarray("value", "from"), varray(-1));
  2298. bind_method(PackedVector3Array, count, sarray("value"), varray());
  2299. /* Color Array */
  2300. bind_method(PackedColorArray, size, sarray(), varray());
  2301. bind_method(PackedColorArray, is_empty, sarray(), varray());
  2302. bind_method(PackedColorArray, set, sarray("index", "value"), varray());
  2303. bind_method(PackedColorArray, push_back, sarray("value"), varray());
  2304. bind_method(PackedColorArray, append, sarray("value"), varray());
  2305. bind_method(PackedColorArray, append_array, sarray("array"), varray());
  2306. bind_method(PackedColorArray, remove_at, sarray("index"), varray());
  2307. bind_method(PackedColorArray, insert, sarray("at_index", "value"), varray());
  2308. bind_method(PackedColorArray, fill, sarray("value"), varray());
  2309. bind_methodv(PackedColorArray, resize, &PackedColorArray::resize_zeroed, sarray("new_size"), varray());
  2310. bind_method(PackedColorArray, clear, sarray(), varray());
  2311. bind_method(PackedColorArray, has, sarray("value"), varray());
  2312. bind_method(PackedColorArray, reverse, sarray(), varray());
  2313. bind_method(PackedColorArray, slice, sarray("begin", "end"), varray(INT_MAX));
  2314. bind_method(PackedColorArray, to_byte_array, sarray(), varray());
  2315. bind_method(PackedColorArray, sort, sarray(), varray());
  2316. bind_method(PackedColorArray, bsearch, sarray("value", "before"), varray(true));
  2317. bind_method(PackedColorArray, duplicate, sarray(), varray());
  2318. bind_method(PackedColorArray, find, sarray("value", "from"), varray(0));
  2319. bind_method(PackedColorArray, rfind, sarray("value", "from"), varray(-1));
  2320. bind_method(PackedColorArray, count, sarray("value"), varray());
  2321. /* Vector4 Array */
  2322. bind_method(PackedVector4Array, size, sarray(), varray());
  2323. bind_method(PackedVector4Array, is_empty, sarray(), varray());
  2324. bind_method(PackedVector4Array, set, sarray("index", "value"), varray());
  2325. bind_method(PackedVector4Array, push_back, sarray("value"), varray());
  2326. bind_method(PackedVector4Array, append, sarray("value"), varray());
  2327. bind_method(PackedVector4Array, append_array, sarray("array"), varray());
  2328. bind_method(PackedVector4Array, remove_at, sarray("index"), varray());
  2329. bind_method(PackedVector4Array, insert, sarray("at_index", "value"), varray());
  2330. bind_method(PackedVector4Array, fill, sarray("value"), varray());
  2331. bind_methodv(PackedVector4Array, resize, &PackedVector4Array::resize_zeroed, sarray("new_size"), varray());
  2332. bind_method(PackedVector4Array, clear, sarray(), varray());
  2333. bind_method(PackedVector4Array, has, sarray("value"), varray());
  2334. bind_method(PackedVector4Array, reverse, sarray(), varray());
  2335. bind_method(PackedVector4Array, slice, sarray("begin", "end"), varray(INT_MAX));
  2336. bind_method(PackedVector4Array, to_byte_array, sarray(), varray());
  2337. bind_method(PackedVector4Array, sort, sarray(), varray());
  2338. bind_method(PackedVector4Array, bsearch, sarray("value", "before"), varray(true));
  2339. bind_method(PackedVector4Array, duplicate, sarray(), varray());
  2340. bind_method(PackedVector4Array, find, sarray("value", "from"), varray(0));
  2341. bind_method(PackedVector4Array, rfind, sarray("value", "from"), varray(-1));
  2342. bind_method(PackedVector4Array, count, sarray("value"), varray());
  2343. }
  2344. static void _register_variant_builtin_constants() {
  2345. /* Register constants */
  2346. int ncc = Color::get_named_color_count();
  2347. for (int i = 0; i < ncc; i++) {
  2348. _VariantCall::add_variant_constant(Variant::COLOR, Color::get_named_color_name(i), Color::get_named_color(i));
  2349. }
  2350. _VariantCall::add_constant(Variant::VECTOR3, "AXIS_X", Vector3::AXIS_X);
  2351. _VariantCall::add_constant(Variant::VECTOR3, "AXIS_Y", Vector3::AXIS_Y);
  2352. _VariantCall::add_constant(Variant::VECTOR3, "AXIS_Z", Vector3::AXIS_Z);
  2353. _VariantCall::add_enum_constant(Variant::VECTOR3, "Axis", "AXIS_X", Vector3::AXIS_X);
  2354. _VariantCall::add_enum_constant(Variant::VECTOR3, "Axis", "AXIS_Y", Vector3::AXIS_Y);
  2355. _VariantCall::add_enum_constant(Variant::VECTOR3, "Axis", "AXIS_Z", Vector3::AXIS_Z);
  2356. _VariantCall::add_variant_constant(Variant::VECTOR3, "ZERO", Vector3(0, 0, 0));
  2357. _VariantCall::add_variant_constant(Variant::VECTOR3, "ONE", Vector3(1, 1, 1));
  2358. _VariantCall::add_variant_constant(Variant::VECTOR3, "INF", Vector3(INFINITY, INFINITY, INFINITY));
  2359. _VariantCall::add_variant_constant(Variant::VECTOR3, "LEFT", Vector3(-1, 0, 0));
  2360. _VariantCall::add_variant_constant(Variant::VECTOR3, "RIGHT", Vector3(1, 0, 0));
  2361. _VariantCall::add_variant_constant(Variant::VECTOR3, "UP", Vector3(0, 1, 0));
  2362. _VariantCall::add_variant_constant(Variant::VECTOR3, "DOWN", Vector3(0, -1, 0));
  2363. _VariantCall::add_variant_constant(Variant::VECTOR3, "FORWARD", Vector3(0, 0, -1));
  2364. _VariantCall::add_variant_constant(Variant::VECTOR3, "BACK", Vector3(0, 0, 1));
  2365. _VariantCall::add_variant_constant(Variant::VECTOR3, "MODEL_LEFT", Vector3(1, 0, 0));
  2366. _VariantCall::add_variant_constant(Variant::VECTOR3, "MODEL_RIGHT", Vector3(-1, 0, 0));
  2367. _VariantCall::add_variant_constant(Variant::VECTOR3, "MODEL_TOP", Vector3(0, 1, 0));
  2368. _VariantCall::add_variant_constant(Variant::VECTOR3, "MODEL_BOTTOM", Vector3(0, -1, 0));
  2369. _VariantCall::add_variant_constant(Variant::VECTOR3, "MODEL_FRONT", Vector3(0, 0, 1));
  2370. _VariantCall::add_variant_constant(Variant::VECTOR3, "MODEL_REAR", Vector3(0, 0, -1));
  2371. _VariantCall::add_constant(Variant::VECTOR4, "AXIS_X", Vector4::AXIS_X);
  2372. _VariantCall::add_constant(Variant::VECTOR4, "AXIS_Y", Vector4::AXIS_Y);
  2373. _VariantCall::add_constant(Variant::VECTOR4, "AXIS_Z", Vector4::AXIS_Z);
  2374. _VariantCall::add_constant(Variant::VECTOR4, "AXIS_W", Vector4::AXIS_W);
  2375. _VariantCall::add_enum_constant(Variant::VECTOR4, "Axis", "AXIS_X", Vector4::AXIS_X);
  2376. _VariantCall::add_enum_constant(Variant::VECTOR4, "Axis", "AXIS_Y", Vector4::AXIS_Y);
  2377. _VariantCall::add_enum_constant(Variant::VECTOR4, "Axis", "AXIS_Z", Vector4::AXIS_Z);
  2378. _VariantCall::add_enum_constant(Variant::VECTOR4, "Axis", "AXIS_W", Vector4::AXIS_W);
  2379. _VariantCall::add_variant_constant(Variant::VECTOR4, "ZERO", Vector4(0, 0, 0, 0));
  2380. _VariantCall::add_variant_constant(Variant::VECTOR4, "ONE", Vector4(1, 1, 1, 1));
  2381. _VariantCall::add_variant_constant(Variant::VECTOR4, "INF", Vector4(INFINITY, INFINITY, INFINITY, INFINITY));
  2382. _VariantCall::add_constant(Variant::VECTOR3I, "AXIS_X", Vector3i::AXIS_X);
  2383. _VariantCall::add_constant(Variant::VECTOR3I, "AXIS_Y", Vector3i::AXIS_Y);
  2384. _VariantCall::add_constant(Variant::VECTOR3I, "AXIS_Z", Vector3i::AXIS_Z);
  2385. _VariantCall::add_enum_constant(Variant::VECTOR3I, "Axis", "AXIS_X", Vector3i::AXIS_X);
  2386. _VariantCall::add_enum_constant(Variant::VECTOR3I, "Axis", "AXIS_Y", Vector3i::AXIS_Y);
  2387. _VariantCall::add_enum_constant(Variant::VECTOR3I, "Axis", "AXIS_Z", Vector3i::AXIS_Z);
  2388. _VariantCall::add_constant(Variant::VECTOR4I, "AXIS_X", Vector4i::AXIS_X);
  2389. _VariantCall::add_constant(Variant::VECTOR4I, "AXIS_Y", Vector4i::AXIS_Y);
  2390. _VariantCall::add_constant(Variant::VECTOR4I, "AXIS_Z", Vector4i::AXIS_Z);
  2391. _VariantCall::add_constant(Variant::VECTOR4I, "AXIS_W", Vector4i::AXIS_W);
  2392. _VariantCall::add_enum_constant(Variant::VECTOR4I, "Axis", "AXIS_X", Vector4i::AXIS_X);
  2393. _VariantCall::add_enum_constant(Variant::VECTOR4I, "Axis", "AXIS_Y", Vector4i::AXIS_Y);
  2394. _VariantCall::add_enum_constant(Variant::VECTOR4I, "Axis", "AXIS_Z", Vector4i::AXIS_Z);
  2395. _VariantCall::add_enum_constant(Variant::VECTOR4I, "Axis", "AXIS_W", Vector4i::AXIS_W);
  2396. _VariantCall::add_variant_constant(Variant::VECTOR4I, "ZERO", Vector4i(0, 0, 0, 0));
  2397. _VariantCall::add_variant_constant(Variant::VECTOR4I, "ONE", Vector4i(1, 1, 1, 1));
  2398. _VariantCall::add_variant_constant(Variant::VECTOR4I, "MIN", Vector4i(INT32_MIN, INT32_MIN, INT32_MIN, INT32_MIN));
  2399. _VariantCall::add_variant_constant(Variant::VECTOR4I, "MAX", Vector4i(INT32_MAX, INT32_MAX, INT32_MAX, INT32_MAX));
  2400. _VariantCall::add_variant_constant(Variant::VECTOR3I, "ZERO", Vector3i(0, 0, 0));
  2401. _VariantCall::add_variant_constant(Variant::VECTOR3I, "ONE", Vector3i(1, 1, 1));
  2402. _VariantCall::add_variant_constant(Variant::VECTOR3I, "MIN", Vector3i(INT32_MIN, INT32_MIN, INT32_MIN));
  2403. _VariantCall::add_variant_constant(Variant::VECTOR3I, "MAX", Vector3i(INT32_MAX, INT32_MAX, INT32_MAX));
  2404. _VariantCall::add_variant_constant(Variant::VECTOR3I, "LEFT", Vector3i(-1, 0, 0));
  2405. _VariantCall::add_variant_constant(Variant::VECTOR3I, "RIGHT", Vector3i(1, 0, 0));
  2406. _VariantCall::add_variant_constant(Variant::VECTOR3I, "UP", Vector3i(0, 1, 0));
  2407. _VariantCall::add_variant_constant(Variant::VECTOR3I, "DOWN", Vector3i(0, -1, 0));
  2408. _VariantCall::add_variant_constant(Variant::VECTOR3I, "FORWARD", Vector3i(0, 0, -1));
  2409. _VariantCall::add_variant_constant(Variant::VECTOR3I, "BACK", Vector3i(0, 0, 1));
  2410. _VariantCall::add_constant(Variant::VECTOR2, "AXIS_X", Vector2::AXIS_X);
  2411. _VariantCall::add_constant(Variant::VECTOR2, "AXIS_Y", Vector2::AXIS_Y);
  2412. _VariantCall::add_enum_constant(Variant::VECTOR2, "Axis", "AXIS_X", Vector2::AXIS_X);
  2413. _VariantCall::add_enum_constant(Variant::VECTOR2, "Axis", "AXIS_Y", Vector2::AXIS_Y);
  2414. _VariantCall::add_constant(Variant::VECTOR2I, "AXIS_X", Vector2i::AXIS_X);
  2415. _VariantCall::add_constant(Variant::VECTOR2I, "AXIS_Y", Vector2i::AXIS_Y);
  2416. _VariantCall::add_enum_constant(Variant::VECTOR2I, "Axis", "AXIS_X", Vector2i::AXIS_X);
  2417. _VariantCall::add_enum_constant(Variant::VECTOR2I, "Axis", "AXIS_Y", Vector2i::AXIS_Y);
  2418. _VariantCall::add_variant_constant(Variant::VECTOR2, "ZERO", Vector2(0, 0));
  2419. _VariantCall::add_variant_constant(Variant::VECTOR2, "ONE", Vector2(1, 1));
  2420. _VariantCall::add_variant_constant(Variant::VECTOR2, "INF", Vector2(INFINITY, INFINITY));
  2421. _VariantCall::add_variant_constant(Variant::VECTOR2, "LEFT", Vector2(-1, 0));
  2422. _VariantCall::add_variant_constant(Variant::VECTOR2, "RIGHT", Vector2(1, 0));
  2423. _VariantCall::add_variant_constant(Variant::VECTOR2, "UP", Vector2(0, -1));
  2424. _VariantCall::add_variant_constant(Variant::VECTOR2, "DOWN", Vector2(0, 1));
  2425. _VariantCall::add_variant_constant(Variant::VECTOR2I, "ZERO", Vector2i(0, 0));
  2426. _VariantCall::add_variant_constant(Variant::VECTOR2I, "ONE", Vector2i(1, 1));
  2427. _VariantCall::add_variant_constant(Variant::VECTOR2I, "MIN", Vector2i(INT32_MIN, INT32_MIN));
  2428. _VariantCall::add_variant_constant(Variant::VECTOR2I, "MAX", Vector2i(INT32_MAX, INT32_MAX));
  2429. _VariantCall::add_variant_constant(Variant::VECTOR2I, "LEFT", Vector2i(-1, 0));
  2430. _VariantCall::add_variant_constant(Variant::VECTOR2I, "RIGHT", Vector2i(1, 0));
  2431. _VariantCall::add_variant_constant(Variant::VECTOR2I, "UP", Vector2i(0, -1));
  2432. _VariantCall::add_variant_constant(Variant::VECTOR2I, "DOWN", Vector2i(0, 1));
  2433. _VariantCall::add_variant_constant(Variant::TRANSFORM2D, "IDENTITY", Transform2D());
  2434. _VariantCall::add_variant_constant(Variant::TRANSFORM2D, "FLIP_X", Transform2D(-1, 0, 0, 1, 0, 0));
  2435. _VariantCall::add_variant_constant(Variant::TRANSFORM2D, "FLIP_Y", Transform2D(1, 0, 0, -1, 0, 0));
  2436. Transform3D identity_transform;
  2437. Transform3D flip_x_transform = Transform3D(-1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0);
  2438. Transform3D flip_y_transform = Transform3D(1, 0, 0, 0, -1, 0, 0, 0, 1, 0, 0, 0);
  2439. Transform3D flip_z_transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 0);
  2440. _VariantCall::add_variant_constant(Variant::TRANSFORM3D, "IDENTITY", identity_transform);
  2441. _VariantCall::add_variant_constant(Variant::TRANSFORM3D, "FLIP_X", flip_x_transform);
  2442. _VariantCall::add_variant_constant(Variant::TRANSFORM3D, "FLIP_Y", flip_y_transform);
  2443. _VariantCall::add_variant_constant(Variant::TRANSFORM3D, "FLIP_Z", flip_z_transform);
  2444. Basis identity_basis;
  2445. Basis flip_x_basis = Basis(-1, 0, 0, 0, 1, 0, 0, 0, 1);
  2446. Basis flip_y_basis = Basis(1, 0, 0, 0, -1, 0, 0, 0, 1);
  2447. Basis flip_z_basis = Basis(1, 0, 0, 0, 1, 0, 0, 0, -1);
  2448. _VariantCall::add_variant_constant(Variant::BASIS, "IDENTITY", identity_basis);
  2449. _VariantCall::add_variant_constant(Variant::BASIS, "FLIP_X", flip_x_basis);
  2450. _VariantCall::add_variant_constant(Variant::BASIS, "FLIP_Y", flip_y_basis);
  2451. _VariantCall::add_variant_constant(Variant::BASIS, "FLIP_Z", flip_z_basis);
  2452. _VariantCall::add_variant_constant(Variant::PLANE, "PLANE_YZ", Plane(Vector3(1, 0, 0), 0));
  2453. _VariantCall::add_variant_constant(Variant::PLANE, "PLANE_XZ", Plane(Vector3(0, 1, 0), 0));
  2454. _VariantCall::add_variant_constant(Variant::PLANE, "PLANE_XY", Plane(Vector3(0, 0, 1), 0));
  2455. _VariantCall::add_variant_constant(Variant::QUATERNION, "IDENTITY", Quaternion(0, 0, 0, 1));
  2456. _VariantCall::add_constant(Variant::PROJECTION, "PLANE_NEAR", Projection::PLANE_NEAR);
  2457. _VariantCall::add_constant(Variant::PROJECTION, "PLANE_FAR", Projection::PLANE_FAR);
  2458. _VariantCall::add_constant(Variant::PROJECTION, "PLANE_LEFT", Projection::PLANE_LEFT);
  2459. _VariantCall::add_constant(Variant::PROJECTION, "PLANE_TOP", Projection::PLANE_TOP);
  2460. _VariantCall::add_constant(Variant::PROJECTION, "PLANE_RIGHT", Projection::PLANE_RIGHT);
  2461. _VariantCall::add_constant(Variant::PROJECTION, "PLANE_BOTTOM", Projection::PLANE_BOTTOM);
  2462. _VariantCall::add_enum_constant(Variant::PROJECTION, "Planes", "PLANE_NEAR", Projection::PLANE_NEAR);
  2463. _VariantCall::add_enum_constant(Variant::PROJECTION, "Planes", "PLANE_FAR", Projection::PLANE_FAR);
  2464. _VariantCall::add_enum_constant(Variant::PROJECTION, "Planes", "PLANE_LEFT", Projection::PLANE_LEFT);
  2465. _VariantCall::add_enum_constant(Variant::PROJECTION, "Planes", "PLANE_TOP", Projection::PLANE_TOP);
  2466. _VariantCall::add_enum_constant(Variant::PROJECTION, "Planes", "PLANE_RIGHT", Projection::PLANE_RIGHT);
  2467. _VariantCall::add_enum_constant(Variant::PROJECTION, "Planes", "PLANE_BOTTOM", Projection::PLANE_BOTTOM);
  2468. Projection p;
  2469. _VariantCall::add_variant_constant(Variant::PROJECTION, "IDENTITY", p);
  2470. p.set_zero();
  2471. _VariantCall::add_variant_constant(Variant::PROJECTION, "ZERO", p);
  2472. }
  2473. void Variant::_register_variant_methods() {
  2474. _register_variant_builtin_methods_string();
  2475. _register_variant_builtin_methods_math();
  2476. _register_variant_builtin_methods_misc();
  2477. _register_variant_builtin_methods_array();
  2478. _register_variant_builtin_constants();
  2479. }
  2480. void Variant::_unregister_variant_methods() {
  2481. //clear methods
  2482. memdelete_arr(builtin_method_names);
  2483. memdelete_arr(builtin_method_info);
  2484. memdelete_arr(_VariantCall::constant_data);
  2485. memdelete_arr(_VariantCall::enum_data);
  2486. }