variant_call.cpp 92 KB

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