variant_call.cpp 96 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171
  1. /*************************************************************************/
  2. /* variant_call.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "variant.h"
  31. #include "core/color_names.inc"
  32. #include "core/core_string_names.h"
  33. #include "core/crypto/crypto_core.h"
  34. #include "core/io/compression.h"
  35. #include "core/object.h"
  36. #include "core/object_rc.h"
  37. #include "core/os/os.h"
  38. #include "core/script_language.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. struct _VariantCall {
  42. static void Vector3_dot(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  43. r_ret = reinterpret_cast<Vector3 *>(p_self._data._mem)->dot(*reinterpret_cast<const Vector3 *>(p_args[0]->_data._mem));
  44. }
  45. struct FuncData {
  46. int arg_count;
  47. Vector<Variant> default_args;
  48. Vector<Variant::Type> arg_types;
  49. Vector<StringName> arg_names;
  50. Variant::Type return_type;
  51. bool _const;
  52. bool returns;
  53. VariantFunc func;
  54. _FORCE_INLINE_ bool verify_arguments(const Variant **p_args, Variant::CallError &r_error) {
  55. if (arg_count == 0) {
  56. return true;
  57. }
  58. const Variant::Type *tptr = &arg_types[0];
  59. for (int i = 0; i < arg_count; i++) {
  60. if (tptr[i] == Variant::NIL || tptr[i] == p_args[i]->type) {
  61. continue; // all good
  62. }
  63. if (!Variant::can_convert(p_args[i]->type, tptr[i])) {
  64. r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
  65. r_error.argument = i;
  66. r_error.expected = tptr[i];
  67. return false;
  68. }
  69. }
  70. return true;
  71. }
  72. _FORCE_INLINE_ void call(Variant &r_ret, Variant &p_self, const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
  73. #ifdef DEBUG_ENABLED
  74. if (p_argcount > arg_count) {
  75. r_error.error = Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
  76. r_error.argument = arg_count;
  77. return;
  78. } else
  79. #endif
  80. if (p_argcount < arg_count) {
  81. int def_argcount = default_args.size();
  82. #ifdef DEBUG_ENABLED
  83. if (p_argcount < (arg_count - def_argcount)) {
  84. r_error.error = Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  85. r_error.argument = arg_count - def_argcount;
  86. return;
  87. }
  88. #endif
  89. ERR_FAIL_COND(p_argcount > VARIANT_ARG_MAX);
  90. const Variant *newargs[VARIANT_ARG_MAX];
  91. for (int i = 0; i < p_argcount; i++) {
  92. newargs[i] = p_args[i];
  93. }
  94. // fill in any remaining parameters with defaults
  95. int first_default_arg = arg_count - def_argcount;
  96. for (int i = p_argcount; i < arg_count; i++) {
  97. newargs[i] = &default_args[i - first_default_arg];
  98. }
  99. #ifdef DEBUG_ENABLED
  100. if (!verify_arguments(newargs, r_error)) {
  101. return;
  102. }
  103. #endif
  104. func(r_ret, p_self, newargs);
  105. } else {
  106. #ifdef DEBUG_ENABLED
  107. if (!verify_arguments(p_args, r_error)) {
  108. return;
  109. }
  110. #endif
  111. func(r_ret, p_self, p_args);
  112. }
  113. }
  114. };
  115. struct TypeFunc {
  116. Map<StringName, FuncData> functions;
  117. };
  118. static TypeFunc *type_funcs;
  119. struct Arg {
  120. StringName name;
  121. Variant::Type type;
  122. Arg() { type = Variant::NIL; }
  123. Arg(Variant::Type p_type, const StringName &p_name) :
  124. name(p_name),
  125. type(p_type) {
  126. }
  127. };
  128. //void addfunc(Variant::Type p_type, const StringName& p_name,VariantFunc p_func);
  129. static void make_func_return_variant(Variant::Type p_type, const StringName &p_name) {
  130. #ifdef DEBUG_ENABLED
  131. type_funcs[p_type].functions[p_name].returns = true;
  132. #endif
  133. }
  134. static void addfunc(bool p_const, Variant::Type p_type, Variant::Type p_return, bool p_has_return, const StringName &p_name, VariantFunc p_func, const Vector<Variant> &p_defaultarg, const Arg &p_argtype1 = Arg(), const Arg &p_argtype2 = Arg(), const Arg &p_argtype3 = Arg(), const Arg &p_argtype4 = Arg(), const Arg &p_argtype5 = Arg()) {
  135. FuncData funcdata;
  136. funcdata.func = p_func;
  137. funcdata.default_args = p_defaultarg;
  138. funcdata._const = p_const;
  139. funcdata.returns = p_has_return;
  140. funcdata.return_type = p_return;
  141. if (p_argtype1.name) {
  142. funcdata.arg_types.push_back(p_argtype1.type);
  143. #ifdef DEBUG_ENABLED
  144. funcdata.arg_names.push_back(p_argtype1.name);
  145. #endif
  146. } else {
  147. goto end;
  148. }
  149. if (p_argtype2.name) {
  150. funcdata.arg_types.push_back(p_argtype2.type);
  151. #ifdef DEBUG_ENABLED
  152. funcdata.arg_names.push_back(p_argtype2.name);
  153. #endif
  154. } else {
  155. goto end;
  156. }
  157. if (p_argtype3.name) {
  158. funcdata.arg_types.push_back(p_argtype3.type);
  159. #ifdef DEBUG_ENABLED
  160. funcdata.arg_names.push_back(p_argtype3.name);
  161. #endif
  162. } else {
  163. goto end;
  164. }
  165. if (p_argtype4.name) {
  166. funcdata.arg_types.push_back(p_argtype4.type);
  167. #ifdef DEBUG_ENABLED
  168. funcdata.arg_names.push_back(p_argtype4.name);
  169. #endif
  170. } else {
  171. goto end;
  172. }
  173. if (p_argtype5.name) {
  174. funcdata.arg_types.push_back(p_argtype5.type);
  175. #ifdef DEBUG_ENABLED
  176. funcdata.arg_names.push_back(p_argtype5.name);
  177. #endif
  178. } else {
  179. goto end;
  180. }
  181. end:
  182. funcdata.arg_count = funcdata.arg_types.size();
  183. type_funcs[p_type].functions[p_name] = funcdata;
  184. }
  185. #define VCALL_LOCALMEM0(m_type, m_method) \
  186. static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._mem)->m_method(); }
  187. #define VCALL_LOCALMEM0R(m_type, m_method) \
  188. static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._mem)->m_method(); }
  189. #define VCALL_LOCALMEM1(m_type, m_method) \
  190. static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._mem)->m_method(*p_args[0]); }
  191. #define VCALL_LOCALMEM1R(m_type, m_method) \
  192. static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._mem)->m_method(*p_args[0]); }
  193. #define VCALL_LOCALMEM2(m_type, m_method) \
  194. static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._mem)->m_method(*p_args[0], *p_args[1]); }
  195. #define VCALL_LOCALMEM2R(m_type, m_method) \
  196. static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._mem)->m_method(*p_args[0], *p_args[1]); }
  197. #define VCALL_LOCALMEM3(m_type, m_method) \
  198. static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._mem)->m_method(*p_args[0], *p_args[1], *p_args[2]); }
  199. #define VCALL_LOCALMEM3R(m_type, m_method) \
  200. static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._mem)->m_method(*p_args[0], *p_args[1], *p_args[2]); }
  201. #define VCALL_LOCALMEM4(m_type, m_method) \
  202. static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._mem)->m_method(*p_args[0], *p_args[1], *p_args[2], *p_args[3]); }
  203. #define VCALL_LOCALMEM4R(m_type, m_method) \
  204. static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._mem)->m_method(*p_args[0], *p_args[1], *p_args[2], *p_args[3]); }
  205. #define VCALL_LOCALMEM5(m_type, m_method) \
  206. static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._mem)->m_method(*p_args[0], *p_args[1], *p_args[2], *p_args[3], *p_args[4]); }
  207. #define VCALL_LOCALMEM5R(m_type, m_method) \
  208. static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._mem)->m_method(*p_args[0], *p_args[1], *p_args[2], *p_args[3], *p_args[4]); }
  209. // built-in functions of localmem based types
  210. VCALL_LOCALMEM1R(String, casecmp_to);
  211. VCALL_LOCALMEM1R(String, nocasecmp_to);
  212. VCALL_LOCALMEM1R(String, naturalnocasecmp_to);
  213. VCALL_LOCALMEM0R(String, length);
  214. VCALL_LOCALMEM3R(String, count);
  215. VCALL_LOCALMEM3R(String, countn);
  216. VCALL_LOCALMEM2R(String, substr);
  217. VCALL_LOCALMEM2R(String, get_slice);
  218. VCALL_LOCALMEM2R(String, find);
  219. VCALL_LOCALMEM1R(String, find_last);
  220. VCALL_LOCALMEM2R(String, findn);
  221. VCALL_LOCALMEM2R(String, rfind);
  222. VCALL_LOCALMEM2R(String, rfindn);
  223. VCALL_LOCALMEM1R(String, match);
  224. VCALL_LOCALMEM1R(String, matchn);
  225. VCALL_LOCALMEM1R(String, begins_with);
  226. VCALL_LOCALMEM1R(String, ends_with);
  227. VCALL_LOCALMEM1R(String, is_subsequence_of);
  228. VCALL_LOCALMEM1R(String, is_subsequence_ofi);
  229. VCALL_LOCALMEM0R(String, bigrams);
  230. VCALL_LOCALMEM1R(String, similarity);
  231. VCALL_LOCALMEM2R(String, format);
  232. VCALL_LOCALMEM2R(String, replace);
  233. VCALL_LOCALMEM2R(String, replacen);
  234. VCALL_LOCALMEM1R(String, repeat);
  235. VCALL_LOCALMEM2R(String, insert);
  236. VCALL_LOCALMEM0R(String, capitalize);
  237. VCALL_LOCALMEM3R(String, split);
  238. VCALL_LOCALMEM3R(String, rsplit);
  239. VCALL_LOCALMEM2R(String, split_floats);
  240. VCALL_LOCALMEM0R(String, to_upper);
  241. VCALL_LOCALMEM0R(String, to_lower);
  242. VCALL_LOCALMEM1R(String, left);
  243. VCALL_LOCALMEM1R(String, right);
  244. VCALL_LOCALMEM0R(String, dedent);
  245. VCALL_LOCALMEM2R(String, strip_edges);
  246. VCALL_LOCALMEM0R(String, strip_escapes);
  247. VCALL_LOCALMEM1R(String, lstrip);
  248. VCALL_LOCALMEM1R(String, rstrip);
  249. VCALL_LOCALMEM0R(String, get_extension);
  250. VCALL_LOCALMEM0R(String, get_basename);
  251. VCALL_LOCALMEM1R(String, plus_file);
  252. VCALL_LOCALMEM1R(String, ord_at);
  253. VCALL_LOCALMEM2(String, erase);
  254. VCALL_LOCALMEM0R(String, hash);
  255. VCALL_LOCALMEM0R(String, md5_text);
  256. VCALL_LOCALMEM0R(String, sha1_text);
  257. VCALL_LOCALMEM0R(String, sha256_text);
  258. VCALL_LOCALMEM0R(String, md5_buffer);
  259. VCALL_LOCALMEM0R(String, sha1_buffer);
  260. VCALL_LOCALMEM0R(String, sha256_buffer);
  261. VCALL_LOCALMEM0R(String, empty);
  262. VCALL_LOCALMEM1R(String, humanize_size);
  263. VCALL_LOCALMEM0R(String, is_abs_path);
  264. VCALL_LOCALMEM0R(String, simplify_path);
  265. VCALL_LOCALMEM0R(String, is_rel_path);
  266. VCALL_LOCALMEM0R(String, get_base_dir);
  267. VCALL_LOCALMEM0R(String, get_file);
  268. VCALL_LOCALMEM0R(String, xml_escape);
  269. VCALL_LOCALMEM0R(String, xml_unescape);
  270. VCALL_LOCALMEM0R(String, http_escape);
  271. VCALL_LOCALMEM0R(String, http_unescape);
  272. VCALL_LOCALMEM0R(String, c_escape);
  273. VCALL_LOCALMEM0R(String, c_unescape);
  274. VCALL_LOCALMEM0R(String, json_escape);
  275. VCALL_LOCALMEM0R(String, percent_encode);
  276. VCALL_LOCALMEM0R(String, percent_decode);
  277. VCALL_LOCALMEM0R(String, validate_node_name);
  278. VCALL_LOCALMEM0R(String, is_valid_identifier);
  279. VCALL_LOCALMEM0R(String, is_valid_integer);
  280. VCALL_LOCALMEM0R(String, is_valid_float);
  281. VCALL_LOCALMEM1R(String, is_valid_hex_number);
  282. VCALL_LOCALMEM0R(String, is_valid_html_color);
  283. VCALL_LOCALMEM0R(String, is_valid_ip_address);
  284. VCALL_LOCALMEM0R(String, is_valid_filename);
  285. VCALL_LOCALMEM0R(String, to_int);
  286. VCALL_LOCALMEM0R(String, to_float);
  287. VCALL_LOCALMEM0R(String, hex_to_int);
  288. VCALL_LOCALMEM1R(String, pad_decimals);
  289. VCALL_LOCALMEM1R(String, pad_zeros);
  290. VCALL_LOCALMEM1R(String, trim_prefix);
  291. VCALL_LOCALMEM1R(String, trim_suffix);
  292. static void _call_String_to_ascii(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  293. String *s = reinterpret_cast<String *>(p_self._data._mem);
  294. if (s->empty()) {
  295. r_ret = PoolByteArray();
  296. return;
  297. }
  298. CharString charstr = s->ascii();
  299. PoolByteArray retval;
  300. size_t len = charstr.length();
  301. retval.resize(len);
  302. PoolByteArray::Write w = retval.write();
  303. memcpy(w.ptr(), charstr.ptr(), len);
  304. w.release();
  305. r_ret = retval;
  306. }
  307. static void _call_String_to_utf8(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  308. String *s = reinterpret_cast<String *>(p_self._data._mem);
  309. if (s->empty()) {
  310. r_ret = PoolByteArray();
  311. return;
  312. }
  313. CharString charstr = s->utf8();
  314. PoolByteArray retval;
  315. size_t len = charstr.length();
  316. retval.resize(len);
  317. PoolByteArray::Write w = retval.write();
  318. memcpy(w.ptr(), charstr.ptr(), len);
  319. w.release();
  320. r_ret = retval;
  321. }
  322. static void _call_String_to_wchar(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  323. String *s = reinterpret_cast<String *>(p_self._data._mem);
  324. if (s->empty()) {
  325. r_ret = PoolByteArray();
  326. return;
  327. }
  328. PoolByteArray retval;
  329. size_t len = s->length() * sizeof(wchar_t);
  330. retval.resize(len);
  331. PoolByteArray::Write w = retval.write();
  332. memcpy(w.ptr(), s->ptr(), len);
  333. w.release();
  334. r_ret = retval;
  335. }
  336. VCALL_LOCALMEM1R(Vector2, distance_to);
  337. VCALL_LOCALMEM1R(Vector2, distance_squared_to);
  338. VCALL_LOCALMEM0R(Vector2, length);
  339. VCALL_LOCALMEM0R(Vector2, length_squared);
  340. VCALL_LOCALMEM0R(Vector2, normalized);
  341. VCALL_LOCALMEM0R(Vector2, is_normalized);
  342. VCALL_LOCALMEM1R(Vector2, is_equal_approx);
  343. VCALL_LOCALMEM1R(Vector2, posmod);
  344. VCALL_LOCALMEM1R(Vector2, posmodv);
  345. VCALL_LOCALMEM1R(Vector2, project);
  346. VCALL_LOCALMEM1R(Vector2, angle_to);
  347. VCALL_LOCALMEM1R(Vector2, angle_to_point);
  348. VCALL_LOCALMEM1R(Vector2, direction_to);
  349. VCALL_LOCALMEM2R(Vector2, linear_interpolate);
  350. VCALL_LOCALMEM2R(Vector2, slerp);
  351. VCALL_LOCALMEM4R(Vector2, cubic_interpolate);
  352. VCALL_LOCALMEM2R(Vector2, move_toward);
  353. VCALL_LOCALMEM1R(Vector2, rotated);
  354. VCALL_LOCALMEM0R(Vector2, tangent);
  355. VCALL_LOCALMEM0R(Vector2, floor);
  356. VCALL_LOCALMEM0R(Vector2, ceil);
  357. VCALL_LOCALMEM0R(Vector2, round);
  358. VCALL_LOCALMEM1R(Vector2, snapped);
  359. VCALL_LOCALMEM0R(Vector2, aspect);
  360. VCALL_LOCALMEM1R(Vector2, dot);
  361. VCALL_LOCALMEM1R(Vector2, slide);
  362. VCALL_LOCALMEM1R(Vector2, bounce);
  363. VCALL_LOCALMEM1R(Vector2, reflect);
  364. VCALL_LOCALMEM0R(Vector2, angle);
  365. VCALL_LOCALMEM1R(Vector2, cross);
  366. VCALL_LOCALMEM0R(Vector2, abs);
  367. VCALL_LOCALMEM1R(Vector2, clamped);
  368. VCALL_LOCALMEM1R(Vector2, limit_length);
  369. VCALL_LOCALMEM0R(Vector2, sign);
  370. VCALL_LOCALMEM0R(Rect2, get_area);
  371. VCALL_LOCALMEM0R(Rect2, get_center);
  372. VCALL_LOCALMEM0R(Rect2, has_no_area);
  373. VCALL_LOCALMEM1R(Rect2, has_point);
  374. VCALL_LOCALMEM1R(Rect2, is_equal_approx);
  375. VCALL_LOCALMEM2R(Rect2, intersects);
  376. VCALL_LOCALMEM1R(Rect2, encloses);
  377. VCALL_LOCALMEM1R(Rect2, clip);
  378. VCALL_LOCALMEM1R(Rect2, merge);
  379. VCALL_LOCALMEM1R(Rect2, expand);
  380. VCALL_LOCALMEM1R(Rect2, grow);
  381. VCALL_LOCALMEM2R(Rect2, grow_margin);
  382. VCALL_LOCALMEM4R(Rect2, grow_individual);
  383. VCALL_LOCALMEM0R(Rect2, abs);
  384. VCALL_LOCALMEM0R(Vector3, min_axis);
  385. VCALL_LOCALMEM0R(Vector3, max_axis);
  386. VCALL_LOCALMEM1R(Vector3, distance_to);
  387. VCALL_LOCALMEM1R(Vector3, distance_squared_to);
  388. VCALL_LOCALMEM0R(Vector3, length);
  389. VCALL_LOCALMEM0R(Vector3, length_squared);
  390. VCALL_LOCALMEM0R(Vector3, normalized);
  391. VCALL_LOCALMEM0R(Vector3, is_normalized);
  392. VCALL_LOCALMEM1R(Vector3, is_equal_approx);
  393. VCALL_LOCALMEM0R(Vector3, inverse);
  394. VCALL_LOCALMEM1R(Vector3, snapped);
  395. VCALL_LOCALMEM2R(Vector3, rotated);
  396. VCALL_LOCALMEM2R(Vector3, linear_interpolate);
  397. VCALL_LOCALMEM2R(Vector3, slerp);
  398. VCALL_LOCALMEM4R(Vector3, cubic_interpolate);
  399. VCALL_LOCALMEM2R(Vector3, move_toward);
  400. VCALL_LOCALMEM1R(Vector3, dot);
  401. VCALL_LOCALMEM1R(Vector3, cross);
  402. VCALL_LOCALMEM1R(Vector3, outer);
  403. VCALL_LOCALMEM0R(Vector3, to_diagonal_matrix);
  404. VCALL_LOCALMEM0R(Vector3, abs);
  405. VCALL_LOCALMEM0R(Vector3, floor);
  406. VCALL_LOCALMEM0R(Vector3, ceil);
  407. VCALL_LOCALMEM0R(Vector3, round);
  408. VCALL_LOCALMEM1R(Vector3, posmod);
  409. VCALL_LOCALMEM1R(Vector3, posmodv);
  410. VCALL_LOCALMEM1R(Vector3, project);
  411. VCALL_LOCALMEM1R(Vector3, angle_to);
  412. VCALL_LOCALMEM2R(Vector3, signed_angle_to);
  413. VCALL_LOCALMEM1R(Vector3, direction_to);
  414. VCALL_LOCALMEM1R(Vector3, slide);
  415. VCALL_LOCALMEM1R(Vector3, bounce);
  416. VCALL_LOCALMEM1R(Vector3, reflect);
  417. VCALL_LOCALMEM1R(Vector3, limit_length);
  418. VCALL_LOCALMEM0R(Vector3, sign);
  419. VCALL_LOCALMEM0R(Plane, normalized);
  420. VCALL_LOCALMEM0R(Plane, center);
  421. VCALL_LOCALMEM0R(Plane, get_any_point);
  422. VCALL_LOCALMEM1R(Plane, is_equal_approx);
  423. VCALL_LOCALMEM1R(Plane, is_point_over);
  424. VCALL_LOCALMEM1R(Plane, distance_to);
  425. VCALL_LOCALMEM2R(Plane, has_point);
  426. VCALL_LOCALMEM1R(Plane, project);
  427. //return vector3 if intersected, nil if not
  428. static void _call_Plane_intersect_3(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  429. Vector3 result;
  430. if (reinterpret_cast<Plane *>(p_self._data._mem)->intersect_3(*p_args[0], *p_args[1], &result)) {
  431. r_ret = result;
  432. } else {
  433. r_ret = Variant();
  434. }
  435. }
  436. static void _call_Plane_intersects_ray(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  437. Vector3 result;
  438. if (reinterpret_cast<Plane *>(p_self._data._mem)->intersects_ray(*p_args[0], *p_args[1], &result)) {
  439. r_ret = result;
  440. } else {
  441. r_ret = Variant();
  442. }
  443. }
  444. static void _call_Plane_intersects_segment(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  445. Vector3 result;
  446. if (reinterpret_cast<Plane *>(p_self._data._mem)->intersects_segment(*p_args[0], *p_args[1], &result)) {
  447. r_ret = result;
  448. } else {
  449. r_ret = Variant();
  450. }
  451. }
  452. VCALL_LOCALMEM0R(Quat, length);
  453. VCALL_LOCALMEM0R(Quat, length_squared);
  454. VCALL_LOCALMEM0R(Quat, normalized);
  455. VCALL_LOCALMEM0R(Quat, is_normalized);
  456. VCALL_LOCALMEM1R(Quat, is_equal_approx);
  457. VCALL_LOCALMEM0R(Quat, inverse);
  458. VCALL_LOCALMEM1R(Quat, angle_to);
  459. VCALL_LOCALMEM1R(Quat, dot);
  460. VCALL_LOCALMEM1R(Quat, xform);
  461. VCALL_LOCALMEM2R(Quat, slerp);
  462. VCALL_LOCALMEM2R(Quat, slerpni);
  463. VCALL_LOCALMEM4R(Quat, cubic_slerp);
  464. VCALL_LOCALMEM0R(Quat, get_euler);
  465. VCALL_LOCALMEM1(Quat, set_euler);
  466. VCALL_LOCALMEM2(Quat, set_axis_angle);
  467. VCALL_LOCALMEM0R(Color, to_argb32);
  468. VCALL_LOCALMEM0R(Color, to_abgr32);
  469. VCALL_LOCALMEM0R(Color, to_rgba32);
  470. VCALL_LOCALMEM0R(Color, to_argb64);
  471. VCALL_LOCALMEM0R(Color, to_abgr64);
  472. VCALL_LOCALMEM0R(Color, to_rgba64);
  473. VCALL_LOCALMEM0R(Color, gray);
  474. VCALL_LOCALMEM0R(Color, inverted);
  475. VCALL_LOCALMEM0R(Color, contrasted);
  476. VCALL_LOCALMEM2R(Color, linear_interpolate);
  477. VCALL_LOCALMEM1R(Color, blend);
  478. VCALL_LOCALMEM1R(Color, lightened);
  479. VCALL_LOCALMEM1R(Color, darkened);
  480. VCALL_LOCALMEM1R(Color, to_html);
  481. VCALL_LOCALMEM4R(Color, from_hsv);
  482. VCALL_LOCALMEM1R(Color, is_equal_approx);
  483. VCALL_LOCALMEM0R(RID, get_id);
  484. VCALL_LOCALMEM0R(NodePath, is_absolute);
  485. VCALL_LOCALMEM0R(NodePath, get_name_count);
  486. VCALL_LOCALMEM1R(NodePath, get_name);
  487. VCALL_LOCALMEM0R(NodePath, get_subname_count);
  488. VCALL_LOCALMEM1R(NodePath, get_subname);
  489. VCALL_LOCALMEM0R(NodePath, get_concatenated_subnames);
  490. VCALL_LOCALMEM0R(NodePath, get_as_property_path);
  491. VCALL_LOCALMEM0R(NodePath, is_empty);
  492. VCALL_LOCALMEM0R(Dictionary, size);
  493. VCALL_LOCALMEM0R(Dictionary, empty);
  494. VCALL_LOCALMEM0(Dictionary, clear);
  495. VCALL_LOCALMEM1R(Dictionary, has);
  496. VCALL_LOCALMEM1R(Dictionary, has_all);
  497. VCALL_LOCALMEM1R(Dictionary, erase);
  498. VCALL_LOCALMEM0R(Dictionary, hash);
  499. VCALL_LOCALMEM0R(Dictionary, keys);
  500. VCALL_LOCALMEM0R(Dictionary, values);
  501. VCALL_LOCALMEM1R(Dictionary, duplicate);
  502. VCALL_LOCALMEM2R(Dictionary, get);
  503. VCALL_LOCALMEM2(Array, set);
  504. VCALL_LOCALMEM1R(Array, get);
  505. VCALL_LOCALMEM0R(Array, size);
  506. VCALL_LOCALMEM0R(Array, empty);
  507. VCALL_LOCALMEM0(Array, clear);
  508. VCALL_LOCALMEM0R(Array, hash);
  509. VCALL_LOCALMEM1(Array, push_back);
  510. VCALL_LOCALMEM1(Array, push_front);
  511. VCALL_LOCALMEM0R(Array, pop_back);
  512. VCALL_LOCALMEM0R(Array, pop_front);
  513. VCALL_LOCALMEM1R(Array, pop_at);
  514. VCALL_LOCALMEM1(Array, append);
  515. VCALL_LOCALMEM1(Array, append_array);
  516. VCALL_LOCALMEM1(Array, resize);
  517. VCALL_LOCALMEM2(Array, insert);
  518. VCALL_LOCALMEM1(Array, remove);
  519. VCALL_LOCALMEM0R(Array, front);
  520. VCALL_LOCALMEM0R(Array, back);
  521. VCALL_LOCALMEM2R(Array, find);
  522. VCALL_LOCALMEM2R(Array, rfind);
  523. VCALL_LOCALMEM1R(Array, find_last);
  524. VCALL_LOCALMEM1R(Array, count);
  525. VCALL_LOCALMEM1R(Array, has);
  526. VCALL_LOCALMEM1(Array, erase);
  527. VCALL_LOCALMEM0(Array, sort);
  528. VCALL_LOCALMEM2(Array, sort_custom);
  529. VCALL_LOCALMEM0(Array, shuffle);
  530. VCALL_LOCALMEM2R(Array, bsearch);
  531. VCALL_LOCALMEM4R(Array, bsearch_custom);
  532. VCALL_LOCALMEM1R(Array, duplicate);
  533. VCALL_LOCALMEM4R(Array, slice);
  534. VCALL_LOCALMEM0(Array, invert);
  535. VCALL_LOCALMEM0R(Array, max);
  536. VCALL_LOCALMEM0R(Array, min);
  537. static void _call_PoolByteArray_get_string_from_ascii(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  538. PoolByteArray *ba = reinterpret_cast<PoolByteArray *>(p_self._data._mem);
  539. String s;
  540. if (ba->size() > 0) {
  541. PoolByteArray::Read r = ba->read();
  542. CharString cs;
  543. cs.resize(ba->size() + 1);
  544. memcpy(cs.ptrw(), r.ptr(), ba->size());
  545. cs[ba->size()] = 0;
  546. s = cs.get_data();
  547. }
  548. r_ret = s;
  549. }
  550. static void _call_PoolByteArray_get_string_from_utf8(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  551. PoolByteArray *ba = reinterpret_cast<PoolByteArray *>(p_self._data._mem);
  552. String s;
  553. if (ba->size() > 0) {
  554. PoolByteArray::Read r = ba->read();
  555. s.parse_utf8((const char *)r.ptr(), ba->size());
  556. }
  557. r_ret = s;
  558. }
  559. static void _call_PoolByteArray_compress(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  560. PoolByteArray *ba = reinterpret_cast<PoolByteArray *>(p_self._data._mem);
  561. PoolByteArray compressed;
  562. if (ba->size() > 0) {
  563. Compression::Mode mode = (Compression::Mode)(int)(*p_args[0]);
  564. compressed.resize(Compression::get_max_compressed_buffer_size(ba->size(), mode));
  565. int result = Compression::compress(compressed.write().ptr(), ba->read().ptr(), ba->size(), mode);
  566. result = result >= 0 ? result : 0;
  567. compressed.resize(result);
  568. }
  569. r_ret = compressed;
  570. }
  571. static void _call_PoolByteArray_decompress(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  572. PoolByteArray *ba = reinterpret_cast<PoolByteArray *>(p_self._data._mem);
  573. PoolByteArray decompressed;
  574. Compression::Mode mode = (Compression::Mode)(int)(*p_args[1]);
  575. int buffer_size = (int)(*p_args[0]);
  576. if (buffer_size <= 0) {
  577. r_ret = decompressed;
  578. ERR_FAIL_MSG("Decompression buffer size must be greater than zero.");
  579. }
  580. if (ba->size() == 0) {
  581. r_ret = decompressed;
  582. ERR_FAIL_MSG("Compressed buffer size must be greater than zero.");
  583. }
  584. decompressed.resize(buffer_size);
  585. int result = Compression::decompress(decompressed.write().ptr(), buffer_size, ba->read().ptr(), ba->size(), mode);
  586. result = result >= 0 ? result : 0;
  587. decompressed.resize(result);
  588. r_ret = decompressed;
  589. }
  590. static void _call_PoolByteArray_decompress_dynamic(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  591. PoolByteArray *ba = reinterpret_cast<PoolByteArray *>(p_self._data._mem);
  592. PoolByteArray *decompressed = memnew(PoolByteArray);
  593. int max_output_size = (int)(*p_args[0]);
  594. Compression::Mode mode = (Compression::Mode)(int)(*p_args[1]);
  595. decompressed->resize(1024);
  596. int result = Compression::decompress_dynamic(decompressed, max_output_size, ba->read().ptr(), ba->size(), mode);
  597. if (result == OK) {
  598. r_ret = decompressed;
  599. } else {
  600. decompressed->resize(0);
  601. r_ret = decompressed;
  602. ERR_FAIL_MSG("Decompression failed.");
  603. }
  604. }
  605. static void _call_PoolByteArray_hex_encode(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  606. PoolByteArray *ba = reinterpret_cast<PoolByteArray *>(p_self._data._mem);
  607. if (ba->size() == 0) {
  608. r_ret = String();
  609. return;
  610. }
  611. PoolByteArray::Read r = ba->read();
  612. String s = String::hex_encode_buffer(&r[0], ba->size());
  613. r_ret = s;
  614. }
  615. VCALL_LOCALMEM0R(PoolByteArray, size);
  616. VCALL_LOCALMEM0R(PoolByteArray, empty);
  617. VCALL_LOCALMEM2(PoolByteArray, set);
  618. VCALL_LOCALMEM1R(PoolByteArray, get);
  619. VCALL_LOCALMEM1(PoolByteArray, push_back);
  620. VCALL_LOCALMEM1(PoolByteArray, resize);
  621. VCALL_LOCALMEM2R(PoolByteArray, insert);
  622. VCALL_LOCALMEM1(PoolByteArray, remove);
  623. VCALL_LOCALMEM1(PoolByteArray, append);
  624. VCALL_LOCALMEM1(PoolByteArray, append_array);
  625. VCALL_LOCALMEM0(PoolByteArray, invert);
  626. VCALL_LOCALMEM2R(PoolByteArray, subarray);
  627. VCALL_LOCALMEM0R(PoolIntArray, size);
  628. VCALL_LOCALMEM0R(PoolIntArray, empty);
  629. VCALL_LOCALMEM2(PoolIntArray, set);
  630. VCALL_LOCALMEM1R(PoolIntArray, get);
  631. VCALL_LOCALMEM1(PoolIntArray, push_back);
  632. VCALL_LOCALMEM1(PoolIntArray, resize);
  633. VCALL_LOCALMEM2R(PoolIntArray, insert);
  634. VCALL_LOCALMEM1(PoolIntArray, remove);
  635. VCALL_LOCALMEM1(PoolIntArray, append);
  636. VCALL_LOCALMEM1(PoolIntArray, append_array);
  637. VCALL_LOCALMEM0(PoolIntArray, invert);
  638. VCALL_LOCALMEM0R(PoolRealArray, size);
  639. VCALL_LOCALMEM0R(PoolRealArray, empty);
  640. VCALL_LOCALMEM2(PoolRealArray, set);
  641. VCALL_LOCALMEM1R(PoolRealArray, get);
  642. VCALL_LOCALMEM1(PoolRealArray, push_back);
  643. VCALL_LOCALMEM1(PoolRealArray, resize);
  644. VCALL_LOCALMEM2R(PoolRealArray, insert);
  645. VCALL_LOCALMEM1(PoolRealArray, remove);
  646. VCALL_LOCALMEM1(PoolRealArray, append);
  647. VCALL_LOCALMEM1(PoolRealArray, append_array);
  648. VCALL_LOCALMEM0(PoolRealArray, invert);
  649. VCALL_LOCALMEM0R(PoolStringArray, size);
  650. VCALL_LOCALMEM0R(PoolStringArray, empty);
  651. VCALL_LOCALMEM2(PoolStringArray, set);
  652. VCALL_LOCALMEM1R(PoolStringArray, get);
  653. VCALL_LOCALMEM1(PoolStringArray, push_back);
  654. VCALL_LOCALMEM1(PoolStringArray, resize);
  655. VCALL_LOCALMEM2R(PoolStringArray, insert);
  656. VCALL_LOCALMEM1(PoolStringArray, remove);
  657. VCALL_LOCALMEM1(PoolStringArray, append);
  658. VCALL_LOCALMEM1(PoolStringArray, append_array);
  659. VCALL_LOCALMEM0(PoolStringArray, invert);
  660. VCALL_LOCALMEM1R(PoolStringArray, join);
  661. VCALL_LOCALMEM0R(PoolVector2Array, size);
  662. VCALL_LOCALMEM0R(PoolVector2Array, empty);
  663. VCALL_LOCALMEM2(PoolVector2Array, set);
  664. VCALL_LOCALMEM1R(PoolVector2Array, get);
  665. VCALL_LOCALMEM1(PoolVector2Array, push_back);
  666. VCALL_LOCALMEM1(PoolVector2Array, resize);
  667. VCALL_LOCALMEM2R(PoolVector2Array, insert);
  668. VCALL_LOCALMEM1(PoolVector2Array, remove);
  669. VCALL_LOCALMEM1(PoolVector2Array, append);
  670. VCALL_LOCALMEM1(PoolVector2Array, append_array);
  671. VCALL_LOCALMEM0(PoolVector2Array, invert);
  672. VCALL_LOCALMEM0R(PoolVector3Array, size);
  673. VCALL_LOCALMEM0R(PoolVector3Array, empty);
  674. VCALL_LOCALMEM2(PoolVector3Array, set);
  675. VCALL_LOCALMEM1R(PoolVector3Array, get);
  676. VCALL_LOCALMEM1(PoolVector3Array, push_back);
  677. VCALL_LOCALMEM1(PoolVector3Array, resize);
  678. VCALL_LOCALMEM2R(PoolVector3Array, insert);
  679. VCALL_LOCALMEM1(PoolVector3Array, remove);
  680. VCALL_LOCALMEM1(PoolVector3Array, append);
  681. VCALL_LOCALMEM1(PoolVector3Array, append_array);
  682. VCALL_LOCALMEM0(PoolVector3Array, invert);
  683. VCALL_LOCALMEM0R(PoolColorArray, size);
  684. VCALL_LOCALMEM0R(PoolColorArray, empty);
  685. VCALL_LOCALMEM2(PoolColorArray, set);
  686. VCALL_LOCALMEM1R(PoolColorArray, get);
  687. VCALL_LOCALMEM1(PoolColorArray, push_back);
  688. VCALL_LOCALMEM1(PoolColorArray, resize);
  689. VCALL_LOCALMEM2R(PoolColorArray, insert);
  690. VCALL_LOCALMEM1(PoolColorArray, remove);
  691. VCALL_LOCALMEM1(PoolColorArray, append);
  692. VCALL_LOCALMEM1(PoolColorArray, append_array);
  693. VCALL_LOCALMEM0(PoolColorArray, invert);
  694. #define VCALL_PTR0(m_type, m_method) \
  695. static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(); }
  696. #define VCALL_PTR0R(m_type, m_method) \
  697. static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(); }
  698. #define VCALL_PTR1(m_type, m_method) \
  699. static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(*p_args[0]); }
  700. #define VCALL_PTR1R(m_type, m_method) \
  701. static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(*p_args[0]); }
  702. #define VCALL_PTR2(m_type, m_method) \
  703. static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(*p_args[0], *p_args[1]); }
  704. #define VCALL_PTR2R(m_type, m_method) \
  705. static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(*p_args[0], *p_args[1]); }
  706. #define VCALL_PTR3(m_type, m_method) \
  707. static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(*p_args[0], *p_args[1], *p_args[2]); }
  708. #define VCALL_PTR3R(m_type, m_method) \
  709. static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(*p_args[0], *p_args[1], *p_args[2]); }
  710. #define VCALL_PTR4(m_type, m_method) \
  711. static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(*p_args[0], *p_args[1], *p_args[2], *p_args[3]); }
  712. #define VCALL_PTR4R(m_type, m_method) \
  713. static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(*p_args[0], *p_args[1], *p_args[2], *p_args[3]); }
  714. #define VCALL_PTR5(m_type, m_method) \
  715. static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(*p_args[0], *p_args[1], *p_args[2], *p_args[3], *p_args[4]); }
  716. #define VCALL_PTR5R(m_type, m_method) \
  717. static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(*p_args[0], *p_args[1], *p_args[2], *p_args[3], *p_args[4]); }
  718. VCALL_PTR0R(AABB, abs);
  719. VCALL_PTR0R(AABB, get_area);
  720. VCALL_PTR0R(AABB, get_center);
  721. VCALL_PTR0R(AABB, has_no_area);
  722. VCALL_PTR0R(AABB, has_no_surface);
  723. VCALL_PTR1R(AABB, has_point);
  724. VCALL_PTR1R(AABB, is_equal_approx);
  725. VCALL_PTR1R(AABB, intersects);
  726. VCALL_PTR1R(AABB, encloses);
  727. VCALL_PTR1R(AABB, intersects_plane);
  728. VCALL_PTR2R(AABB, intersects_segment);
  729. VCALL_PTR1R(AABB, intersection);
  730. VCALL_PTR1R(AABB, merge);
  731. VCALL_PTR1R(AABB, expand);
  732. VCALL_PTR1R(AABB, grow);
  733. VCALL_PTR1R(AABB, get_support);
  734. VCALL_PTR0R(AABB, get_longest_axis);
  735. VCALL_PTR0R(AABB, get_longest_axis_index);
  736. VCALL_PTR0R(AABB, get_longest_axis_size);
  737. VCALL_PTR0R(AABB, get_shortest_axis);
  738. VCALL_PTR0R(AABB, get_shortest_axis_index);
  739. VCALL_PTR0R(AABB, get_shortest_axis_size);
  740. VCALL_PTR1R(AABB, get_endpoint);
  741. VCALL_PTR0R(Transform2D, inverse);
  742. VCALL_PTR0R(Transform2D, affine_inverse);
  743. VCALL_PTR0R(Transform2D, get_rotation);
  744. VCALL_PTR0R(Transform2D, get_origin);
  745. VCALL_PTR0R(Transform2D, get_scale);
  746. VCALL_PTR0R(Transform2D, orthonormalized);
  747. VCALL_PTR1R(Transform2D, rotated);
  748. VCALL_PTR1R(Transform2D, scaled);
  749. VCALL_PTR1R(Transform2D, translated);
  750. VCALL_PTR2R(Transform2D, interpolate_with);
  751. VCALL_PTR1R(Transform2D, is_equal_approx);
  752. static void _call_Transform2D_xform(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  753. switch (p_args[0]->type) {
  754. case Variant::VECTOR2:
  755. r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->xform(p_args[0]->operator Vector2());
  756. return;
  757. case Variant::RECT2:
  758. r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->xform(p_args[0]->operator Rect2());
  759. return;
  760. case Variant::POOL_VECTOR2_ARRAY:
  761. r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->xform(p_args[0]->operator PoolVector2Array());
  762. return;
  763. default:
  764. r_ret = Variant();
  765. }
  766. }
  767. static void _call_Transform2D_xform_inv(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  768. switch (p_args[0]->type) {
  769. case Variant::VECTOR2:
  770. r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->xform_inv(p_args[0]->operator Vector2());
  771. return;
  772. case Variant::RECT2:
  773. r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->xform_inv(p_args[0]->operator Rect2());
  774. return;
  775. case Variant::POOL_VECTOR2_ARRAY:
  776. r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->xform_inv(p_args[0]->operator PoolVector2Array());
  777. return;
  778. default:
  779. r_ret = Variant();
  780. }
  781. }
  782. static void _call_Transform2D_basis_xform(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  783. switch (p_args[0]->type) {
  784. case Variant::VECTOR2:
  785. r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->basis_xform(p_args[0]->operator Vector2());
  786. return;
  787. default:
  788. r_ret = Variant();
  789. }
  790. }
  791. static void _call_Transform2D_basis_xform_inv(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  792. switch (p_args[0]->type) {
  793. case Variant::VECTOR2:
  794. r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->basis_xform_inv(p_args[0]->operator Vector2());
  795. return;
  796. default:
  797. r_ret = Variant();
  798. }
  799. }
  800. VCALL_PTR0R(Basis, inverse);
  801. VCALL_PTR0R(Basis, transposed);
  802. VCALL_PTR0R(Basis, determinant);
  803. VCALL_PTR2R(Basis, rotated);
  804. VCALL_PTR1R(Basis, scaled);
  805. VCALL_PTR0R(Basis, get_scale);
  806. VCALL_PTR0R(Basis, get_euler);
  807. VCALL_PTR0R(Basis, get_euler_xyz);
  808. VCALL_PTR1(Basis, set_euler_xyz);
  809. VCALL_PTR0R(Basis, get_euler_xzy);
  810. VCALL_PTR1(Basis, set_euler_xzy);
  811. VCALL_PTR0R(Basis, get_euler_yzx);
  812. VCALL_PTR1(Basis, set_euler_yzx);
  813. VCALL_PTR0R(Basis, get_euler_yxz);
  814. VCALL_PTR1(Basis, set_euler_yxz);
  815. VCALL_PTR0R(Basis, get_euler_zxy);
  816. VCALL_PTR1(Basis, set_euler_zxy);
  817. VCALL_PTR0R(Basis, get_euler_zyx);
  818. VCALL_PTR1(Basis, set_euler_zyx);
  819. VCALL_PTR1R(Basis, tdotx);
  820. VCALL_PTR1R(Basis, tdoty);
  821. VCALL_PTR1R(Basis, tdotz);
  822. VCALL_PTR1R(Basis, xform);
  823. VCALL_PTR1R(Basis, xform_inv);
  824. VCALL_PTR0R(Basis, get_orthogonal_index);
  825. VCALL_PTR0R(Basis, orthonormalized);
  826. VCALL_PTR2R(Basis, slerp);
  827. VCALL_PTR2R(Basis, is_equal_approx);
  828. VCALL_PTR0R(Basis, get_rotation_quat);
  829. VCALL_PTR0R(Transform, inverse);
  830. VCALL_PTR0R(Transform, affine_inverse);
  831. VCALL_PTR2R(Transform, rotated);
  832. VCALL_PTR1R(Transform, scaled);
  833. VCALL_PTR1R(Transform, translated);
  834. VCALL_PTR0R(Transform, orthonormalized);
  835. VCALL_PTR2R(Transform, looking_at);
  836. VCALL_PTR2R(Transform, interpolate_with);
  837. VCALL_PTR1R(Transform, is_equal_approx);
  838. static void _call_Transform_xform(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  839. switch (p_args[0]->type) {
  840. case Variant::VECTOR3:
  841. r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform(p_args[0]->operator Vector3());
  842. return;
  843. case Variant::PLANE:
  844. r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform(p_args[0]->operator Plane());
  845. return;
  846. case Variant::AABB:
  847. r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform(p_args[0]->operator ::AABB());
  848. return;
  849. case Variant::POOL_VECTOR3_ARRAY:
  850. r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform(p_args[0]->operator ::PoolVector3Array());
  851. return;
  852. default:
  853. r_ret = Variant();
  854. }
  855. }
  856. static void _call_Transform_xform_inv(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  857. switch (p_args[0]->type) {
  858. case Variant::VECTOR3:
  859. r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform_inv(p_args[0]->operator Vector3());
  860. return;
  861. case Variant::PLANE:
  862. r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform_inv(p_args[0]->operator Plane());
  863. return;
  864. case Variant::AABB:
  865. r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform_inv(p_args[0]->operator ::AABB());
  866. return;
  867. case Variant::POOL_VECTOR3_ARRAY:
  868. r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform_inv(p_args[0]->operator ::PoolVector3Array());
  869. return;
  870. default:
  871. r_ret = Variant();
  872. }
  873. }
  874. /*
  875. VCALL_PTR0( Transform, invert );
  876. VCALL_PTR0( Transform, affine_invert );
  877. VCALL_PTR2( Transform, rotate );
  878. VCALL_PTR1( Transform, scale );
  879. VCALL_PTR1( Transform, translate );
  880. VCALL_PTR0( Transform, orthonormalize ); */
  881. struct ConstructData {
  882. int arg_count;
  883. Vector<Variant::Type> arg_types;
  884. Vector<String> arg_names;
  885. VariantConstructFunc func;
  886. };
  887. struct ConstructFunc {
  888. List<ConstructData> constructors;
  889. };
  890. static ConstructFunc *construct_funcs;
  891. static void Vector2_init1(Variant &r_ret, const Variant **p_args) {
  892. r_ret = Vector2(*p_args[0], *p_args[1]);
  893. }
  894. static void Rect2_init1(Variant &r_ret, const Variant **p_args) {
  895. r_ret = Rect2(*p_args[0], *p_args[1]);
  896. }
  897. static void Rect2_init2(Variant &r_ret, const Variant **p_args) {
  898. r_ret = Rect2(*p_args[0], *p_args[1], *p_args[2], *p_args[3]);
  899. }
  900. static void Transform2D_init2(Variant &r_ret, const Variant **p_args) {
  901. Transform2D m(*p_args[0], *p_args[1]);
  902. r_ret = m;
  903. }
  904. static void Transform2D_init3(Variant &r_ret, const Variant **p_args) {
  905. Transform2D m;
  906. m[0] = *p_args[0];
  907. m[1] = *p_args[1];
  908. m[2] = *p_args[2];
  909. r_ret = m;
  910. }
  911. static void Vector3_init1(Variant &r_ret, const Variant **p_args) {
  912. r_ret = Vector3(*p_args[0], *p_args[1], *p_args[2]);
  913. }
  914. static void Plane_init1(Variant &r_ret, const Variant **p_args) {
  915. r_ret = Plane(*p_args[0], *p_args[1], *p_args[2], *p_args[3]);
  916. }
  917. static void Plane_init2(Variant &r_ret, const Variant **p_args) {
  918. r_ret = Plane(*p_args[0], *p_args[1], *p_args[2]);
  919. }
  920. static void Plane_init3(Variant &r_ret, const Variant **p_args) {
  921. r_ret = Plane(p_args[0]->operator Vector3(), p_args[1]->operator real_t());
  922. }
  923. static void Plane_init4(Variant &r_ret, const Variant **p_args) {
  924. r_ret = Plane(p_args[0]->operator Vector3(), p_args[1]->operator Vector3());
  925. }
  926. static void Quat_init1(Variant &r_ret, const Variant **p_args) {
  927. r_ret = Quat(*p_args[0], *p_args[1], *p_args[2], *p_args[3]);
  928. }
  929. static void Quat_init2(Variant &r_ret, const Variant **p_args) {
  930. r_ret = Quat(((Vector3)(*p_args[0])), ((real_t)(*p_args[1])));
  931. }
  932. static void Quat_init3(Variant &r_ret, const Variant **p_args) {
  933. r_ret = Quat(((Vector3)(*p_args[0])));
  934. }
  935. static void Color_init1(Variant &r_ret, const Variant **p_args) {
  936. r_ret = Color(*p_args[0], *p_args[1], *p_args[2], *p_args[3]);
  937. }
  938. static void Color_init2(Variant &r_ret, const Variant **p_args) {
  939. r_ret = Color(*p_args[0], *p_args[1], *p_args[2]);
  940. }
  941. static void Color_init3(Variant &r_ret, const Variant **p_args) {
  942. r_ret = Color::html(*p_args[0]);
  943. }
  944. static void Color_init4(Variant &r_ret, const Variant **p_args) {
  945. r_ret = Color::hex(*p_args[0]);
  946. }
  947. static void AABB_init1(Variant &r_ret, const Variant **p_args) {
  948. r_ret = ::AABB(*p_args[0], *p_args[1]);
  949. }
  950. static void Basis_init1(Variant &r_ret, const Variant **p_args) {
  951. Basis m;
  952. m.set_axis(0, *p_args[0]);
  953. m.set_axis(1, *p_args[1]);
  954. m.set_axis(2, *p_args[2]);
  955. r_ret = m;
  956. }
  957. static void Basis_init2(Variant &r_ret, const Variant **p_args) {
  958. r_ret = Basis(p_args[0]->operator Vector3(), p_args[1]->operator real_t());
  959. }
  960. static void Transform_init1(Variant &r_ret, const Variant **p_args) {
  961. Transform t;
  962. t.basis.set_axis(0, *p_args[0]);
  963. t.basis.set_axis(1, *p_args[1]);
  964. t.basis.set_axis(2, *p_args[2]);
  965. t.origin = *p_args[3];
  966. r_ret = t;
  967. }
  968. static void Transform_init2(Variant &r_ret, const Variant **p_args) {
  969. r_ret = Transform(p_args[0]->operator Basis(), p_args[1]->operator Vector3());
  970. }
  971. static void add_constructor(VariantConstructFunc p_func, const Variant::Type p_type,
  972. const String &p_name1 = "", const Variant::Type p_type1 = Variant::NIL,
  973. const String &p_name2 = "", const Variant::Type p_type2 = Variant::NIL,
  974. const String &p_name3 = "", const Variant::Type p_type3 = Variant::NIL,
  975. const String &p_name4 = "", const Variant::Type p_type4 = Variant::NIL) {
  976. ConstructData cd;
  977. cd.func = p_func;
  978. cd.arg_count = 0;
  979. if (p_name1 == "") {
  980. goto end;
  981. }
  982. cd.arg_count++;
  983. cd.arg_names.push_back(p_name1);
  984. cd.arg_types.push_back(p_type1);
  985. if (p_name2 == "") {
  986. goto end;
  987. }
  988. cd.arg_count++;
  989. cd.arg_names.push_back(p_name2);
  990. cd.arg_types.push_back(p_type2);
  991. if (p_name3 == "") {
  992. goto end;
  993. }
  994. cd.arg_count++;
  995. cd.arg_names.push_back(p_name3);
  996. cd.arg_types.push_back(p_type3);
  997. if (p_name4 == "") {
  998. goto end;
  999. }
  1000. cd.arg_count++;
  1001. cd.arg_names.push_back(p_name4);
  1002. cd.arg_types.push_back(p_type4);
  1003. end:
  1004. construct_funcs[p_type].constructors.push_back(cd);
  1005. }
  1006. struct ConstantData {
  1007. Map<StringName, int> value;
  1008. #ifdef DEBUG_ENABLED
  1009. List<StringName> value_ordered;
  1010. #endif
  1011. Map<StringName, Variant> variant_value;
  1012. #ifdef DEBUG_ENABLED
  1013. List<StringName> variant_value_ordered;
  1014. #endif
  1015. };
  1016. static ConstantData *constant_data;
  1017. static void add_constant(int p_type, StringName p_constant_name, int p_constant_value) {
  1018. constant_data[p_type].value[p_constant_name] = p_constant_value;
  1019. #ifdef DEBUG_ENABLED
  1020. constant_data[p_type].value_ordered.push_back(p_constant_name);
  1021. #endif
  1022. }
  1023. static void add_variant_constant(int p_type, StringName p_constant_name, const Variant &p_constant_value) {
  1024. constant_data[p_type].variant_value[p_constant_name] = p_constant_value;
  1025. #ifdef DEBUG_ENABLED
  1026. constant_data[p_type].variant_value_ordered.push_back(p_constant_name);
  1027. #endif
  1028. }
  1029. };
  1030. _VariantCall::TypeFunc *_VariantCall::type_funcs = nullptr;
  1031. _VariantCall::ConstructFunc *_VariantCall::construct_funcs = nullptr;
  1032. _VariantCall::ConstantData *_VariantCall::constant_data = nullptr;
  1033. Variant Variant::call(const StringName &p_method, const Variant **p_args, int p_argcount, CallError &r_error) {
  1034. Variant ret;
  1035. call_ptr(p_method, p_args, p_argcount, &ret, r_error);
  1036. return ret;
  1037. }
  1038. void Variant::call_ptr(const StringName &p_method, const Variant **p_args, int p_argcount, Variant *r_ret, CallError &r_error) {
  1039. Variant ret;
  1040. if (type == Variant::OBJECT) {
  1041. //call object
  1042. Object *obj = _OBJ_PTR(*this);
  1043. if (unlikely(!obj)) {
  1044. #ifdef DEBUG_ENABLED
  1045. if (_get_obj().rc) {
  1046. ERR_PRINT("Attempted method call on a deleted object.");
  1047. }
  1048. #endif
  1049. r_error.error = CallError::CALL_ERROR_INSTANCE_IS_NULL;
  1050. return;
  1051. }
  1052. ret = obj->call(p_method, p_args, p_argcount, r_error);
  1053. //else if (type==Variant::METHOD) {
  1054. } else {
  1055. r_error.error = Variant::CallError::CALL_OK;
  1056. Map<StringName, _VariantCall::FuncData>::Element *E = _VariantCall::type_funcs[type].functions.find(p_method);
  1057. #ifdef DEBUG_ENABLED
  1058. if (!E) {
  1059. r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
  1060. return;
  1061. }
  1062. #endif
  1063. _VariantCall::FuncData &funcdata = E->get();
  1064. funcdata.call(ret, *this, p_args, p_argcount, r_error);
  1065. }
  1066. if (r_error.error == Variant::CallError::CALL_OK && r_ret) {
  1067. *r_ret = ret;
  1068. }
  1069. }
  1070. #define VCALL(m_type, m_method) _VariantCall::_call_##m_type##_##m_method
  1071. Variant Variant::construct(const Variant::Type p_type, const Variant **p_args, int p_argcount, CallError &r_error, bool p_strict) {
  1072. r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
  1073. ERR_FAIL_INDEX_V(p_type, VARIANT_MAX, Variant());
  1074. r_error.error = Variant::CallError::CALL_OK;
  1075. if (p_argcount == 0) { //generic construct
  1076. switch (p_type) {
  1077. case NIL:
  1078. return Variant();
  1079. // atomic types
  1080. case BOOL:
  1081. return Variant(false);
  1082. case INT:
  1083. return 0;
  1084. case REAL:
  1085. return 0.0f;
  1086. case STRING:
  1087. return String();
  1088. // math types
  1089. case VECTOR2:
  1090. return Vector2(); // 5
  1091. case RECT2:
  1092. return Rect2();
  1093. case VECTOR3:
  1094. return Vector3();
  1095. case TRANSFORM2D:
  1096. return Transform2D();
  1097. case PLANE:
  1098. return Plane();
  1099. case QUAT:
  1100. return Quat();
  1101. case AABB:
  1102. return ::AABB(); // 10
  1103. case BASIS:
  1104. return Basis();
  1105. case TRANSFORM:
  1106. return Transform();
  1107. // misc types
  1108. case COLOR:
  1109. return Color();
  1110. case NODE_PATH:
  1111. return NodePath(); // 15
  1112. case _RID:
  1113. return RID();
  1114. case OBJECT:
  1115. return (Object *)nullptr;
  1116. case DICTIONARY:
  1117. return Dictionary();
  1118. case ARRAY:
  1119. return Array(); // 20
  1120. case POOL_BYTE_ARRAY:
  1121. return PoolByteArray();
  1122. case POOL_INT_ARRAY:
  1123. return PoolIntArray();
  1124. case POOL_REAL_ARRAY:
  1125. return PoolRealArray();
  1126. case POOL_STRING_ARRAY:
  1127. return PoolStringArray();
  1128. case POOL_VECTOR2_ARRAY:
  1129. return PoolVector2Array(); // 25
  1130. case POOL_VECTOR3_ARRAY:
  1131. return PoolVector3Array();
  1132. case POOL_COLOR_ARRAY:
  1133. return PoolColorArray();
  1134. default:
  1135. return Variant();
  1136. }
  1137. } else if (p_argcount == 1 && p_args[0]->type == p_type) {
  1138. return *p_args[0]; //copy construct
  1139. } else if (p_argcount == 1 && (!p_strict || Variant::can_convert(p_args[0]->type, p_type))) {
  1140. //near match construct
  1141. switch (p_type) {
  1142. case NIL: {
  1143. return Variant();
  1144. } break;
  1145. case BOOL: {
  1146. return Variant(bool(*p_args[0]));
  1147. }
  1148. case INT: {
  1149. return (int64_t(*p_args[0]));
  1150. }
  1151. case REAL: {
  1152. return double(*p_args[0]);
  1153. }
  1154. case STRING: {
  1155. return String(*p_args[0]);
  1156. }
  1157. case VECTOR2: {
  1158. return Vector2(*p_args[0]);
  1159. }
  1160. case RECT2:
  1161. return (Rect2(*p_args[0]));
  1162. case VECTOR3:
  1163. return (Vector3(*p_args[0]));
  1164. case TRANSFORM2D:
  1165. return (Transform2D(p_args[0]->operator Transform2D()));
  1166. case PLANE:
  1167. return (Plane(*p_args[0]));
  1168. case QUAT:
  1169. return (p_args[0]->operator Quat());
  1170. case AABB:
  1171. return (::AABB(*p_args[0])); // 10
  1172. case BASIS:
  1173. return (Basis(p_args[0]->operator Basis()));
  1174. case TRANSFORM:
  1175. return (Transform(p_args[0]->operator Transform()));
  1176. // misc types
  1177. case COLOR:
  1178. return p_args[0]->type == Variant::STRING ? Color::html(*p_args[0]) : Color::hex(*p_args[0]);
  1179. case NODE_PATH:
  1180. return (NodePath(p_args[0]->operator NodePath())); // 15
  1181. case _RID:
  1182. return (RID(*p_args[0]));
  1183. case OBJECT:
  1184. return ((Object *)(p_args[0]->operator Object *()));
  1185. case DICTIONARY:
  1186. return p_args[0]->operator Dictionary();
  1187. case ARRAY:
  1188. return p_args[0]->operator Array(); // 20
  1189. // arrays
  1190. case POOL_BYTE_ARRAY:
  1191. return (PoolByteArray(*p_args[0]));
  1192. case POOL_INT_ARRAY:
  1193. return (PoolIntArray(*p_args[0]));
  1194. case POOL_REAL_ARRAY:
  1195. return (PoolRealArray(*p_args[0]));
  1196. case POOL_STRING_ARRAY:
  1197. return (PoolStringArray(*p_args[0]));
  1198. case POOL_VECTOR2_ARRAY:
  1199. return (PoolVector2Array(*p_args[0])); // 25
  1200. case POOL_VECTOR3_ARRAY:
  1201. return (PoolVector3Array(*p_args[0]));
  1202. case POOL_COLOR_ARRAY:
  1203. return (PoolColorArray(*p_args[0]));
  1204. default:
  1205. return Variant();
  1206. }
  1207. } else if (p_argcount >= 1) {
  1208. _VariantCall::ConstructFunc &c = _VariantCall::construct_funcs[p_type];
  1209. for (List<_VariantCall::ConstructData>::Element *E = c.constructors.front(); E; E = E->next()) {
  1210. const _VariantCall::ConstructData &cd = E->get();
  1211. if (cd.arg_count != p_argcount) {
  1212. continue;
  1213. }
  1214. //validate parameters
  1215. for (int i = 0; i < cd.arg_count; i++) {
  1216. if (!Variant::can_convert(p_args[i]->type, cd.arg_types[i])) {
  1217. r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; //no such constructor
  1218. r_error.argument = i;
  1219. r_error.expected = cd.arg_types[i];
  1220. return Variant();
  1221. }
  1222. }
  1223. Variant v;
  1224. cd.func(v, p_args);
  1225. return v;
  1226. }
  1227. }
  1228. r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; //no such constructor
  1229. return Variant();
  1230. }
  1231. bool Variant::has_method(const StringName &p_method) const {
  1232. if (type == OBJECT) {
  1233. Object *obj = _OBJ_PTR(*this);
  1234. if (unlikely(!obj)) {
  1235. #ifdef DEBUG_ENABLED
  1236. if (_get_obj().rc) {
  1237. ERR_PRINT("Attempted method check on a deleted object.");
  1238. }
  1239. #endif
  1240. return false;
  1241. }
  1242. return obj->has_method(p_method);
  1243. }
  1244. const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[type];
  1245. return tf.functions.has(p_method);
  1246. }
  1247. Vector<Variant::Type> Variant::get_method_argument_types(Variant::Type p_type, const StringName &p_method) {
  1248. const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type];
  1249. const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method);
  1250. if (!E) {
  1251. return Vector<Variant::Type>();
  1252. }
  1253. return E->get().arg_types;
  1254. }
  1255. bool Variant::is_method_const(Variant::Type p_type, const StringName &p_method) {
  1256. const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type];
  1257. const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method);
  1258. if (!E) {
  1259. return false;
  1260. }
  1261. return E->get()._const;
  1262. }
  1263. Vector<StringName> Variant::get_method_argument_names(Variant::Type p_type, const StringName &p_method) {
  1264. const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type];
  1265. const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method);
  1266. if (!E) {
  1267. return Vector<StringName>();
  1268. }
  1269. return E->get().arg_names;
  1270. }
  1271. Variant::Type Variant::get_method_return_type(Variant::Type p_type, const StringName &p_method, bool *r_has_return) {
  1272. const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type];
  1273. const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method);
  1274. if (!E) {
  1275. return Variant::NIL;
  1276. }
  1277. if (r_has_return) {
  1278. *r_has_return = E->get().returns;
  1279. }
  1280. return E->get().return_type;
  1281. }
  1282. Vector<Variant> Variant::get_method_default_arguments(Variant::Type p_type, const StringName &p_method) {
  1283. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, Vector<Variant>());
  1284. const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type];
  1285. const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method);
  1286. ERR_FAIL_COND_V(!E, Vector<Variant>());
  1287. return E->get().default_args;
  1288. }
  1289. void Variant::get_method_list(List<MethodInfo> *p_list) const {
  1290. const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[type];
  1291. for (const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.front(); E; E = E->next()) {
  1292. const _VariantCall::FuncData &fd = E->get();
  1293. MethodInfo mi;
  1294. mi.name = E->key();
  1295. if (fd._const) {
  1296. mi.flags |= METHOD_FLAG_CONST;
  1297. }
  1298. for (int i = 0; i < fd.arg_types.size(); i++) {
  1299. PropertyInfo pi;
  1300. pi.type = fd.arg_types[i];
  1301. #ifdef DEBUG_ENABLED
  1302. pi.name = fd.arg_names[i];
  1303. #endif
  1304. mi.arguments.push_back(pi);
  1305. }
  1306. mi.default_arguments = fd.default_args;
  1307. PropertyInfo ret;
  1308. #ifdef DEBUG_ENABLED
  1309. ret.type = fd.return_type;
  1310. if (fd.returns) {
  1311. ret.name = "ret";
  1312. }
  1313. mi.return_val = ret;
  1314. #endif
  1315. p_list->push_back(mi);
  1316. }
  1317. }
  1318. void Variant::get_constructor_list(Variant::Type p_type, List<MethodInfo> *p_list) {
  1319. ERR_FAIL_INDEX(p_type, VARIANT_MAX);
  1320. //custom constructors
  1321. for (const List<_VariantCall::ConstructData>::Element *E = _VariantCall::construct_funcs[p_type].constructors.front(); E; E = E->next()) {
  1322. const _VariantCall::ConstructData &cd = E->get();
  1323. MethodInfo mi;
  1324. mi.name = Variant::get_type_name(p_type);
  1325. mi.return_val.type = p_type;
  1326. for (int i = 0; i < cd.arg_count; i++) {
  1327. PropertyInfo pi;
  1328. pi.name = cd.arg_names[i];
  1329. pi.type = cd.arg_types[i];
  1330. mi.arguments.push_back(pi);
  1331. }
  1332. p_list->push_back(mi);
  1333. }
  1334. //default constructors
  1335. for (int i = 0; i < VARIANT_MAX; i++) {
  1336. if (i == p_type) {
  1337. continue;
  1338. }
  1339. if (!Variant::can_convert(Variant::Type(i), p_type)) {
  1340. continue;
  1341. }
  1342. MethodInfo mi;
  1343. mi.name = Variant::get_type_name(p_type);
  1344. PropertyInfo pi;
  1345. pi.name = "from";
  1346. pi.type = Variant::Type(i);
  1347. mi.arguments.push_back(pi);
  1348. mi.return_val.type = p_type;
  1349. p_list->push_back(mi);
  1350. }
  1351. }
  1352. void Variant::get_constants_for_type(Variant::Type p_type, List<StringName> *p_constants) {
  1353. ERR_FAIL_INDEX(p_type, Variant::VARIANT_MAX);
  1354. _VariantCall::ConstantData &cd = _VariantCall::constant_data[p_type];
  1355. #ifdef DEBUG_ENABLED
  1356. for (List<StringName>::Element *E = cd.value_ordered.front(); E; E = E->next()) {
  1357. p_constants->push_back(E->get());
  1358. #else
  1359. for (Map<StringName, int>::Element *E = cd.value.front(); E; E = E->next()) {
  1360. p_constants->push_back(E->key());
  1361. #endif
  1362. }
  1363. #ifdef DEBUG_ENABLED
  1364. for (List<StringName>::Element *E = cd.variant_value_ordered.front(); E; E = E->next()) {
  1365. p_constants->push_back(E->get());
  1366. #else
  1367. for (Map<StringName, Variant>::Element *E = cd.variant_value.front(); E; E = E->next()) {
  1368. p_constants->push_back(E->key());
  1369. #endif
  1370. }
  1371. }
  1372. bool Variant::has_constant(Variant::Type p_type, const StringName &p_value) {
  1373. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, false);
  1374. _VariantCall::ConstantData &cd = _VariantCall::constant_data[p_type];
  1375. return cd.value.has(p_value) || cd.variant_value.has(p_value);
  1376. }
  1377. Variant Variant::get_constant_value(Variant::Type p_type, const StringName &p_value, bool *r_valid) {
  1378. if (r_valid) {
  1379. *r_valid = false;
  1380. }
  1381. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, 0);
  1382. _VariantCall::ConstantData &cd = _VariantCall::constant_data[p_type];
  1383. Map<StringName, int>::Element *E = cd.value.find(p_value);
  1384. if (!E) {
  1385. Map<StringName, Variant>::Element *F = cd.variant_value.find(p_value);
  1386. if (F) {
  1387. if (r_valid) {
  1388. *r_valid = true;
  1389. }
  1390. return F->get();
  1391. } else {
  1392. return -1;
  1393. }
  1394. }
  1395. if (r_valid) {
  1396. *r_valid = true;
  1397. }
  1398. return E->get();
  1399. }
  1400. void register_variant_methods() {
  1401. _VariantCall::type_funcs = memnew_arr(_VariantCall::TypeFunc, Variant::VARIANT_MAX);
  1402. _VariantCall::construct_funcs = memnew_arr(_VariantCall::ConstructFunc, Variant::VARIANT_MAX);
  1403. _VariantCall::constant_data = memnew_arr(_VariantCall::ConstantData, Variant::VARIANT_MAX);
  1404. #define ADDFUNC0R(m_vtype, m_ret, m_class, m_method, m_defarg) \
  1405. _VariantCall::addfunc(true, Variant::m_vtype, Variant::m_ret, true, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg);
  1406. #define ADDFUNC1R(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_defarg) \
  1407. _VariantCall::addfunc(true, Variant::m_vtype, Variant::m_ret, true, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)));
  1408. #define ADDFUNC2R(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_defarg) \
  1409. _VariantCall::addfunc(true, Variant::m_vtype, Variant::m_ret, true, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2)));
  1410. #define ADDFUNC3R(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_arg3, m_argname3, m_defarg) \
  1411. _VariantCall::addfunc(true, Variant::m_vtype, Variant::m_ret, true, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2)), _VariantCall::Arg(Variant::m_arg3, _scs_create(m_argname3)));
  1412. #define ADDFUNC4R(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_arg3, m_argname3, m_arg4, m_argname4, m_defarg) \
  1413. _VariantCall::addfunc(true, Variant::m_vtype, Variant::m_ret, true, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2)), _VariantCall::Arg(Variant::m_arg3, _scs_create(m_argname3)), _VariantCall::Arg(Variant::m_arg4, _scs_create(m_argname4)));
  1414. #define ADDFUNC0RNC(m_vtype, m_ret, m_class, m_method, m_defarg) \
  1415. _VariantCall::addfunc(false, Variant::m_vtype, Variant::m_ret, true, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg);
  1416. #define ADDFUNC1RNC(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_defarg) \
  1417. _VariantCall::addfunc(false, Variant::m_vtype, Variant::m_ret, true, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)));
  1418. #define ADDFUNC2RNC(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_defarg) \
  1419. _VariantCall::addfunc(false, Variant::m_vtype, Variant::m_ret, true, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2)));
  1420. #define ADDFUNC3RNC(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_arg3, m_argname3, m_defarg) \
  1421. _VariantCall::addfunc(false, Variant::m_vtype, Variant::m_ret, true, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2)), _VariantCall::Arg(Variant::m_arg3, _scs_create(m_argname3)));
  1422. #define ADDFUNC4RNC(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_arg3, m_argname3, m_arg4, m_argname4, m_defarg) \
  1423. _VariantCall::addfunc(false, Variant::m_vtype, Variant::m_ret, true, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2)), _VariantCall::Arg(Variant::m_arg3, _scs_create(m_argname3)), _VariantCall::Arg(Variant::m_arg4, _scs_create(m_argname4)));
  1424. #define ADDFUNC0(m_vtype, m_ret, m_class, m_method, m_defarg) \
  1425. _VariantCall::addfunc(true, Variant::m_vtype, Variant::m_ret, false, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg);
  1426. #define ADDFUNC1(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_defarg) \
  1427. _VariantCall::addfunc(true, Variant::m_vtype, Variant::m_ret, false, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)));
  1428. #define ADDFUNC2(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_defarg) \
  1429. _VariantCall::addfunc(true, Variant::m_vtype, Variant::m_ret, false, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2)));
  1430. #define ADDFUNC3(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_arg3, m_argname3, m_defarg) \
  1431. _VariantCall::addfunc(true, Variant::m_vtype, Variant::m_ret, false, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2)), _VariantCall::Arg(Variant::m_arg3, _scs_create(m_argname3)));
  1432. #define ADDFUNC4(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_arg3, m_argname3, m_arg4, m_argname4, m_defarg) \
  1433. _VariantCall::addfunc(true, Variant::m_vtype, Variant::m_ret, false, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2)), _VariantCall::Arg(Variant::m_arg3, _scs_create(m_argname3)), _VariantCall::Arg(Variant::m_arg4, _scs_create(m_argname4)));
  1434. #define ADDFUNC0NC(m_vtype, m_ret, m_class, m_method, m_defarg) \
  1435. _VariantCall::addfunc(false, Variant::m_vtype, Variant::m_ret, false, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg);
  1436. #define ADDFUNC1NC(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_defarg) \
  1437. _VariantCall::addfunc(false, Variant::m_vtype, Variant::m_ret, false, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)));
  1438. #define ADDFUNC2NC(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_defarg) \
  1439. _VariantCall::addfunc(false, Variant::m_vtype, Variant::m_ret, false, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2)));
  1440. #define ADDFUNC3NC(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_arg3, m_argname3, m_defarg) \
  1441. _VariantCall::addfunc(false, Variant::m_vtype, Variant::m_ret, false, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2)), _VariantCall::Arg(Variant::m_arg3, _scs_create(m_argname3)));
  1442. #define ADDFUNC4NC(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_arg3, m_argname3, m_arg4, m_argname4, m_defarg) \
  1443. _VariantCall::addfunc(false, Variant::m_vtype, Variant::m_ret, false, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2)), _VariantCall::Arg(Variant::m_arg3, _scs_create(m_argname3)), _VariantCall::Arg(Variant::m_arg4, _scs_create(m_argname4)));
  1444. /* STRING */
  1445. ADDFUNC1R(STRING, INT, String, casecmp_to, STRING, "to", varray());
  1446. ADDFUNC1R(STRING, INT, String, nocasecmp_to, STRING, "to", varray());
  1447. ADDFUNC1R(STRING, INT, String, naturalnocasecmp_to, STRING, "to", varray());
  1448. ADDFUNC0R(STRING, INT, String, length, varray());
  1449. ADDFUNC2R(STRING, STRING, String, substr, INT, "from", INT, "len", varray(-1));
  1450. ADDFUNC2R(STRING, STRING, String, get_slice, STRING, "delimiter", INT, "slice", varray());
  1451. ADDFUNC2R(STRING, INT, String, find, STRING, "what", INT, "from", varray(0));
  1452. ADDFUNC3R(STRING, INT, String, count, STRING, "what", INT, "from", INT, "to", varray(0, 0));
  1453. ADDFUNC3R(STRING, INT, String, countn, STRING, "what", INT, "from", INT, "to", varray(0, 0));
  1454. ADDFUNC1R(STRING, INT, String, find_last, STRING, "what", varray());
  1455. ADDFUNC2R(STRING, INT, String, findn, STRING, "what", INT, "from", varray(0));
  1456. ADDFUNC2R(STRING, INT, String, rfind, STRING, "what", INT, "from", varray(-1));
  1457. ADDFUNC2R(STRING, INT, String, rfindn, STRING, "what", INT, "from", varray(-1));
  1458. ADDFUNC1R(STRING, BOOL, String, match, STRING, "expr", varray());
  1459. ADDFUNC1R(STRING, BOOL, String, matchn, STRING, "expr", varray());
  1460. ADDFUNC1R(STRING, BOOL, String, begins_with, STRING, "text", varray());
  1461. ADDFUNC1R(STRING, BOOL, String, ends_with, STRING, "text", varray());
  1462. ADDFUNC1R(STRING, BOOL, String, is_subsequence_of, STRING, "text", varray());
  1463. ADDFUNC1R(STRING, BOOL, String, is_subsequence_ofi, STRING, "text", varray());
  1464. ADDFUNC0R(STRING, POOL_STRING_ARRAY, String, bigrams, varray());
  1465. ADDFUNC1R(STRING, REAL, String, similarity, STRING, "text", varray());
  1466. ADDFUNC2R(STRING, STRING, String, format, NIL, "values", STRING, "placeholder", varray("{_}"));
  1467. ADDFUNC2R(STRING, STRING, String, replace, STRING, "what", STRING, "forwhat", varray());
  1468. ADDFUNC2R(STRING, STRING, String, replacen, STRING, "what", STRING, "forwhat", varray());
  1469. ADDFUNC1R(STRING, STRING, String, repeat, INT, "count", varray());
  1470. ADDFUNC2R(STRING, STRING, String, insert, INT, "position", STRING, "what", varray());
  1471. ADDFUNC0R(STRING, STRING, String, capitalize, varray());
  1472. ADDFUNC3R(STRING, POOL_STRING_ARRAY, String, split, STRING, "delimiter", BOOL, "allow_empty", INT, "maxsplit", varray(true, 0));
  1473. ADDFUNC3R(STRING, POOL_STRING_ARRAY, String, rsplit, STRING, "delimiter", BOOL, "allow_empty", INT, "maxsplit", varray(true, 0));
  1474. ADDFUNC2R(STRING, POOL_REAL_ARRAY, String, split_floats, STRING, "delimiter", BOOL, "allow_empty", varray(true));
  1475. ADDFUNC0R(STRING, STRING, String, to_upper, varray());
  1476. ADDFUNC0R(STRING, STRING, String, to_lower, varray());
  1477. ADDFUNC1R(STRING, STRING, String, left, INT, "position", varray());
  1478. ADDFUNC1R(STRING, STRING, String, right, INT, "position", varray());
  1479. ADDFUNC2R(STRING, STRING, String, strip_edges, BOOL, "left", BOOL, "right", varray(true, true));
  1480. ADDFUNC0R(STRING, STRING, String, strip_escapes, varray());
  1481. ADDFUNC1R(STRING, STRING, String, lstrip, STRING, "chars", varray());
  1482. ADDFUNC1R(STRING, STRING, String, rstrip, STRING, "chars", varray());
  1483. ADDFUNC0R(STRING, STRING, String, get_extension, varray());
  1484. ADDFUNC0R(STRING, STRING, String, get_basename, varray());
  1485. ADDFUNC1R(STRING, STRING, String, plus_file, STRING, "file", varray());
  1486. ADDFUNC1R(STRING, INT, String, ord_at, INT, "at", varray());
  1487. ADDFUNC0R(STRING, STRING, String, dedent, varray());
  1488. ADDFUNC2(STRING, NIL, String, erase, INT, "position", INT, "chars", varray());
  1489. ADDFUNC0R(STRING, INT, String, hash, varray());
  1490. ADDFUNC0R(STRING, STRING, String, md5_text, varray());
  1491. ADDFUNC0R(STRING, STRING, String, sha1_text, varray());
  1492. ADDFUNC0R(STRING, STRING, String, sha256_text, varray());
  1493. ADDFUNC0R(STRING, POOL_BYTE_ARRAY, String, md5_buffer, varray());
  1494. ADDFUNC0R(STRING, POOL_BYTE_ARRAY, String, sha1_buffer, varray());
  1495. ADDFUNC0R(STRING, POOL_BYTE_ARRAY, String, sha256_buffer, varray());
  1496. ADDFUNC0R(STRING, BOOL, String, empty, varray());
  1497. ADDFUNC1R(STRING, STRING, String, humanize_size, INT, "size", varray());
  1498. ADDFUNC0R(STRING, BOOL, String, is_abs_path, varray());
  1499. ADDFUNC0R(STRING, STRING, String, simplify_path, varray());
  1500. ADDFUNC0R(STRING, BOOL, String, is_rel_path, varray());
  1501. ADDFUNC0R(STRING, STRING, String, get_base_dir, varray());
  1502. ADDFUNC0R(STRING, STRING, String, get_file, varray());
  1503. ADDFUNC0R(STRING, STRING, String, xml_escape, varray());
  1504. ADDFUNC0R(STRING, STRING, String, xml_unescape, varray());
  1505. ADDFUNC0R(STRING, STRING, String, http_escape, varray());
  1506. ADDFUNC0R(STRING, STRING, String, http_unescape, varray());
  1507. ADDFUNC0R(STRING, STRING, String, c_escape, varray());
  1508. ADDFUNC0R(STRING, STRING, String, c_unescape, varray());
  1509. ADDFUNC0R(STRING, STRING, String, json_escape, varray());
  1510. ADDFUNC0R(STRING, STRING, String, percent_encode, varray());
  1511. ADDFUNC0R(STRING, STRING, String, percent_decode, varray());
  1512. ADDFUNC0R(STRING, STRING, String, validate_node_name, varray());
  1513. ADDFUNC0R(STRING, BOOL, String, is_valid_identifier, varray());
  1514. ADDFUNC0R(STRING, BOOL, String, is_valid_integer, varray());
  1515. ADDFUNC0R(STRING, BOOL, String, is_valid_float, varray());
  1516. ADDFUNC1R(STRING, BOOL, String, is_valid_hex_number, BOOL, "with_prefix", varray(false));
  1517. ADDFUNC0R(STRING, BOOL, String, is_valid_html_color, varray());
  1518. ADDFUNC0R(STRING, BOOL, String, is_valid_ip_address, varray());
  1519. ADDFUNC0R(STRING, BOOL, String, is_valid_filename, varray());
  1520. ADDFUNC0R(STRING, INT, String, to_int, varray());
  1521. ADDFUNC0R(STRING, REAL, String, to_float, varray());
  1522. ADDFUNC0R(STRING, INT, String, hex_to_int, varray());
  1523. ADDFUNC1R(STRING, STRING, String, pad_decimals, INT, "digits", varray());
  1524. ADDFUNC1R(STRING, STRING, String, pad_zeros, INT, "digits", varray());
  1525. ADDFUNC1R(STRING, STRING, String, trim_prefix, STRING, "prefix", varray());
  1526. ADDFUNC1R(STRING, STRING, String, trim_suffix, STRING, "suffix", varray());
  1527. ADDFUNC0R(STRING, POOL_BYTE_ARRAY, String, to_ascii, varray());
  1528. ADDFUNC0R(STRING, POOL_BYTE_ARRAY, String, to_utf8, varray());
  1529. ADDFUNC0R(STRING, POOL_BYTE_ARRAY, String, to_wchar, varray());
  1530. ADDFUNC0R(VECTOR2, REAL, Vector2, angle, varray());
  1531. ADDFUNC1R(VECTOR2, REAL, Vector2, angle_to, VECTOR2, "to", varray());
  1532. ADDFUNC1R(VECTOR2, REAL, Vector2, angle_to_point, VECTOR2, "to", varray());
  1533. ADDFUNC1R(VECTOR2, VECTOR2, Vector2, direction_to, VECTOR2, "b", varray());
  1534. ADDFUNC1R(VECTOR2, REAL, Vector2, distance_to, VECTOR2, "to", varray());
  1535. ADDFUNC1R(VECTOR2, REAL, Vector2, distance_squared_to, VECTOR2, "to", varray());
  1536. ADDFUNC0R(VECTOR2, REAL, Vector2, length, varray());
  1537. ADDFUNC0R(VECTOR2, REAL, Vector2, length_squared, varray());
  1538. ADDFUNC0R(VECTOR2, VECTOR2, Vector2, normalized, varray());
  1539. ADDFUNC0R(VECTOR2, BOOL, Vector2, is_normalized, varray());
  1540. ADDFUNC1R(VECTOR2, BOOL, Vector2, is_equal_approx, VECTOR2, "v", varray());
  1541. ADDFUNC1R(VECTOR2, VECTOR2, Vector2, posmod, REAL, "mod", varray());
  1542. ADDFUNC1R(VECTOR2, VECTOR2, Vector2, posmodv, VECTOR2, "modv", varray());
  1543. ADDFUNC1R(VECTOR2, VECTOR2, Vector2, project, VECTOR2, "b", varray());
  1544. ADDFUNC2R(VECTOR2, VECTOR2, Vector2, linear_interpolate, VECTOR2, "to", REAL, "weight", varray());
  1545. ADDFUNC2R(VECTOR2, VECTOR2, Vector2, slerp, VECTOR2, "to", REAL, "weight", varray());
  1546. ADDFUNC4R(VECTOR2, VECTOR2, Vector2, cubic_interpolate, VECTOR2, "b", VECTOR2, "pre_a", VECTOR2, "post_b", REAL, "weight", varray());
  1547. ADDFUNC2R(VECTOR2, VECTOR2, Vector2, move_toward, VECTOR2, "to", REAL, "delta", varray());
  1548. ADDFUNC1R(VECTOR2, VECTOR2, Vector2, rotated, REAL, "phi", varray());
  1549. ADDFUNC0R(VECTOR2, VECTOR2, Vector2, tangent, varray());
  1550. ADDFUNC0R(VECTOR2, VECTOR2, Vector2, floor, varray());
  1551. ADDFUNC0R(VECTOR2, VECTOR2, Vector2, ceil, varray());
  1552. ADDFUNC0R(VECTOR2, VECTOR2, Vector2, round, varray());
  1553. ADDFUNC1R(VECTOR2, VECTOR2, Vector2, snapped, VECTOR2, "by", varray());
  1554. ADDFUNC0R(VECTOR2, REAL, Vector2, aspect, varray());
  1555. ADDFUNC1R(VECTOR2, REAL, Vector2, dot, VECTOR2, "with", varray());
  1556. ADDFUNC1R(VECTOR2, VECTOR2, Vector2, slide, VECTOR2, "n", varray());
  1557. ADDFUNC1R(VECTOR2, VECTOR2, Vector2, bounce, VECTOR2, "n", varray());
  1558. ADDFUNC1R(VECTOR2, VECTOR2, Vector2, reflect, VECTOR2, "n", varray());
  1559. ADDFUNC1R(VECTOR2, REAL, Vector2, cross, VECTOR2, "with", varray());
  1560. ADDFUNC0R(VECTOR2, VECTOR2, Vector2, abs, varray());
  1561. ADDFUNC1R(VECTOR2, VECTOR2, Vector2, clamped, REAL, "length", varray());
  1562. ADDFUNC1R(VECTOR2, VECTOR2, Vector2, limit_length, REAL, "length", varray(1.0));
  1563. ADDFUNC0R(VECTOR2, VECTOR2, Vector2, sign, varray());
  1564. ADDFUNC0R(RECT2, REAL, Rect2, get_area, varray());
  1565. ADDFUNC0R(RECT2, VECTOR2, Rect2, get_center, varray());
  1566. ADDFUNC0R(RECT2, BOOL, Rect2, has_no_area, varray());
  1567. ADDFUNC1R(RECT2, BOOL, Rect2, has_point, VECTOR2, "point", varray());
  1568. ADDFUNC1R(RECT2, BOOL, Rect2, is_equal_approx, RECT2, "rect", varray());
  1569. ADDFUNC2R(RECT2, BOOL, Rect2, intersects, RECT2, "b", BOOL, "include_borders", varray(false));
  1570. ADDFUNC1R(RECT2, BOOL, Rect2, encloses, RECT2, "b", varray());
  1571. ADDFUNC1R(RECT2, RECT2, Rect2, clip, RECT2, "b", varray());
  1572. ADDFUNC1R(RECT2, RECT2, Rect2, merge, RECT2, "b", varray());
  1573. ADDFUNC1R(RECT2, RECT2, Rect2, expand, VECTOR2, "to", varray());
  1574. ADDFUNC1R(RECT2, RECT2, Rect2, grow, REAL, "by", varray());
  1575. ADDFUNC2R(RECT2, RECT2, Rect2, grow_margin, INT, "margin", REAL, "by", varray());
  1576. ADDFUNC4R(RECT2, RECT2, Rect2, grow_individual, REAL, "left", REAL, "top", REAL, "right", REAL, " bottom", varray());
  1577. ADDFUNC0R(RECT2, RECT2, Rect2, abs, varray());
  1578. ADDFUNC0R(VECTOR3, INT, Vector3, min_axis, varray());
  1579. ADDFUNC0R(VECTOR3, INT, Vector3, max_axis, varray());
  1580. ADDFUNC1R(VECTOR3, REAL, Vector3, angle_to, VECTOR3, "to", varray());
  1581. ADDFUNC2R(VECTOR3, REAL, Vector3, signed_angle_to, VECTOR3, "to", VECTOR3, "axis", varray());
  1582. ADDFUNC1R(VECTOR3, VECTOR3, Vector3, direction_to, VECTOR3, "b", varray());
  1583. ADDFUNC1R(VECTOR3, REAL, Vector3, distance_to, VECTOR3, "b", varray());
  1584. ADDFUNC1R(VECTOR3, REAL, Vector3, distance_squared_to, VECTOR3, "b", varray());
  1585. ADDFUNC0R(VECTOR3, REAL, Vector3, length, varray());
  1586. ADDFUNC0R(VECTOR3, REAL, Vector3, length_squared, varray());
  1587. ADDFUNC0R(VECTOR3, VECTOR3, Vector3, normalized, varray());
  1588. ADDFUNC0R(VECTOR3, BOOL, Vector3, is_normalized, varray());
  1589. ADDFUNC1R(VECTOR3, BOOL, Vector3, is_equal_approx, VECTOR3, "v", varray());
  1590. ADDFUNC0R(VECTOR3, VECTOR3, Vector3, inverse, varray());
  1591. ADDFUNC1R(VECTOR3, VECTOR3, Vector3, snapped, VECTOR3, "by", varray());
  1592. ADDFUNC2R(VECTOR3, VECTOR3, Vector3, rotated, VECTOR3, "axis", REAL, "phi", varray());
  1593. ADDFUNC2R(VECTOR3, VECTOR3, Vector3, linear_interpolate, VECTOR3, "to", REAL, "weight", varray());
  1594. ADDFUNC2R(VECTOR3, VECTOR3, Vector3, slerp, VECTOR3, "to", REAL, "weight", varray());
  1595. ADDFUNC4R(VECTOR3, VECTOR3, Vector3, cubic_interpolate, VECTOR3, "b", VECTOR3, "pre_a", VECTOR3, "post_b", REAL, "weight", varray());
  1596. ADDFUNC2R(VECTOR3, VECTOR3, Vector3, move_toward, VECTOR3, "to", REAL, "delta", varray());
  1597. ADDFUNC1R(VECTOR3, REAL, Vector3, dot, VECTOR3, "b", varray());
  1598. ADDFUNC1R(VECTOR3, VECTOR3, Vector3, cross, VECTOR3, "b", varray());
  1599. ADDFUNC1R(VECTOR3, BASIS, Vector3, outer, VECTOR3, "b", varray());
  1600. ADDFUNC0R(VECTOR3, BASIS, Vector3, to_diagonal_matrix, varray());
  1601. ADDFUNC0R(VECTOR3, VECTOR3, Vector3, abs, varray());
  1602. ADDFUNC0R(VECTOR3, VECTOR3, Vector3, floor, varray());
  1603. ADDFUNC0R(VECTOR3, VECTOR3, Vector3, ceil, varray());
  1604. ADDFUNC0R(VECTOR3, VECTOR3, Vector3, round, varray());
  1605. ADDFUNC1R(VECTOR3, VECTOR3, Vector3, posmod, REAL, "mod", varray());
  1606. ADDFUNC1R(VECTOR3, VECTOR3, Vector3, posmodv, VECTOR3, "modv", varray());
  1607. ADDFUNC1R(VECTOR3, VECTOR3, Vector3, project, VECTOR3, "b", varray());
  1608. ADDFUNC1R(VECTOR3, VECTOR3, Vector3, slide, VECTOR3, "n", varray());
  1609. ADDFUNC1R(VECTOR3, VECTOR3, Vector3, bounce, VECTOR3, "n", varray());
  1610. ADDFUNC1R(VECTOR3, VECTOR3, Vector3, reflect, VECTOR3, "n", varray());
  1611. ADDFUNC1R(VECTOR3, VECTOR3, Vector3, limit_length, REAL, "length", varray(1.0));
  1612. ADDFUNC0R(VECTOR3, VECTOR3, Vector3, sign, varray());
  1613. ADDFUNC0R(PLANE, PLANE, Plane, normalized, varray());
  1614. ADDFUNC0R(PLANE, VECTOR3, Plane, center, varray());
  1615. ADDFUNC0R(PLANE, VECTOR3, Plane, get_any_point, varray());
  1616. ADDFUNC1R(PLANE, BOOL, Plane, is_equal_approx, PLANE, "plane", varray());
  1617. ADDFUNC1R(PLANE, BOOL, Plane, is_point_over, VECTOR3, "point", varray());
  1618. ADDFUNC1R(PLANE, REAL, Plane, distance_to, VECTOR3, "point", varray());
  1619. ADDFUNC2R(PLANE, BOOL, Plane, has_point, VECTOR3, "point", REAL, "epsilon", varray(CMP_EPSILON));
  1620. ADDFUNC1R(PLANE, VECTOR3, Plane, project, VECTOR3, "point", varray());
  1621. ADDFUNC2R(PLANE, VECTOR3, Plane, intersect_3, PLANE, "b", PLANE, "c", varray());
  1622. ADDFUNC2R(PLANE, VECTOR3, Plane, intersects_ray, VECTOR3, "from", VECTOR3, "dir", varray());
  1623. ADDFUNC2R(PLANE, VECTOR3, Plane, intersects_segment, VECTOR3, "begin", VECTOR3, "end", varray());
  1624. ADDFUNC0R(QUAT, REAL, Quat, length, varray());
  1625. ADDFUNC0R(QUAT, REAL, Quat, length_squared, varray());
  1626. ADDFUNC0R(QUAT, QUAT, Quat, normalized, varray());
  1627. ADDFUNC0R(QUAT, BOOL, Quat, is_normalized, varray());
  1628. ADDFUNC1R(QUAT, BOOL, Quat, is_equal_approx, QUAT, "quat", varray());
  1629. ADDFUNC0R(QUAT, QUAT, Quat, inverse, varray());
  1630. ADDFUNC1R(QUAT, REAL, Quat, angle_to, QUAT, "to", varray());
  1631. ADDFUNC1R(QUAT, REAL, Quat, dot, QUAT, "b", varray());
  1632. ADDFUNC1R(QUAT, VECTOR3, Quat, xform, VECTOR3, "v", varray());
  1633. ADDFUNC2R(QUAT, QUAT, Quat, slerp, QUAT, "to", REAL, "weight", varray());
  1634. ADDFUNC2R(QUAT, QUAT, Quat, slerpni, QUAT, "to", REAL, "weight", varray());
  1635. ADDFUNC4R(QUAT, QUAT, Quat, cubic_slerp, QUAT, "b", QUAT, "pre_a", QUAT, "post_b", REAL, "weight", varray());
  1636. ADDFUNC0R(QUAT, VECTOR3, Quat, get_euler, varray());
  1637. ADDFUNC1(QUAT, NIL, Quat, set_euler, VECTOR3, "euler", varray());
  1638. ADDFUNC2(QUAT, NIL, Quat, set_axis_angle, VECTOR3, "axis", REAL, "angle", varray());
  1639. ADDFUNC0R(COLOR, INT, Color, to_argb32, varray());
  1640. ADDFUNC0R(COLOR, INT, Color, to_abgr32, varray());
  1641. ADDFUNC0R(COLOR, INT, Color, to_rgba32, varray());
  1642. ADDFUNC0R(COLOR, INT, Color, to_argb64, varray());
  1643. ADDFUNC0R(COLOR, INT, Color, to_abgr64, varray());
  1644. ADDFUNC0R(COLOR, INT, Color, to_rgba64, varray());
  1645. ADDFUNC0R(COLOR, REAL, Color, gray, varray());
  1646. ADDFUNC0R(COLOR, COLOR, Color, inverted, varray());
  1647. ADDFUNC0R(COLOR, COLOR, Color, contrasted, varray());
  1648. ADDFUNC2R(COLOR, COLOR, Color, linear_interpolate, COLOR, "to", REAL, "weight", varray());
  1649. ADDFUNC1R(COLOR, COLOR, Color, blend, COLOR, "over", varray());
  1650. ADDFUNC1R(COLOR, COLOR, Color, lightened, REAL, "amount", varray());
  1651. ADDFUNC1R(COLOR, COLOR, Color, darkened, REAL, "amount", varray());
  1652. ADDFUNC1R(COLOR, STRING, Color, to_html, BOOL, "with_alpha", varray(true));
  1653. ADDFUNC4R(COLOR, COLOR, Color, from_hsv, REAL, "h", REAL, "s", REAL, "v", REAL, "a", varray(1.0));
  1654. ADDFUNC1R(COLOR, BOOL, Color, is_equal_approx, COLOR, "color", varray());
  1655. ADDFUNC0R(_RID, INT, RID, get_id, varray());
  1656. ADDFUNC0R(NODE_PATH, BOOL, NodePath, is_absolute, varray());
  1657. ADDFUNC0R(NODE_PATH, INT, NodePath, get_name_count, varray());
  1658. ADDFUNC1R(NODE_PATH, STRING, NodePath, get_name, INT, "idx", varray());
  1659. ADDFUNC0R(NODE_PATH, INT, NodePath, get_subname_count, varray());
  1660. ADDFUNC1R(NODE_PATH, STRING, NodePath, get_subname, INT, "idx", varray());
  1661. ADDFUNC0R(NODE_PATH, STRING, NodePath, get_concatenated_subnames, varray());
  1662. ADDFUNC0R(NODE_PATH, NODE_PATH, NodePath, get_as_property_path, varray());
  1663. ADDFUNC0R(NODE_PATH, BOOL, NodePath, is_empty, varray());
  1664. ADDFUNC0R(DICTIONARY, INT, Dictionary, size, varray());
  1665. ADDFUNC0R(DICTIONARY, BOOL, Dictionary, empty, varray());
  1666. ADDFUNC0NC(DICTIONARY, NIL, Dictionary, clear, varray());
  1667. ADDFUNC1R(DICTIONARY, BOOL, Dictionary, has, NIL, "key", varray());
  1668. ADDFUNC1R(DICTIONARY, BOOL, Dictionary, has_all, ARRAY, "keys", varray());
  1669. ADDFUNC1RNC(DICTIONARY, BOOL, Dictionary, erase, NIL, "key", varray());
  1670. ADDFUNC0R(DICTIONARY, INT, Dictionary, hash, varray());
  1671. ADDFUNC0R(DICTIONARY, ARRAY, Dictionary, keys, varray());
  1672. ADDFUNC0R(DICTIONARY, ARRAY, Dictionary, values, varray());
  1673. ADDFUNC1R(DICTIONARY, DICTIONARY, Dictionary, duplicate, BOOL, "deep", varray(false));
  1674. ADDFUNC2R(DICTIONARY, NIL, Dictionary, get, NIL, "key", NIL, "default", varray(Variant()));
  1675. ADDFUNC0R(ARRAY, INT, Array, size, varray());
  1676. ADDFUNC0R(ARRAY, BOOL, Array, empty, varray());
  1677. ADDFUNC0NC(ARRAY, NIL, Array, clear, varray());
  1678. ADDFUNC0R(ARRAY, INT, Array, hash, varray());
  1679. ADDFUNC1NC(ARRAY, NIL, Array, push_back, NIL, "value", varray());
  1680. ADDFUNC1NC(ARRAY, NIL, Array, push_front, NIL, "value", varray());
  1681. ADDFUNC1NC(ARRAY, NIL, Array, append, NIL, "value", varray());
  1682. ADDFUNC1NC(ARRAY, NIL, Array, append_array, ARRAY, "array", varray());
  1683. ADDFUNC1NC(ARRAY, NIL, Array, resize, INT, "size", varray());
  1684. ADDFUNC2NC(ARRAY, NIL, Array, insert, INT, "position", NIL, "value", varray());
  1685. ADDFUNC1NC(ARRAY, NIL, Array, remove, INT, "position", varray());
  1686. ADDFUNC1NC(ARRAY, NIL, Array, erase, NIL, "value", varray());
  1687. ADDFUNC0R(ARRAY, NIL, Array, front, varray());
  1688. ADDFUNC0R(ARRAY, NIL, Array, back, varray());
  1689. ADDFUNC2R(ARRAY, INT, Array, find, NIL, "what", INT, "from", varray(0));
  1690. ADDFUNC2R(ARRAY, INT, Array, rfind, NIL, "what", INT, "from", varray(-1));
  1691. ADDFUNC1R(ARRAY, INT, Array, find_last, NIL, "value", varray());
  1692. ADDFUNC1R(ARRAY, INT, Array, count, NIL, "value", varray());
  1693. ADDFUNC1R(ARRAY, BOOL, Array, has, NIL, "value", varray());
  1694. ADDFUNC0RNC(ARRAY, NIL, Array, pop_back, varray());
  1695. ADDFUNC0RNC(ARRAY, NIL, Array, pop_front, varray());
  1696. ADDFUNC1RNC(ARRAY, NIL, Array, pop_at, INT, "position", varray());
  1697. ADDFUNC0NC(ARRAY, NIL, Array, sort, varray());
  1698. ADDFUNC2NC(ARRAY, NIL, Array, sort_custom, OBJECT, "obj", STRING, "func", varray());
  1699. ADDFUNC0NC(ARRAY, NIL, Array, shuffle, varray());
  1700. ADDFUNC2R(ARRAY, INT, Array, bsearch, NIL, "value", BOOL, "before", varray(true));
  1701. ADDFUNC4R(ARRAY, INT, Array, bsearch_custom, NIL, "value", OBJECT, "obj", STRING, "func", BOOL, "before", varray(true));
  1702. ADDFUNC0NC(ARRAY, NIL, Array, invert, varray());
  1703. ADDFUNC1R(ARRAY, ARRAY, Array, duplicate, BOOL, "deep", varray(false));
  1704. ADDFUNC4R(ARRAY, ARRAY, Array, slice, INT, "begin", INT, "end", INT, "step", BOOL, "deep", varray(1, false));
  1705. ADDFUNC0R(ARRAY, NIL, Array, max, varray());
  1706. ADDFUNC0R(ARRAY, NIL, Array, min, varray());
  1707. ADDFUNC0R(POOL_BYTE_ARRAY, INT, PoolByteArray, size, varray());
  1708. ADDFUNC0R(POOL_BYTE_ARRAY, BOOL, PoolByteArray, empty, varray());
  1709. ADDFUNC2(POOL_BYTE_ARRAY, NIL, PoolByteArray, set, INT, "idx", INT, "byte", varray());
  1710. ADDFUNC1(POOL_BYTE_ARRAY, NIL, PoolByteArray, push_back, INT, "byte", varray());
  1711. ADDFUNC1(POOL_BYTE_ARRAY, NIL, PoolByteArray, append, INT, "byte", varray());
  1712. ADDFUNC1(POOL_BYTE_ARRAY, NIL, PoolByteArray, append_array, POOL_BYTE_ARRAY, "array", varray());
  1713. ADDFUNC1(POOL_BYTE_ARRAY, NIL, PoolByteArray, remove, INT, "idx", varray());
  1714. ADDFUNC2R(POOL_BYTE_ARRAY, INT, PoolByteArray, insert, INT, "idx", INT, "byte", varray());
  1715. ADDFUNC1(POOL_BYTE_ARRAY, NIL, PoolByteArray, resize, INT, "idx", varray());
  1716. ADDFUNC0(POOL_BYTE_ARRAY, NIL, PoolByteArray, invert, varray());
  1717. ADDFUNC2R(POOL_BYTE_ARRAY, POOL_BYTE_ARRAY, PoolByteArray, subarray, INT, "from", INT, "to", varray());
  1718. ADDFUNC0R(POOL_BYTE_ARRAY, STRING, PoolByteArray, get_string_from_ascii, varray());
  1719. ADDFUNC0R(POOL_BYTE_ARRAY, STRING, PoolByteArray, get_string_from_utf8, varray());
  1720. ADDFUNC0R(POOL_BYTE_ARRAY, STRING, PoolByteArray, hex_encode, varray());
  1721. ADDFUNC1R(POOL_BYTE_ARRAY, POOL_BYTE_ARRAY, PoolByteArray, compress, INT, "compression_mode", varray(0));
  1722. ADDFUNC2R(POOL_BYTE_ARRAY, POOL_BYTE_ARRAY, PoolByteArray, decompress, INT, "buffer_size", INT, "compression_mode", varray(0));
  1723. ADDFUNC2R(POOL_BYTE_ARRAY, POOL_BYTE_ARRAY, PoolByteArray, decompress_dynamic, INT, "max_output_size", INT, "compression_mode", varray(0));
  1724. ADDFUNC0R(POOL_INT_ARRAY, INT, PoolIntArray, size, varray());
  1725. ADDFUNC0R(POOL_INT_ARRAY, BOOL, PoolIntArray, empty, varray());
  1726. ADDFUNC2(POOL_INT_ARRAY, NIL, PoolIntArray, set, INT, "idx", INT, "integer", varray());
  1727. ADDFUNC1(POOL_INT_ARRAY, NIL, PoolIntArray, push_back, INT, "integer", varray());
  1728. ADDFUNC1(POOL_INT_ARRAY, NIL, PoolIntArray, append, INT, "integer", varray());
  1729. ADDFUNC1(POOL_INT_ARRAY, NIL, PoolIntArray, append_array, POOL_INT_ARRAY, "array", varray());
  1730. ADDFUNC1(POOL_INT_ARRAY, NIL, PoolIntArray, remove, INT, "idx", varray());
  1731. ADDFUNC2R(POOL_INT_ARRAY, INT, PoolIntArray, insert, INT, "idx", INT, "integer", varray());
  1732. ADDFUNC1(POOL_INT_ARRAY, NIL, PoolIntArray, resize, INT, "idx", varray());
  1733. ADDFUNC0(POOL_INT_ARRAY, NIL, PoolIntArray, invert, varray());
  1734. ADDFUNC0R(POOL_REAL_ARRAY, INT, PoolRealArray, size, varray());
  1735. ADDFUNC0R(POOL_REAL_ARRAY, BOOL, PoolRealArray, empty, varray());
  1736. ADDFUNC2(POOL_REAL_ARRAY, NIL, PoolRealArray, set, INT, "idx", REAL, "value", varray());
  1737. ADDFUNC1(POOL_REAL_ARRAY, NIL, PoolRealArray, push_back, REAL, "value", varray());
  1738. ADDFUNC1(POOL_REAL_ARRAY, NIL, PoolRealArray, append, REAL, "value", varray());
  1739. ADDFUNC1(POOL_REAL_ARRAY, NIL, PoolRealArray, append_array, POOL_REAL_ARRAY, "array", varray());
  1740. ADDFUNC1(POOL_REAL_ARRAY, NIL, PoolRealArray, remove, INT, "idx", varray());
  1741. ADDFUNC2R(POOL_REAL_ARRAY, INT, PoolRealArray, insert, INT, "idx", REAL, "value", varray());
  1742. ADDFUNC1(POOL_REAL_ARRAY, NIL, PoolRealArray, resize, INT, "idx", varray());
  1743. ADDFUNC0(POOL_REAL_ARRAY, NIL, PoolRealArray, invert, varray());
  1744. ADDFUNC0R(POOL_STRING_ARRAY, INT, PoolStringArray, size, varray());
  1745. ADDFUNC0R(POOL_STRING_ARRAY, BOOL, PoolStringArray, empty, varray());
  1746. ADDFUNC2(POOL_STRING_ARRAY, NIL, PoolStringArray, set, INT, "idx", STRING, "string", varray());
  1747. ADDFUNC1(POOL_STRING_ARRAY, NIL, PoolStringArray, push_back, STRING, "string", varray());
  1748. ADDFUNC1(POOL_STRING_ARRAY, NIL, PoolStringArray, append, STRING, "string", varray());
  1749. ADDFUNC1(POOL_STRING_ARRAY, NIL, PoolStringArray, append_array, POOL_STRING_ARRAY, "array", varray());
  1750. ADDFUNC1(POOL_STRING_ARRAY, NIL, PoolStringArray, remove, INT, "idx", varray());
  1751. ADDFUNC2R(POOL_STRING_ARRAY, INT, PoolStringArray, insert, INT, "idx", STRING, "string", varray());
  1752. ADDFUNC1(POOL_STRING_ARRAY, NIL, PoolStringArray, resize, INT, "idx", varray());
  1753. ADDFUNC0(POOL_STRING_ARRAY, NIL, PoolStringArray, invert, varray());
  1754. ADDFUNC1(POOL_STRING_ARRAY, STRING, PoolStringArray, join, STRING, "delimiter", varray());
  1755. ADDFUNC0R(POOL_VECTOR2_ARRAY, INT, PoolVector2Array, size, varray());
  1756. ADDFUNC0R(POOL_VECTOR2_ARRAY, BOOL, PoolVector2Array, empty, varray());
  1757. ADDFUNC2(POOL_VECTOR2_ARRAY, NIL, PoolVector2Array, set, INT, "idx", VECTOR2, "vector2", varray());
  1758. ADDFUNC1(POOL_VECTOR2_ARRAY, NIL, PoolVector2Array, push_back, VECTOR2, "vector2", varray());
  1759. ADDFUNC1(POOL_VECTOR2_ARRAY, NIL, PoolVector2Array, append, VECTOR2, "vector2", varray());
  1760. ADDFUNC1(POOL_VECTOR2_ARRAY, NIL, PoolVector2Array, append_array, POOL_VECTOR2_ARRAY, "array", varray());
  1761. ADDFUNC1(POOL_VECTOR2_ARRAY, NIL, PoolVector2Array, remove, INT, "idx", varray());
  1762. ADDFUNC2R(POOL_VECTOR2_ARRAY, INT, PoolVector2Array, insert, INT, "idx", VECTOR2, "vector2", varray());
  1763. ADDFUNC1(POOL_VECTOR2_ARRAY, NIL, PoolVector2Array, resize, INT, "idx", varray());
  1764. ADDFUNC0(POOL_VECTOR2_ARRAY, NIL, PoolVector2Array, invert, varray());
  1765. ADDFUNC0R(POOL_VECTOR3_ARRAY, INT, PoolVector3Array, size, varray());
  1766. ADDFUNC0R(POOL_VECTOR3_ARRAY, BOOL, PoolVector3Array, empty, varray());
  1767. ADDFUNC2(POOL_VECTOR3_ARRAY, NIL, PoolVector3Array, set, INT, "idx", VECTOR3, "vector3", varray());
  1768. ADDFUNC1(POOL_VECTOR3_ARRAY, NIL, PoolVector3Array, push_back, VECTOR3, "vector3", varray());
  1769. ADDFUNC1(POOL_VECTOR3_ARRAY, NIL, PoolVector3Array, append, VECTOR3, "vector3", varray());
  1770. ADDFUNC1(POOL_VECTOR3_ARRAY, NIL, PoolVector3Array, append_array, POOL_VECTOR3_ARRAY, "array", varray());
  1771. ADDFUNC1(POOL_VECTOR3_ARRAY, NIL, PoolVector3Array, remove, INT, "idx", varray());
  1772. ADDFUNC2R(POOL_VECTOR3_ARRAY, INT, PoolVector3Array, insert, INT, "idx", VECTOR3, "vector3", varray());
  1773. ADDFUNC1(POOL_VECTOR3_ARRAY, NIL, PoolVector3Array, resize, INT, "idx", varray());
  1774. ADDFUNC0(POOL_VECTOR3_ARRAY, NIL, PoolVector3Array, invert, varray());
  1775. ADDFUNC0R(POOL_COLOR_ARRAY, INT, PoolColorArray, size, varray());
  1776. ADDFUNC0R(POOL_COLOR_ARRAY, BOOL, PoolColorArray, empty, varray());
  1777. ADDFUNC2(POOL_COLOR_ARRAY, NIL, PoolColorArray, set, INT, "idx", COLOR, "color", varray());
  1778. ADDFUNC1(POOL_COLOR_ARRAY, NIL, PoolColorArray, push_back, COLOR, "color", varray());
  1779. ADDFUNC1(POOL_COLOR_ARRAY, NIL, PoolColorArray, append, COLOR, "color", varray());
  1780. ADDFUNC1(POOL_COLOR_ARRAY, NIL, PoolColorArray, append_array, POOL_COLOR_ARRAY, "array", varray());
  1781. ADDFUNC1(POOL_COLOR_ARRAY, NIL, PoolColorArray, remove, INT, "idx", varray());
  1782. ADDFUNC2R(POOL_COLOR_ARRAY, INT, PoolColorArray, insert, INT, "idx", COLOR, "color", varray());
  1783. ADDFUNC1(POOL_COLOR_ARRAY, NIL, PoolColorArray, resize, INT, "idx", varray());
  1784. ADDFUNC0(POOL_COLOR_ARRAY, NIL, PoolColorArray, invert, varray());
  1785. //pointerbased
  1786. ADDFUNC0R(AABB, AABB, AABB, abs, varray());
  1787. ADDFUNC0R(AABB, REAL, AABB, get_area, varray());
  1788. ADDFUNC0R(AABB, VECTOR3, AABB, get_center, varray());
  1789. ADDFUNC0R(AABB, BOOL, AABB, has_no_area, varray());
  1790. ADDFUNC0R(AABB, BOOL, AABB, has_no_surface, varray());
  1791. ADDFUNC1R(AABB, BOOL, AABB, has_point, VECTOR3, "point", varray());
  1792. ADDFUNC1R(AABB, BOOL, AABB, is_equal_approx, AABB, "aabb", varray());
  1793. ADDFUNC1R(AABB, BOOL, AABB, intersects, AABB, "with", varray());
  1794. ADDFUNC1R(AABB, BOOL, AABB, encloses, AABB, "with", varray());
  1795. ADDFUNC1R(AABB, BOOL, AABB, intersects_plane, PLANE, "plane", varray());
  1796. ADDFUNC2R(AABB, BOOL, AABB, intersects_segment, VECTOR3, "from", VECTOR3, "to", varray());
  1797. ADDFUNC1R(AABB, AABB, AABB, intersection, AABB, "with", varray());
  1798. ADDFUNC1R(AABB, AABB, AABB, merge, AABB, "with", varray());
  1799. ADDFUNC1R(AABB, AABB, AABB, expand, VECTOR3, "to_point", varray());
  1800. ADDFUNC1R(AABB, AABB, AABB, grow, REAL, "by", varray());
  1801. ADDFUNC1R(AABB, VECTOR3, AABB, get_support, VECTOR3, "dir", varray());
  1802. ADDFUNC0R(AABB, VECTOR3, AABB, get_longest_axis, varray());
  1803. ADDFUNC0R(AABB, INT, AABB, get_longest_axis_index, varray());
  1804. ADDFUNC0R(AABB, REAL, AABB, get_longest_axis_size, varray());
  1805. ADDFUNC0R(AABB, VECTOR3, AABB, get_shortest_axis, varray());
  1806. ADDFUNC0R(AABB, INT, AABB, get_shortest_axis_index, varray());
  1807. ADDFUNC0R(AABB, REAL, AABB, get_shortest_axis_size, varray());
  1808. ADDFUNC1R(AABB, VECTOR3, AABB, get_endpoint, INT, "idx", varray());
  1809. ADDFUNC0R(TRANSFORM2D, TRANSFORM2D, Transform2D, inverse, varray());
  1810. ADDFUNC0R(TRANSFORM2D, TRANSFORM2D, Transform2D, affine_inverse, varray());
  1811. ADDFUNC0R(TRANSFORM2D, REAL, Transform2D, get_rotation, varray());
  1812. ADDFUNC0R(TRANSFORM2D, VECTOR2, Transform2D, get_origin, varray());
  1813. ADDFUNC0R(TRANSFORM2D, VECTOR2, Transform2D, get_scale, varray());
  1814. ADDFUNC0R(TRANSFORM2D, TRANSFORM2D, Transform2D, orthonormalized, varray());
  1815. ADDFUNC1R(TRANSFORM2D, TRANSFORM2D, Transform2D, rotated, REAL, "phi", varray());
  1816. ADDFUNC1R(TRANSFORM2D, TRANSFORM2D, Transform2D, scaled, VECTOR2, "scale", varray());
  1817. ADDFUNC1R(TRANSFORM2D, TRANSFORM2D, Transform2D, translated, VECTOR2, "offset", varray());
  1818. ADDFUNC1R(TRANSFORM2D, NIL, Transform2D, xform, NIL, "v", varray());
  1819. ADDFUNC1R(TRANSFORM2D, NIL, Transform2D, xform_inv, NIL, "v", varray());
  1820. ADDFUNC1R(TRANSFORM2D, VECTOR2, Transform2D, basis_xform, VECTOR2, "v", varray());
  1821. ADDFUNC1R(TRANSFORM2D, VECTOR2, Transform2D, basis_xform_inv, VECTOR2, "v", varray());
  1822. ADDFUNC2R(TRANSFORM2D, TRANSFORM2D, Transform2D, interpolate_with, TRANSFORM2D, "transform", REAL, "weight", varray());
  1823. ADDFUNC1R(TRANSFORM2D, BOOL, Transform2D, is_equal_approx, TRANSFORM2D, "transform", varray());
  1824. ADDFUNC0R(BASIS, BASIS, Basis, inverse, varray());
  1825. ADDFUNC0R(BASIS, BASIS, Basis, transposed, varray());
  1826. ADDFUNC0R(BASIS, BASIS, Basis, orthonormalized, varray());
  1827. ADDFUNC0R(BASIS, REAL, Basis, determinant, varray());
  1828. ADDFUNC2R(BASIS, BASIS, Basis, rotated, VECTOR3, "axis", REAL, "phi", varray());
  1829. ADDFUNC1R(BASIS, BASIS, Basis, scaled, VECTOR3, "scale", varray());
  1830. ADDFUNC0R(BASIS, VECTOR3, Basis, get_scale, varray());
  1831. ADDFUNC0R(BASIS, VECTOR3, Basis, get_euler, varray());
  1832. ADDFUNC1R(BASIS, REAL, Basis, tdotx, VECTOR3, "with", varray());
  1833. ADDFUNC1R(BASIS, REAL, Basis, tdoty, VECTOR3, "with", varray());
  1834. ADDFUNC1R(BASIS, REAL, Basis, tdotz, VECTOR3, "with", varray());
  1835. ADDFUNC1R(BASIS, VECTOR3, Basis, xform, VECTOR3, "v", varray());
  1836. ADDFUNC1R(BASIS, VECTOR3, Basis, xform_inv, VECTOR3, "v", varray());
  1837. ADDFUNC0R(BASIS, INT, Basis, get_orthogonal_index, varray());
  1838. ADDFUNC2R(BASIS, BASIS, Basis, slerp, BASIS, "to", REAL, "weight", varray());
  1839. // For complicated reasons, the epsilon argument is always discarded. See #45062.
  1840. ADDFUNC2R(BASIS, BOOL, Basis, is_equal_approx, BASIS, "b", REAL, "epsilon", varray(CMP_EPSILON));
  1841. ADDFUNC0R(BASIS, QUAT, Basis, get_rotation_quat, varray());
  1842. ADDFUNC0R(TRANSFORM, TRANSFORM, Transform, inverse, varray());
  1843. ADDFUNC0R(TRANSFORM, TRANSFORM, Transform, affine_inverse, varray());
  1844. ADDFUNC0R(TRANSFORM, TRANSFORM, Transform, orthonormalized, varray());
  1845. ADDFUNC2R(TRANSFORM, TRANSFORM, Transform, rotated, VECTOR3, "axis", REAL, "phi", varray());
  1846. ADDFUNC1R(TRANSFORM, TRANSFORM, Transform, scaled, VECTOR3, "scale", varray());
  1847. ADDFUNC1R(TRANSFORM, TRANSFORM, Transform, translated, VECTOR3, "offset", varray());
  1848. ADDFUNC2R(TRANSFORM, TRANSFORM, Transform, looking_at, VECTOR3, "target", VECTOR3, "up", varray());
  1849. ADDFUNC2R(TRANSFORM, TRANSFORM, Transform, interpolate_with, TRANSFORM, "transform", REAL, "weight", varray());
  1850. ADDFUNC1R(TRANSFORM, BOOL, Transform, is_equal_approx, TRANSFORM, "transform", varray());
  1851. ADDFUNC1R(TRANSFORM, NIL, Transform, xform, NIL, "v", varray());
  1852. ADDFUNC1R(TRANSFORM, NIL, Transform, xform_inv, NIL, "v", varray());
  1853. /* REGISTER CONSTRUCTORS */
  1854. _VariantCall::add_constructor(_VariantCall::Vector2_init1, Variant::VECTOR2, "x", Variant::REAL, "y", Variant::REAL);
  1855. _VariantCall::add_constructor(_VariantCall::Rect2_init1, Variant::RECT2, "position", Variant::VECTOR2, "size", Variant::VECTOR2);
  1856. _VariantCall::add_constructor(_VariantCall::Rect2_init2, Variant::RECT2, "x", Variant::REAL, "y", Variant::REAL, "width", Variant::REAL, "height", Variant::REAL);
  1857. _VariantCall::add_constructor(_VariantCall::Transform2D_init2, Variant::TRANSFORM2D, "rotation", Variant::REAL, "position", Variant::VECTOR2);
  1858. _VariantCall::add_constructor(_VariantCall::Transform2D_init3, Variant::TRANSFORM2D, "x_axis", Variant::VECTOR2, "y_axis", Variant::VECTOR2, "origin", Variant::VECTOR2);
  1859. _VariantCall::add_constructor(_VariantCall::Vector3_init1, Variant::VECTOR3, "x", Variant::REAL, "y", Variant::REAL, "z", Variant::REAL);
  1860. _VariantCall::add_constructor(_VariantCall::Plane_init1, Variant::PLANE, "a", Variant::REAL, "b", Variant::REAL, "c", Variant::REAL, "d", Variant::REAL);
  1861. _VariantCall::add_constructor(_VariantCall::Plane_init2, Variant::PLANE, "v1", Variant::VECTOR3, "v2", Variant::VECTOR3, "v3", Variant::VECTOR3);
  1862. _VariantCall::add_constructor(_VariantCall::Plane_init3, Variant::PLANE, "normal", Variant::VECTOR3, "d", Variant::REAL);
  1863. _VariantCall::add_constructor(_VariantCall::Quat_init1, Variant::QUAT, "x", Variant::REAL, "y", Variant::REAL, "z", Variant::REAL, "w", Variant::REAL);
  1864. _VariantCall::add_constructor(_VariantCall::Quat_init2, Variant::QUAT, "axis", Variant::VECTOR3, "angle", Variant::REAL);
  1865. _VariantCall::add_constructor(_VariantCall::Quat_init3, Variant::QUAT, "euler", Variant::VECTOR3);
  1866. _VariantCall::add_constructor(_VariantCall::Color_init1, Variant::COLOR, "r", Variant::REAL, "g", Variant::REAL, "b", Variant::REAL, "a", Variant::REAL);
  1867. _VariantCall::add_constructor(_VariantCall::Color_init2, Variant::COLOR, "r", Variant::REAL, "g", Variant::REAL, "b", Variant::REAL);
  1868. _VariantCall::add_constructor(_VariantCall::AABB_init1, Variant::AABB, "position", Variant::VECTOR3, "size", Variant::VECTOR3);
  1869. _VariantCall::add_constructor(_VariantCall::Basis_init1, Variant::BASIS, "x_axis", Variant::VECTOR3, "y_axis", Variant::VECTOR3, "z_axis", Variant::VECTOR3);
  1870. _VariantCall::add_constructor(_VariantCall::Basis_init2, Variant::BASIS, "axis", Variant::VECTOR3, "phi", Variant::REAL);
  1871. _VariantCall::add_constructor(_VariantCall::Transform_init1, Variant::TRANSFORM, "x_axis", Variant::VECTOR3, "y_axis", Variant::VECTOR3, "z_axis", Variant::VECTOR3, "origin", Variant::VECTOR3);
  1872. _VariantCall::add_constructor(_VariantCall::Transform_init2, Variant::TRANSFORM, "basis", Variant::BASIS, "origin", Variant::VECTOR3);
  1873. /* REGISTER CONSTANTS */
  1874. _populate_named_colors();
  1875. for (Map<String, Color>::Element *color = _named_colors.front(); color; color = color->next()) {
  1876. _VariantCall::add_variant_constant(Variant::COLOR, color->key(), color->value());
  1877. }
  1878. _VariantCall::add_constant(Variant::VECTOR3, "AXIS_X", Vector3::AXIS_X);
  1879. _VariantCall::add_constant(Variant::VECTOR3, "AXIS_Y", Vector3::AXIS_Y);
  1880. _VariantCall::add_constant(Variant::VECTOR3, "AXIS_Z", Vector3::AXIS_Z);
  1881. _VariantCall::add_variant_constant(Variant::VECTOR3, "ZERO", Vector3(0, 0, 0));
  1882. _VariantCall::add_variant_constant(Variant::VECTOR3, "ONE", Vector3(1, 1, 1));
  1883. _VariantCall::add_variant_constant(Variant::VECTOR3, "INF", Vector3(Math_INF, Math_INF, Math_INF));
  1884. _VariantCall::add_variant_constant(Variant::VECTOR3, "LEFT", Vector3(-1, 0, 0));
  1885. _VariantCall::add_variant_constant(Variant::VECTOR3, "RIGHT", Vector3(1, 0, 0));
  1886. _VariantCall::add_variant_constant(Variant::VECTOR3, "UP", Vector3(0, 1, 0));
  1887. _VariantCall::add_variant_constant(Variant::VECTOR3, "DOWN", Vector3(0, -1, 0));
  1888. _VariantCall::add_variant_constant(Variant::VECTOR3, "FORWARD", Vector3(0, 0, -1));
  1889. _VariantCall::add_variant_constant(Variant::VECTOR3, "BACK", Vector3(0, 0, 1));
  1890. _VariantCall::add_constant(Variant::VECTOR2, "AXIS_X", Vector2::AXIS_X);
  1891. _VariantCall::add_constant(Variant::VECTOR2, "AXIS_Y", Vector2::AXIS_Y);
  1892. _VariantCall::add_variant_constant(Variant::VECTOR2, "ZERO", Vector2(0, 0));
  1893. _VariantCall::add_variant_constant(Variant::VECTOR2, "ONE", Vector2(1, 1));
  1894. _VariantCall::add_variant_constant(Variant::VECTOR2, "INF", Vector2(Math_INF, Math_INF));
  1895. _VariantCall::add_variant_constant(Variant::VECTOR2, "LEFT", Vector2(-1, 0));
  1896. _VariantCall::add_variant_constant(Variant::VECTOR2, "RIGHT", Vector2(1, 0));
  1897. _VariantCall::add_variant_constant(Variant::VECTOR2, "UP", Vector2(0, -1));
  1898. _VariantCall::add_variant_constant(Variant::VECTOR2, "DOWN", Vector2(0, 1));
  1899. _VariantCall::add_variant_constant(Variant::TRANSFORM2D, "IDENTITY", Transform2D());
  1900. _VariantCall::add_variant_constant(Variant::TRANSFORM2D, "FLIP_X", Transform2D(-1, 0, 0, 1, 0, 0));
  1901. _VariantCall::add_variant_constant(Variant::TRANSFORM2D, "FLIP_Y", Transform2D(1, 0, 0, -1, 0, 0));
  1902. Transform identity_transform = Transform();
  1903. Transform flip_x_transform = Transform(-1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0);
  1904. Transform flip_y_transform = Transform(1, 0, 0, 0, -1, 0, 0, 0, 1, 0, 0, 0);
  1905. Transform flip_z_transform = Transform(1, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 0);
  1906. _VariantCall::add_variant_constant(Variant::TRANSFORM, "IDENTITY", identity_transform);
  1907. _VariantCall::add_variant_constant(Variant::TRANSFORM, "FLIP_X", flip_x_transform);
  1908. _VariantCall::add_variant_constant(Variant::TRANSFORM, "FLIP_Y", flip_y_transform);
  1909. _VariantCall::add_variant_constant(Variant::TRANSFORM, "FLIP_Z", flip_z_transform);
  1910. Basis identity_basis = Basis();
  1911. Basis flip_x_basis = Basis(-1, 0, 0, 0, 1, 0, 0, 0, 1);
  1912. Basis flip_y_basis = Basis(1, 0, 0, 0, -1, 0, 0, 0, 1);
  1913. Basis flip_z_basis = Basis(1, 0, 0, 0, 1, 0, 0, 0, -1);
  1914. _VariantCall::add_variant_constant(Variant::BASIS, "IDENTITY", identity_basis);
  1915. _VariantCall::add_variant_constant(Variant::BASIS, "FLIP_X", flip_x_basis);
  1916. _VariantCall::add_variant_constant(Variant::BASIS, "FLIP_Y", flip_y_basis);
  1917. _VariantCall::add_variant_constant(Variant::BASIS, "FLIP_Z", flip_z_basis);
  1918. _VariantCall::add_variant_constant(Variant::PLANE, "PLANE_YZ", Plane(Vector3(1, 0, 0), 0));
  1919. _VariantCall::add_variant_constant(Variant::PLANE, "PLANE_XZ", Plane(Vector3(0, 1, 0), 0));
  1920. _VariantCall::add_variant_constant(Variant::PLANE, "PLANE_XY", Plane(Vector3(0, 0, 1), 0));
  1921. _VariantCall::add_variant_constant(Variant::QUAT, "IDENTITY", Quat(0, 0, 0, 1));
  1922. }
  1923. void unregister_variant_methods() {
  1924. memdelete_arr(_VariantCall::type_funcs);
  1925. memdelete_arr(_VariantCall::construct_funcs);
  1926. memdelete_arr(_VariantCall::constant_data);
  1927. }