variant_call.cpp 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775
  1. /*************************************************************************/
  2. /* variant_call.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 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 "core_string_names.h"
  31. #include "object.h"
  32. #include "os/os.h"
  33. #include "script_language.h"
  34. #include "variant.h"
  35. typedef void (*VariantFunc)(Variant &r_ret, Variant &p_self, const Variant **p_args);
  36. typedef void (*VariantConstructFunc)(Variant &r_ret, const Variant **p_args);
  37. VARIANT_ENUM_CAST(Image::CompressMode);
  38. //VARIANT_ENUM_CAST(Image::Format);
  39. struct _VariantCall {
  40. static void Vector3_dot(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  41. r_ret = reinterpret_cast<Vector3 *>(p_self._data._mem)->dot(*reinterpret_cast<const Vector3 *>(p_args[0]->_data._mem));
  42. }
  43. struct FuncData {
  44. int arg_count;
  45. Vector<Variant> default_args;
  46. Vector<Variant::Type> arg_types;
  47. #ifdef DEBUG_ENABLED
  48. Vector<StringName> arg_names;
  49. Variant::Type return_type;
  50. bool returns;
  51. #endif
  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. Variant::Type *tptr = &arg_types[0];
  57. for (int i = 0; i < arg_count; i++) {
  58. if (!tptr[i] || 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. int defargcount = def_argcount;
  91. for (int i = p_argcount; i < arg_count; i++)
  92. newargs[i] = &default_args[defargcount - (i - p_argcount) - 1]; //default arguments
  93. #ifdef DEBUG_ENABLED
  94. if (!verify_arguments(newargs, r_error))
  95. return;
  96. #endif
  97. func(r_ret, p_self, newargs);
  98. } else {
  99. #ifdef DEBUG_ENABLED
  100. if (!verify_arguments(p_args, r_error))
  101. return;
  102. #endif
  103. func(r_ret, p_self, p_args);
  104. }
  105. }
  106. };
  107. struct TypeFunc {
  108. Map<StringName, FuncData> functions;
  109. };
  110. static TypeFunc *type_funcs;
  111. struct Arg {
  112. StringName name;
  113. Variant::Type type;
  114. Arg() { type = Variant::NIL; }
  115. Arg(Variant::Type p_type, const StringName &p_name) {
  116. name = p_name;
  117. type = p_type;
  118. }
  119. };
  120. // void addfunc(Variant::Type p_type, const StringName& p_name,VariantFunc p_func);
  121. static void addfunc(Variant::Type p_type, Variant::Type p_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()) {
  122. FuncData funcdata;
  123. funcdata.func = p_func;
  124. funcdata.default_args = p_defaultarg;
  125. #ifdef DEBUG_ENABLED
  126. funcdata.return_type = p_return;
  127. funcdata.returns = p_return != Variant::NIL;
  128. #endif
  129. if (p_argtype1.name) {
  130. funcdata.arg_types.push_back(p_argtype1.type);
  131. #ifdef DEBUG_ENABLED
  132. funcdata.arg_names.push_back(p_argtype1.name);
  133. #endif
  134. } else
  135. goto end;
  136. if (p_argtype2.name) {
  137. funcdata.arg_types.push_back(p_argtype2.type);
  138. #ifdef DEBUG_ENABLED
  139. funcdata.arg_names.push_back(p_argtype2.name);
  140. #endif
  141. } else
  142. goto end;
  143. if (p_argtype3.name) {
  144. funcdata.arg_types.push_back(p_argtype3.type);
  145. #ifdef DEBUG_ENABLED
  146. funcdata.arg_names.push_back(p_argtype3.name);
  147. #endif
  148. } else
  149. goto end;
  150. if (p_argtype4.name) {
  151. funcdata.arg_types.push_back(p_argtype4.type);
  152. #ifdef DEBUG_ENABLED
  153. funcdata.arg_names.push_back(p_argtype4.name);
  154. #endif
  155. } else
  156. goto end;
  157. if (p_argtype5.name) {
  158. funcdata.arg_types.push_back(p_argtype5.type);
  159. #ifdef DEBUG_ENABLED
  160. funcdata.arg_names.push_back(p_argtype5.name);
  161. #endif
  162. } else
  163. goto end;
  164. end:
  165. funcdata.arg_count = funcdata.arg_types.size();
  166. type_funcs[p_type].functions[p_name] = funcdata;
  167. }
  168. #define VCALL_LOCALMEM0(m_type, m_method) \
  169. 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(); }
  170. #define VCALL_LOCALMEM0R(m_type, m_method) \
  171. 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(); }
  172. #define VCALL_LOCALMEM1(m_type, m_method) \
  173. 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]); }
  174. #define VCALL_LOCALMEM1R(m_type, m_method) \
  175. 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]); }
  176. #define VCALL_LOCALMEM2(m_type, m_method) \
  177. 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]); }
  178. #define VCALL_LOCALMEM2R(m_type, m_method) \
  179. 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]); }
  180. #define VCALL_LOCALMEM3(m_type, m_method) \
  181. 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]); }
  182. #define VCALL_LOCALMEM3R(m_type, m_method) \
  183. 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]); }
  184. #define VCALL_LOCALMEM4(m_type, m_method) \
  185. 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]); }
  186. #define VCALL_LOCALMEM4R(m_type, m_method) \
  187. 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]); }
  188. #define VCALL_LOCALMEM5(m_type, m_method) \
  189. 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]); }
  190. #define VCALL_LOCALMEM5R(m_type, m_method) \
  191. 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]); }
  192. // built-in functions of localmem based types
  193. VCALL_LOCALMEM1R(String, casecmp_to);
  194. VCALL_LOCALMEM1R(String, nocasecmp_to);
  195. VCALL_LOCALMEM0R(String, length);
  196. VCALL_LOCALMEM2R(String, substr);
  197. VCALL_LOCALMEM2R(String, find);
  198. VCALL_LOCALMEM1R(String, find_last);
  199. VCALL_LOCALMEM2R(String, findn);
  200. VCALL_LOCALMEM2R(String, rfind);
  201. VCALL_LOCALMEM2R(String, rfindn);
  202. VCALL_LOCALMEM1R(String, match);
  203. VCALL_LOCALMEM1R(String, matchn);
  204. VCALL_LOCALMEM1R(String, begins_with);
  205. VCALL_LOCALMEM1R(String, ends_with);
  206. VCALL_LOCALMEM1R(String, is_subsequence_of);
  207. VCALL_LOCALMEM1R(String, is_subsequence_ofi);
  208. VCALL_LOCALMEM0R(String, bigrams);
  209. VCALL_LOCALMEM1R(String, similarity);
  210. VCALL_LOCALMEM2R(String, format);
  211. VCALL_LOCALMEM2R(String, replace);
  212. VCALL_LOCALMEM2R(String, replacen);
  213. VCALL_LOCALMEM2R(String, insert);
  214. VCALL_LOCALMEM0R(String, capitalize);
  215. VCALL_LOCALMEM2R(String, split);
  216. VCALL_LOCALMEM2R(String, split_floats);
  217. VCALL_LOCALMEM0R(String, to_upper);
  218. VCALL_LOCALMEM0R(String, to_lower);
  219. VCALL_LOCALMEM1R(String, left);
  220. VCALL_LOCALMEM1R(String, right);
  221. VCALL_LOCALMEM2R(String, strip_edges);
  222. VCALL_LOCALMEM0R(String, extension);
  223. VCALL_LOCALMEM0R(String, basename);
  224. VCALL_LOCALMEM1R(String, plus_file);
  225. VCALL_LOCALMEM1R(String, ord_at);
  226. VCALL_LOCALMEM2(String, erase);
  227. VCALL_LOCALMEM0R(String, hash);
  228. VCALL_LOCALMEM0R(String, md5_text);
  229. VCALL_LOCALMEM0R(String, sha256_text);
  230. VCALL_LOCALMEM1R(String, encrypt_text);
  231. VCALL_LOCALMEM1R(String, decrypt_text);
  232. VCALL_LOCALMEM0R(String, md5_buffer);
  233. VCALL_LOCALMEM0R(String, sha256_buffer);
  234. VCALL_LOCALMEM0R(String, empty);
  235. VCALL_LOCALMEM0R(String, is_abs_path);
  236. VCALL_LOCALMEM0R(String, is_rel_path);
  237. VCALL_LOCALMEM0R(String, get_base_dir);
  238. VCALL_LOCALMEM0R(String, get_file);
  239. VCALL_LOCALMEM0R(String, xml_escape);
  240. VCALL_LOCALMEM0R(String, xml_unescape);
  241. VCALL_LOCALMEM0R(String, c_escape);
  242. VCALL_LOCALMEM0R(String, c_unescape);
  243. VCALL_LOCALMEM0R(String, json_escape);
  244. VCALL_LOCALMEM0R(String, percent_encode);
  245. VCALL_LOCALMEM0R(String, percent_decode);
  246. VCALL_LOCALMEM0R(String, is_valid_identifier);
  247. VCALL_LOCALMEM0R(String, is_valid_integer);
  248. VCALL_LOCALMEM0R(String, is_valid_float);
  249. VCALL_LOCALMEM0R(String, is_valid_html_color);
  250. VCALL_LOCALMEM0R(String, is_valid_ip_address);
  251. VCALL_LOCALMEM0R(String, to_int);
  252. VCALL_LOCALMEM0R(String, to_float);
  253. VCALL_LOCALMEM0R(String, hex_to_int);
  254. VCALL_LOCALMEM1R(String, pad_decimals);
  255. VCALL_LOCALMEM1R(String, pad_zeros);
  256. static void _call_String_to_ascii(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  257. String *s = reinterpret_cast<String *>(p_self._data._mem);
  258. CharString charstr = s->ascii();
  259. ByteArray retval;
  260. size_t len = charstr.length();
  261. retval.resize(len);
  262. ByteArray::Write w = retval.write();
  263. copymem(w.ptr(), charstr.ptr(), len);
  264. w = DVector<uint8_t>::Write();
  265. r_ret = retval;
  266. }
  267. static void _call_String_to_utf8(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  268. String *s = reinterpret_cast<String *>(p_self._data._mem);
  269. CharString charstr = s->utf8();
  270. ByteArray retval;
  271. size_t len = charstr.length();
  272. retval.resize(len);
  273. ByteArray::Write w = retval.write();
  274. copymem(w.ptr(), charstr.ptr(), len);
  275. w = DVector<uint8_t>::Write();
  276. r_ret = retval;
  277. }
  278. VCALL_LOCALMEM0R(Vector2, normalized);
  279. VCALL_LOCALMEM0R(Vector2, length);
  280. VCALL_LOCALMEM0R(Vector2, length_squared);
  281. VCALL_LOCALMEM1R(Vector2, distance_to);
  282. VCALL_LOCALMEM1R(Vector2, distance_squared_to);
  283. VCALL_LOCALMEM1R(Vector2, angle_to);
  284. VCALL_LOCALMEM1R(Vector2, angle_to_point);
  285. VCALL_LOCALMEM2R(Vector2, linear_interpolate);
  286. VCALL_LOCALMEM4R(Vector2, cubic_interpolate);
  287. VCALL_LOCALMEM1R(Vector2, rotated);
  288. VCALL_LOCALMEM0R(Vector2, tangent);
  289. VCALL_LOCALMEM0R(Vector2, floor);
  290. VCALL_LOCALMEM1R(Vector2, snapped);
  291. VCALL_LOCALMEM0R(Vector2, get_aspect);
  292. VCALL_LOCALMEM1R(Vector2, dot);
  293. VCALL_LOCALMEM1R(Vector2, slide);
  294. VCALL_LOCALMEM1R(Vector2, reflect);
  295. VCALL_LOCALMEM0R(Vector2, angle);
  296. // VCALL_LOCALMEM1R(Vector2,cross);
  297. VCALL_LOCALMEM0R(Vector2, abs);
  298. VCALL_LOCALMEM1R(Vector2, clamped);
  299. VCALL_LOCALMEM0R(Rect2, get_area);
  300. VCALL_LOCALMEM1R(Rect2, intersects);
  301. VCALL_LOCALMEM1R(Rect2, encloses);
  302. VCALL_LOCALMEM0R(Rect2, has_no_area);
  303. VCALL_LOCALMEM1R(Rect2, clip);
  304. VCALL_LOCALMEM1R(Rect2, merge);
  305. VCALL_LOCALMEM1R(Rect2, has_point);
  306. VCALL_LOCALMEM1R(Rect2, grow);
  307. VCALL_LOCALMEM2R(Rect2, grow_margin);
  308. VCALL_LOCALMEM4R(Rect2, grow_individual);
  309. VCALL_LOCALMEM1R(Rect2, expand);
  310. VCALL_LOCALMEM0R(Vector3, min_axis);
  311. VCALL_LOCALMEM0R(Vector3, max_axis);
  312. VCALL_LOCALMEM0R(Vector3, length);
  313. VCALL_LOCALMEM0R(Vector3, length_squared);
  314. VCALL_LOCALMEM0R(Vector3, normalized);
  315. VCALL_LOCALMEM0R(Vector3, inverse);
  316. VCALL_LOCALMEM1R(Vector3, snapped);
  317. VCALL_LOCALMEM2R(Vector3, rotated);
  318. VCALL_LOCALMEM2R(Vector3, linear_interpolate);
  319. VCALL_LOCALMEM4R(Vector3, cubic_interpolate);
  320. VCALL_LOCALMEM1R(Vector3, dot);
  321. VCALL_LOCALMEM1R(Vector3, cross);
  322. VCALL_LOCALMEM0R(Vector3, abs);
  323. VCALL_LOCALMEM0R(Vector3, floor);
  324. VCALL_LOCALMEM0R(Vector3, ceil);
  325. VCALL_LOCALMEM1R(Vector3, distance_to);
  326. VCALL_LOCALMEM1R(Vector3, distance_squared_to);
  327. VCALL_LOCALMEM1R(Vector3, angle_to);
  328. VCALL_LOCALMEM1R(Vector3, slide);
  329. VCALL_LOCALMEM1R(Vector3, reflect);
  330. VCALL_LOCALMEM0R(Plane, normalized);
  331. VCALL_LOCALMEM0R(Plane, center);
  332. VCALL_LOCALMEM0R(Plane, get_any_point);
  333. VCALL_LOCALMEM1R(Plane, is_point_over);
  334. VCALL_LOCALMEM1R(Plane, distance_to);
  335. VCALL_LOCALMEM2R(Plane, has_point);
  336. VCALL_LOCALMEM1R(Plane, project);
  337. //return vector3 if intersected, nil if not
  338. static void _call_Plane_intersect_3(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  339. Vector3 result;
  340. if (reinterpret_cast<Plane *>(p_self._data._mem)->intersect_3(*p_args[0], *p_args[1], &result))
  341. r_ret = result;
  342. else
  343. r_ret = Variant();
  344. }
  345. static void _call_Plane_intersects_ray(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  346. Vector3 result;
  347. if (reinterpret_cast<Plane *>(p_self._data._mem)->intersects_ray(*p_args[0], *p_args[1], &result))
  348. r_ret = result;
  349. else
  350. r_ret = Variant();
  351. }
  352. static void _call_Plane_intersects_segment(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  353. Vector3 result;
  354. if (reinterpret_cast<Plane *>(p_self._data._mem)->intersects_segment(*p_args[0], *p_args[1], &result))
  355. r_ret = result;
  356. else
  357. r_ret = Variant();
  358. }
  359. static void _call_Vector2_floorf(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  360. r_ret = reinterpret_cast<Vector2 *>(p_self._data._mem)->floor();
  361. };
  362. VCALL_LOCALMEM0R(Quat, length);
  363. VCALL_LOCALMEM0R(Quat, length_squared);
  364. VCALL_LOCALMEM0R(Quat, normalized);
  365. VCALL_LOCALMEM0R(Quat, inverse);
  366. VCALL_LOCALMEM1R(Quat, dot);
  367. VCALL_LOCALMEM1R(Quat, xform);
  368. VCALL_LOCALMEM2R(Quat, slerp);
  369. VCALL_LOCALMEM2R(Quat, slerpni);
  370. VCALL_LOCALMEM4R(Quat, cubic_slerp);
  371. VCALL_LOCALMEM0R(Color, to_32);
  372. VCALL_LOCALMEM0R(Color, to_ARGB32);
  373. VCALL_LOCALMEM0R(Color, gray);
  374. VCALL_LOCALMEM0R(Color, inverted);
  375. VCALL_LOCALMEM0R(Color, contrasted);
  376. VCALL_LOCALMEM2R(Color, linear_interpolate);
  377. VCALL_LOCALMEM1R(Color, blend);
  378. VCALL_LOCALMEM1R(Color, to_html);
  379. VCALL_LOCALMEM0R(RID, get_id);
  380. VCALL_LOCALMEM0R(NodePath, is_absolute);
  381. VCALL_LOCALMEM0R(NodePath, get_name_count);
  382. VCALL_LOCALMEM1R(NodePath, get_name);
  383. VCALL_LOCALMEM0R(NodePath, get_subname_count);
  384. VCALL_LOCALMEM1R(NodePath, get_subname);
  385. VCALL_LOCALMEM0R(NodePath, get_property);
  386. VCALL_LOCALMEM0R(NodePath, is_empty);
  387. VCALL_LOCALMEM0R(Dictionary, size);
  388. VCALL_LOCALMEM0R(Dictionary, empty);
  389. VCALL_LOCALMEM0(Dictionary, clear);
  390. VCALL_LOCALMEM1R(Dictionary, has);
  391. VCALL_LOCALMEM1R(Dictionary, has_all);
  392. VCALL_LOCALMEM1(Dictionary, erase);
  393. VCALL_LOCALMEM0R(Dictionary, hash);
  394. VCALL_LOCALMEM0R(Dictionary, keys);
  395. VCALL_LOCALMEM0R(Dictionary, values);
  396. VCALL_LOCALMEM1R(Dictionary, parse_json);
  397. VCALL_LOCALMEM0R(Dictionary, to_json);
  398. VCALL_LOCALMEM2(Array, set);
  399. VCALL_LOCALMEM1R(Array, get);
  400. VCALL_LOCALMEM0R(Array, size);
  401. VCALL_LOCALMEM0R(Array, empty);
  402. VCALL_LOCALMEM0(Array, clear);
  403. VCALL_LOCALMEM0R(Array, hash);
  404. VCALL_LOCALMEM1(Array, push_back);
  405. VCALL_LOCALMEM1(Array, push_front);
  406. VCALL_LOCALMEM0(Array, pop_back);
  407. VCALL_LOCALMEM0(Array, pop_front);
  408. VCALL_LOCALMEM1(Array, append);
  409. VCALL_LOCALMEM1(Array, resize);
  410. VCALL_LOCALMEM2(Array, insert);
  411. VCALL_LOCALMEM1(Array, remove);
  412. VCALL_LOCALMEM0R(Array, front);
  413. VCALL_LOCALMEM0R(Array, back);
  414. VCALL_LOCALMEM2R(Array, find);
  415. VCALL_LOCALMEM2R(Array, rfind);
  416. VCALL_LOCALMEM1R(Array, find_last);
  417. VCALL_LOCALMEM1R(Array, count);
  418. VCALL_LOCALMEM1R(Array, has);
  419. VCALL_LOCALMEM1(Array, erase);
  420. VCALL_LOCALMEM0(Array, sort);
  421. VCALL_LOCALMEM2(Array, sort_custom);
  422. VCALL_LOCALMEM0(Array, invert);
  423. VCALL_LOCALMEM0R(Array, is_shared);
  424. static void _call_ByteArray_get_string_from_ascii(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  425. ByteArray *ba = reinterpret_cast<ByteArray *>(p_self._data._mem);
  426. String s;
  427. if (ba->size() >= 0) {
  428. ByteArray::Read r = ba->read();
  429. CharString cs;
  430. cs.resize(ba->size() + 1);
  431. copymem(cs.ptr(), r.ptr(), ba->size());
  432. cs[ba->size()] = 0;
  433. s = cs.get_data();
  434. }
  435. r_ret = s;
  436. }
  437. static void _call_ByteArray_get_string_from_utf8(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  438. ByteArray *ba = reinterpret_cast<ByteArray *>(p_self._data._mem);
  439. String s;
  440. if (ba->size() >= 0) {
  441. ByteArray::Read r = ba->read();
  442. s.parse_utf8((const char *)r.ptr(), ba->size());
  443. }
  444. r_ret = s;
  445. }
  446. VCALL_LOCALMEM0R(ByteArray, size);
  447. VCALL_LOCALMEM2(ByteArray, set);
  448. VCALL_LOCALMEM1R(ByteArray, get);
  449. VCALL_LOCALMEM1(ByteArray, push_back);
  450. VCALL_LOCALMEM1(ByteArray, resize);
  451. VCALL_LOCALMEM2R(ByteArray, insert);
  452. VCALL_LOCALMEM1(ByteArray, remove);
  453. VCALL_LOCALMEM1(ByteArray, append);
  454. VCALL_LOCALMEM1(ByteArray, append_array);
  455. VCALL_LOCALMEM0(ByteArray, invert);
  456. VCALL_LOCALMEM0R(IntArray, size);
  457. VCALL_LOCALMEM2(IntArray, set);
  458. VCALL_LOCALMEM1R(IntArray, get);
  459. VCALL_LOCALMEM1(IntArray, push_back);
  460. VCALL_LOCALMEM1(IntArray, resize);
  461. VCALL_LOCALMEM2R(IntArray, insert);
  462. VCALL_LOCALMEM1(IntArray, remove);
  463. VCALL_LOCALMEM1(IntArray, append);
  464. VCALL_LOCALMEM1(IntArray, append_array);
  465. VCALL_LOCALMEM0(IntArray, invert);
  466. VCALL_LOCALMEM0R(RealArray, size);
  467. VCALL_LOCALMEM2(RealArray, set);
  468. VCALL_LOCALMEM1R(RealArray, get);
  469. VCALL_LOCALMEM1(RealArray, push_back);
  470. VCALL_LOCALMEM1(RealArray, resize);
  471. VCALL_LOCALMEM2R(RealArray, insert);
  472. VCALL_LOCALMEM1(RealArray, remove);
  473. VCALL_LOCALMEM1(RealArray, append);
  474. VCALL_LOCALMEM1(RealArray, append_array);
  475. VCALL_LOCALMEM0(RealArray, invert);
  476. VCALL_LOCALMEM0R(StringArray, size);
  477. VCALL_LOCALMEM2(StringArray, set);
  478. VCALL_LOCALMEM1R(StringArray, get);
  479. VCALL_LOCALMEM1(StringArray, push_back);
  480. VCALL_LOCALMEM1(StringArray, resize);
  481. VCALL_LOCALMEM2R(StringArray, insert);
  482. VCALL_LOCALMEM1(StringArray, remove);
  483. VCALL_LOCALMEM1(StringArray, append);
  484. VCALL_LOCALMEM1(StringArray, append_array);
  485. VCALL_LOCALMEM0(StringArray, invert);
  486. VCALL_LOCALMEM0R(Vector2Array, size);
  487. VCALL_LOCALMEM2(Vector2Array, set);
  488. VCALL_LOCALMEM1R(Vector2Array, get);
  489. VCALL_LOCALMEM1(Vector2Array, push_back);
  490. VCALL_LOCALMEM1(Vector2Array, resize);
  491. VCALL_LOCALMEM2R(Vector2Array, insert);
  492. VCALL_LOCALMEM1(Vector2Array, remove);
  493. VCALL_LOCALMEM1(Vector2Array, append);
  494. VCALL_LOCALMEM1(Vector2Array, append_array);
  495. VCALL_LOCALMEM0(Vector2Array, invert);
  496. VCALL_LOCALMEM0R(Vector3Array, size);
  497. VCALL_LOCALMEM2(Vector3Array, set);
  498. VCALL_LOCALMEM1R(Vector3Array, get);
  499. VCALL_LOCALMEM1(Vector3Array, push_back);
  500. VCALL_LOCALMEM1(Vector3Array, resize);
  501. VCALL_LOCALMEM2R(Vector3Array, insert);
  502. VCALL_LOCALMEM1(Vector3Array, remove);
  503. VCALL_LOCALMEM1(Vector3Array, append);
  504. VCALL_LOCALMEM1(Vector3Array, append_array);
  505. VCALL_LOCALMEM0(Vector3Array, invert);
  506. VCALL_LOCALMEM0R(ColorArray, size);
  507. VCALL_LOCALMEM2(ColorArray, set);
  508. VCALL_LOCALMEM1R(ColorArray, get);
  509. VCALL_LOCALMEM1(ColorArray, push_back);
  510. VCALL_LOCALMEM1(ColorArray, resize);
  511. VCALL_LOCALMEM2R(ColorArray, insert);
  512. VCALL_LOCALMEM1(ColorArray, remove);
  513. VCALL_LOCALMEM1(ColorArray, append);
  514. VCALL_LOCALMEM1(ColorArray, append_array);
  515. VCALL_LOCALMEM0(ColorArray, invert);
  516. #define VCALL_PTR0(m_type, m_method) \
  517. 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(); }
  518. #define VCALL_PTR0R(m_type, m_method) \
  519. 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(); }
  520. #define VCALL_PTR1(m_type, m_method) \
  521. 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]); }
  522. #define VCALL_PTR1R(m_type, m_method) \
  523. 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]); }
  524. #define VCALL_PTR2(m_type, m_method) \
  525. 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]); }
  526. #define VCALL_PTR2R(m_type, m_method) \
  527. 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]); }
  528. #define VCALL_PTR3(m_type, m_method) \
  529. 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]); }
  530. #define VCALL_PTR3R(m_type, m_method) \
  531. 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]); }
  532. #define VCALL_PTR4(m_type, m_method) \
  533. 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]); }
  534. #define VCALL_PTR4R(m_type, m_method) \
  535. 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]); }
  536. #define VCALL_PTR5(m_type, m_method) \
  537. 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]); }
  538. #define VCALL_PTR5R(m_type, m_method) \
  539. 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]); }
  540. VCALL_PTR0R(Image, get_format);
  541. VCALL_PTR0R(Image, get_width);
  542. VCALL_PTR0R(Image, get_height);
  543. VCALL_PTR0R(Image, empty);
  544. VCALL_PTR3R(Image, get_pixel);
  545. VCALL_PTR4(Image, put_pixel);
  546. VCALL_PTR0R(Image, get_used_rect);
  547. VCALL_PTR3R(Image, brushed);
  548. VCALL_PTR1R(Image, load);
  549. VCALL_PTR1R(Image, save_png);
  550. VCALL_PTR3(Image, brush_transfer);
  551. VCALL_PTR1R(Image, get_rect);
  552. VCALL_PTR1R(Image, compressed);
  553. VCALL_PTR0R(Image, decompressed);
  554. VCALL_PTR3R(Image, resized);
  555. VCALL_PTR0R(Image, get_data);
  556. VCALL_PTR3(Image, blit_rect);
  557. VCALL_PTR4(Image, blit_rect_mask);
  558. VCALL_PTR3(Image, blend_rect);
  559. VCALL_PTR4(Image, blend_rect_mask);
  560. VCALL_PTR1(Image, fill);
  561. VCALL_PTR1R(Image, converted);
  562. VCALL_PTR0(Image, fix_alpha_edges);
  563. VCALL_PTR0R(AABB, get_area);
  564. VCALL_PTR0R(AABB, has_no_area);
  565. VCALL_PTR0R(AABB, has_no_surface);
  566. VCALL_PTR1R(AABB, intersects);
  567. VCALL_PTR1R(AABB, encloses);
  568. VCALL_PTR1R(AABB, merge);
  569. VCALL_PTR1R(AABB, intersection);
  570. VCALL_PTR1R(AABB, intersects_plane);
  571. VCALL_PTR2R(AABB, intersects_segment);
  572. VCALL_PTR1R(AABB, has_point);
  573. VCALL_PTR1R(AABB, get_support);
  574. VCALL_PTR0R(AABB, get_longest_axis);
  575. VCALL_PTR0R(AABB, get_longest_axis_index);
  576. VCALL_PTR0R(AABB, get_longest_axis_size);
  577. VCALL_PTR0R(AABB, get_shortest_axis);
  578. VCALL_PTR0R(AABB, get_shortest_axis_index);
  579. VCALL_PTR0R(AABB, get_shortest_axis_size);
  580. VCALL_PTR1R(AABB, expand);
  581. VCALL_PTR1R(AABB, grow);
  582. VCALL_PTR1R(AABB, get_endpoint);
  583. VCALL_PTR0R(Matrix32, inverse);
  584. VCALL_PTR0R(Matrix32, affine_inverse);
  585. VCALL_PTR0R(Matrix32, get_rotation);
  586. VCALL_PTR0R(Matrix32, get_origin);
  587. VCALL_PTR0R(Matrix32, get_scale);
  588. VCALL_PTR0R(Matrix32, orthonormalized);
  589. VCALL_PTR1R(Matrix32, rotated);
  590. VCALL_PTR1R(Matrix32, scaled);
  591. VCALL_PTR1R(Matrix32, translated);
  592. VCALL_PTR2R(Matrix32, interpolate_with);
  593. static void _call_Matrix32_xform(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  594. switch (p_args[0]->type) {
  595. case Variant::VECTOR2: r_ret = reinterpret_cast<Matrix32 *>(p_self._data._ptr)->xform(p_args[0]->operator Vector2()); return;
  596. case Variant::RECT2: r_ret = reinterpret_cast<Matrix32 *>(p_self._data._ptr)->xform(p_args[0]->operator Rect2()); return;
  597. default: r_ret = Variant();
  598. }
  599. }
  600. static void _call_Matrix32_xform_inv(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  601. switch (p_args[0]->type) {
  602. case Variant::VECTOR2: r_ret = reinterpret_cast<Matrix32 *>(p_self._data._ptr)->xform_inv(p_args[0]->operator Vector2()); return;
  603. case Variant::RECT2: r_ret = reinterpret_cast<Matrix32 *>(p_self._data._ptr)->xform_inv(p_args[0]->operator Rect2()); return;
  604. default: r_ret = Variant();
  605. }
  606. }
  607. static void _call_Matrix32_basis_xform(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  608. switch (p_args[0]->type) {
  609. case Variant::VECTOR2: r_ret = reinterpret_cast<Matrix32 *>(p_self._data._ptr)->basis_xform(p_args[0]->operator Vector2()); return;
  610. default: r_ret = Variant();
  611. }
  612. }
  613. static void _call_Matrix32_basis_xform_inv(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  614. switch (p_args[0]->type) {
  615. case Variant::VECTOR2: r_ret = reinterpret_cast<Matrix32 *>(p_self._data._ptr)->basis_xform_inv(p_args[0]->operator Vector2()); return;
  616. default: r_ret = Variant();
  617. }
  618. }
  619. VCALL_PTR0R(Matrix3, inverse);
  620. VCALL_PTR0R(Matrix3, transposed);
  621. VCALL_PTR0R(Matrix3, determinant);
  622. VCALL_PTR2R(Matrix3, rotated);
  623. VCALL_PTR1R(Matrix3, scaled);
  624. VCALL_PTR0R(Matrix3, get_scale);
  625. VCALL_PTR0R(Matrix3, get_euler);
  626. VCALL_PTR1R(Matrix3, tdotx);
  627. VCALL_PTR1R(Matrix3, tdoty);
  628. VCALL_PTR1R(Matrix3, tdotz);
  629. VCALL_PTR1R(Matrix3, xform);
  630. VCALL_PTR1R(Matrix3, xform_inv);
  631. VCALL_PTR0R(Matrix3, get_orthogonal_index);
  632. VCALL_PTR0R(Matrix3, orthonormalized);
  633. VCALL_PTR0R(Transform, inverse);
  634. VCALL_PTR0R(Transform, affine_inverse);
  635. VCALL_PTR2R(Transform, rotated);
  636. VCALL_PTR1R(Transform, scaled);
  637. VCALL_PTR1R(Transform, translated);
  638. VCALL_PTR0R(Transform, orthonormalized);
  639. VCALL_PTR2R(Transform, looking_at);
  640. static void _call_Transform_xform(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  641. switch (p_args[0]->type) {
  642. case Variant::VECTOR3: r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform(p_args[0]->operator Vector3()); return;
  643. case Variant::PLANE: r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform(p_args[0]->operator Plane()); return;
  644. case Variant::_AABB: r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform(p_args[0]->operator AABB()); return;
  645. default: r_ret = Variant();
  646. }
  647. }
  648. static void _call_Transform_xform_inv(Variant &r_ret, Variant &p_self, const Variant **p_args) {
  649. switch (p_args[0]->type) {
  650. case Variant::VECTOR3: r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform_inv(p_args[0]->operator Vector3()); return;
  651. case Variant::PLANE: r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform_inv(p_args[0]->operator Plane()); return;
  652. case Variant::_AABB: r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform_inv(p_args[0]->operator AABB()); return;
  653. default: r_ret = Variant();
  654. }
  655. }
  656. /*
  657. VCALL_PTR0( Transform, invert );
  658. VCALL_PTR0( Transform, affine_invert );
  659. VCALL_PTR2( Transform, rotate );
  660. VCALL_PTR1( Transform, scale );
  661. VCALL_PTR1( Transform, translate );
  662. VCALL_PTR0( Transform, orthonormalize ); */
  663. VCALL_PTR0R(InputEvent, is_pressed);
  664. VCALL_PTR1R(InputEvent, is_action);
  665. VCALL_PTR1R(InputEvent, is_action_pressed);
  666. VCALL_PTR1R(InputEvent, is_action_released);
  667. VCALL_PTR0R(InputEvent, is_echo);
  668. VCALL_PTR2(InputEvent, set_as_action);
  669. struct ConstructData {
  670. int arg_count;
  671. Vector<Variant::Type> arg_types;
  672. Vector<String> arg_names;
  673. VariantConstructFunc func;
  674. };
  675. struct ConstructFunc {
  676. List<ConstructData> constructors;
  677. };
  678. static ConstructFunc *construct_funcs;
  679. static void Vector2_init1(Variant &r_ret, const Variant **p_args) {
  680. r_ret = Vector2(*p_args[0], *p_args[1]);
  681. }
  682. static void Rect2_init1(Variant &r_ret, const Variant **p_args) {
  683. r_ret = Rect2(*p_args[0], *p_args[1]);
  684. }
  685. static void Rect2_init2(Variant &r_ret, const Variant **p_args) {
  686. r_ret = Rect2(*p_args[0], *p_args[1], *p_args[2], *p_args[3]);
  687. }
  688. static void Matrix32_init2(Variant &r_ret, const Variant **p_args) {
  689. Matrix32 m(*p_args[0], *p_args[1]);
  690. r_ret = m;
  691. }
  692. static void Matrix32_init3(Variant &r_ret, const Variant **p_args) {
  693. Matrix32 m;
  694. m[0] = *p_args[0];
  695. m[1] = *p_args[1];
  696. m[2] = *p_args[2];
  697. r_ret = m;
  698. }
  699. static void Vector3_init1(Variant &r_ret, const Variant **p_args) {
  700. r_ret = Vector3(*p_args[0], *p_args[1], *p_args[2]);
  701. }
  702. static void Plane_init1(Variant &r_ret, const Variant **p_args) {
  703. r_ret = Plane(*p_args[0], *p_args[1], *p_args[2], *p_args[3]);
  704. }
  705. static void Plane_init2(Variant &r_ret, const Variant **p_args) {
  706. r_ret = Plane(*p_args[0], *p_args[1], *p_args[2]);
  707. }
  708. static void Plane_init3(Variant &r_ret, const Variant **p_args) {
  709. r_ret = Plane(p_args[0]->operator Vector3(), p_args[1]->operator real_t());
  710. }
  711. static void Plane_init4(Variant &r_ret, const Variant **p_args) {
  712. r_ret = Plane(p_args[0]->operator Vector3(), p_args[1]->operator Vector3());
  713. }
  714. static void Quat_init1(Variant &r_ret, const Variant **p_args) {
  715. r_ret = Quat(*p_args[0], *p_args[1], *p_args[2], *p_args[3]);
  716. }
  717. static void Quat_init2(Variant &r_ret, const Variant **p_args) {
  718. r_ret = Quat(((Vector3)(*p_args[0])), ((float)(*p_args[1])));
  719. }
  720. static void Color_init1(Variant &r_ret, const Variant **p_args) {
  721. r_ret = Color(*p_args[0], *p_args[1], *p_args[2], *p_args[3]);
  722. }
  723. static void Color_init2(Variant &r_ret, const Variant **p_args) {
  724. r_ret = Color(*p_args[0], *p_args[1], *p_args[2]);
  725. }
  726. static void Color_init3(Variant &r_ret, const Variant **p_args) {
  727. r_ret = Color::html(*p_args[0]);
  728. }
  729. static void Color_init4(Variant &r_ret, const Variant **p_args) {
  730. r_ret = Color::hex(*p_args[0]);
  731. }
  732. static void AABB_init1(Variant &r_ret, const Variant **p_args) {
  733. r_ret = AABB(*p_args[0], *p_args[1]);
  734. }
  735. static void Matrix3_init1(Variant &r_ret, const Variant **p_args) {
  736. Matrix3 m;
  737. m.set_axis(0, *p_args[0]);
  738. m.set_axis(1, *p_args[1]);
  739. m.set_axis(2, *p_args[2]);
  740. r_ret = m;
  741. }
  742. static void Matrix3_init2(Variant &r_ret, const Variant **p_args) {
  743. r_ret = Matrix3(p_args[0]->operator Vector3(), p_args[1]->operator real_t());
  744. }
  745. static void Transform_init1(Variant &r_ret, const Variant **p_args) {
  746. Transform t;
  747. t.basis.set_axis(0, *p_args[0]);
  748. t.basis.set_axis(1, *p_args[1]);
  749. t.basis.set_axis(2, *p_args[2]);
  750. t.origin = *p_args[3];
  751. r_ret = t;
  752. }
  753. static void Transform_init2(Variant &r_ret, const Variant **p_args) {
  754. r_ret = Transform(p_args[0]->operator Matrix3(), p_args[1]->operator Vector3());
  755. }
  756. static void Image_init1(Variant &r_ret, const Variant **p_args) {
  757. r_ret = Image(*p_args[0], *p_args[1], *p_args[2], Image::Format(p_args[3]->operator int()));
  758. }
  759. static void add_constructor(VariantConstructFunc p_func, const Variant::Type p_type,
  760. const String &p_name1 = "", const Variant::Type p_type1 = Variant::NIL,
  761. const String &p_name2 = "", const Variant::Type p_type2 = Variant::NIL,
  762. const String &p_name3 = "", const Variant::Type p_type3 = Variant::NIL,
  763. const String &p_name4 = "", const Variant::Type p_type4 = Variant::NIL) {
  764. ConstructData cd;
  765. cd.func = p_func;
  766. cd.arg_count = 0;
  767. if (p_name1 == "")
  768. goto end;
  769. cd.arg_count++;
  770. cd.arg_names.push_back(p_name1);
  771. cd.arg_types.push_back(p_type1);
  772. if (p_name2 == "")
  773. goto end;
  774. cd.arg_count++;
  775. cd.arg_names.push_back(p_name2);
  776. cd.arg_types.push_back(p_type2);
  777. if (p_name3 == "")
  778. goto end;
  779. cd.arg_count++;
  780. cd.arg_names.push_back(p_name3);
  781. cd.arg_types.push_back(p_type3);
  782. if (p_name4 == "")
  783. goto end;
  784. cd.arg_count++;
  785. cd.arg_names.push_back(p_name4);
  786. cd.arg_types.push_back(p_type4);
  787. end:
  788. construct_funcs[p_type].constructors.push_back(cd);
  789. }
  790. struct ConstantData {
  791. Map<StringName, int> value;
  792. #ifdef DEBUG_ENABLED
  793. List<StringName> value_ordered;
  794. #endif
  795. };
  796. static ConstantData *constant_data;
  797. static void add_constant(int p_type, StringName p_constant_name, int p_constant_value) {
  798. constant_data[p_type].value[p_constant_name] = p_constant_value;
  799. #ifdef DEBUG_ENABLED
  800. constant_data[p_type].value_ordered.push_back(p_constant_name);
  801. #endif
  802. }
  803. };
  804. _VariantCall::TypeFunc *_VariantCall::type_funcs = NULL;
  805. _VariantCall::ConstructFunc *_VariantCall::construct_funcs = NULL;
  806. _VariantCall::ConstantData *_VariantCall::constant_data = NULL;
  807. Variant Variant::call(const StringName &p_method, const Variant **p_args, int p_argcount, CallError &r_error) {
  808. Variant ret;
  809. call_ptr(p_method, p_args, p_argcount, &ret, r_error);
  810. return ret;
  811. }
  812. void Variant::call_ptr(const StringName &p_method, const Variant **p_args, int p_argcount, Variant *r_ret, CallError &r_error) {
  813. Variant ret;
  814. if (type == Variant::OBJECT) {
  815. //call object
  816. Object *obj = _get_obj().obj;
  817. if (!obj) {
  818. r_error.error = CallError::CALL_ERROR_INSTANCE_IS_NULL;
  819. return;
  820. }
  821. #ifdef DEBUG_ENABLED
  822. if (ScriptDebugger::get_singleton() && _get_obj().ref.is_null()) {
  823. //only if debugging!
  824. if (!ObjectDB::instance_validate(obj)) {
  825. r_error.error = CallError::CALL_ERROR_INSTANCE_IS_NULL;
  826. return;
  827. }
  828. }
  829. #endif
  830. ret = _get_obj().obj->call(p_method, p_args, p_argcount, r_error);
  831. //else if (type==Variant::METHOD) {
  832. } else {
  833. r_error.error = Variant::CallError::CALL_OK;
  834. Map<StringName, _VariantCall::FuncData>::Element *E = _VariantCall::type_funcs[type].functions.find(p_method);
  835. #ifdef DEBUG_ENABLED
  836. if (!E) {
  837. r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
  838. return;
  839. }
  840. #endif
  841. _VariantCall::FuncData &funcdata = E->get();
  842. funcdata.call(ret, *this, p_args, p_argcount, r_error);
  843. }
  844. if (r_error.error == Variant::CallError::CALL_OK && r_ret)
  845. *r_ret = ret;
  846. }
  847. #define VCALL(m_type, m_method) _VariantCall::_call_##m_type##_##m_method
  848. Variant Variant::construct(const Variant::Type p_type, const Variant **p_args, int p_argcount, CallError &r_error, bool p_strict) {
  849. r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
  850. ERR_FAIL_INDEX_V(p_type, VARIANT_MAX, Variant());
  851. r_error.error = Variant::CallError::CALL_OK;
  852. if (p_argcount == 0) { //generic construct
  853. switch (p_type) {
  854. case NIL:
  855. return Variant();
  856. // atomic types
  857. case BOOL: return Variant(false);
  858. case INT: return 0;
  859. case REAL: return 0.0f;
  860. case STRING:
  861. return String();
  862. // math types
  863. case VECTOR2:
  864. return Vector2(); // 5
  865. case RECT2: return Rect2();
  866. case VECTOR3: return Vector3();
  867. case MATRIX32: return Matrix32();
  868. case PLANE: return Plane();
  869. case QUAT: return Quat();
  870. case _AABB:
  871. return AABB(); //sorry naming convention fail :( not like it's used often // 10
  872. case MATRIX3: return Matrix3();
  873. case TRANSFORM:
  874. return Transform();
  875. // misc types
  876. case COLOR: return Color();
  877. case IMAGE: return Image();
  878. case NODE_PATH:
  879. return NodePath(); // 15
  880. case _RID: return RID();
  881. case OBJECT: return (Object *)NULL;
  882. case INPUT_EVENT: return InputEvent();
  883. case DICTIONARY: return Dictionary();
  884. case ARRAY:
  885. return Array(); // 20
  886. case RAW_ARRAY: return ByteArray();
  887. case INT_ARRAY: return IntArray();
  888. case REAL_ARRAY: return RealArray();
  889. case STRING_ARRAY: return StringArray();
  890. case VECTOR2_ARRAY:
  891. return Vector2Array(); // 25
  892. case VECTOR3_ARRAY:
  893. return Vector3Array(); // 25
  894. case COLOR_ARRAY: return ColorArray();
  895. default: return Variant();
  896. }
  897. } else if (p_argcount > 1) {
  898. _VariantCall::ConstructFunc &c = _VariantCall::construct_funcs[p_type];
  899. for (List<_VariantCall::ConstructData>::Element *E = c.constructors.front(); E; E = E->next()) {
  900. const _VariantCall::ConstructData &cd = E->get();
  901. if (cd.arg_count != p_argcount)
  902. continue;
  903. //validate parameters
  904. for (int i = 0; i < cd.arg_count; i++) {
  905. if (!Variant::can_convert(p_args[i]->type, cd.arg_types[i])) {
  906. r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; //no such constructor
  907. r_error.argument = i;
  908. r_error.expected = cd.arg_types[i];
  909. return Variant();
  910. }
  911. }
  912. Variant v;
  913. cd.func(v, p_args);
  914. return v;
  915. }
  916. } else if (p_argcount == 1 && p_args[0]->type == p_type) {
  917. return *p_args[0]; //copy construct
  918. } else if (p_argcount == 1 && (!p_strict || Variant::can_convert(p_args[0]->type, p_type))) {
  919. //near match construct
  920. switch (p_type) {
  921. case NIL: {
  922. return Variant();
  923. } break;
  924. case BOOL: {
  925. return Variant(bool(*p_args[0]));
  926. }
  927. case INT: {
  928. return (int(*p_args[0]));
  929. }
  930. case REAL: {
  931. return real_t(*p_args[0]);
  932. }
  933. case STRING: {
  934. return String(*p_args[0]);
  935. }
  936. case VECTOR2: {
  937. return Vector2(*p_args[0]);
  938. }
  939. case RECT2: return (Rect2(*p_args[0]));
  940. case VECTOR3: return (Vector3(*p_args[0]));
  941. case PLANE: return (Plane(*p_args[0]));
  942. case QUAT: return (Quat(*p_args[0]));
  943. case _AABB:
  944. return (AABB(*p_args[0])); //sorry naming convention fail :( not like it's used often // 10
  945. case MATRIX3: return (Matrix3(p_args[0]->operator Matrix3()));
  946. case TRANSFORM:
  947. return (Transform(p_args[0]->operator Transform()));
  948. // misc types
  949. case COLOR: return p_args[0]->type == Variant::STRING ? Color::html(*p_args[0]) : Color::hex(*p_args[0]);
  950. case IMAGE: return (Image(*p_args[0]));
  951. case NODE_PATH:
  952. return (NodePath(p_args[0]->operator NodePath())); // 15
  953. case _RID: return (RID(*p_args[0]));
  954. case OBJECT: return ((Object *)(p_args[0]->operator Object *()));
  955. case INPUT_EVENT: return (InputEvent(*p_args[0]));
  956. case DICTIONARY: return p_args[0]->operator Dictionary();
  957. case ARRAY:
  958. return p_args[0]->operator Array(); // 20
  959. // arrays
  960. case RAW_ARRAY: return (ByteArray(*p_args[0]));
  961. case INT_ARRAY: return (IntArray(*p_args[0]));
  962. case REAL_ARRAY: return (RealArray(*p_args[0]));
  963. case STRING_ARRAY: return (StringArray(*p_args[0]));
  964. case VECTOR2_ARRAY:
  965. return (Vector2Array(*p_args[0])); // 25
  966. case VECTOR3_ARRAY:
  967. return (Vector3Array(*p_args[0])); // 25
  968. case COLOR_ARRAY: return (ColorArray(*p_args[0]));
  969. default: return Variant();
  970. }
  971. }
  972. r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; //no such constructor
  973. return Variant();
  974. }
  975. bool Variant::has_method(const StringName &p_method) const {
  976. if (type == OBJECT) {
  977. Object *obj = operator Object *();
  978. if (!obj)
  979. return false;
  980. #ifdef DEBUG_ENABLED
  981. if (ScriptDebugger::get_singleton()) {
  982. if (ObjectDB::instance_validate(obj)) {
  983. #endif
  984. return obj->has_method(p_method);
  985. #ifdef DEBUG_ENABLED
  986. }
  987. }
  988. #endif
  989. }
  990. const _VariantCall::TypeFunc &fd = _VariantCall::type_funcs[type];
  991. return fd.functions.has(p_method);
  992. }
  993. void Variant::get_method_list(List<MethodInfo> *p_list) const {
  994. const _VariantCall::TypeFunc &fd = _VariantCall::type_funcs[type];
  995. for (const Map<StringName, _VariantCall::FuncData>::Element *E = fd.functions.front(); E; E = E->next()) {
  996. const _VariantCall::FuncData &fd = E->get();
  997. MethodInfo mi;
  998. mi.name = E->key();
  999. for (int i = 0; i < fd.arg_types.size(); i++) {
  1000. PropertyInfo pi;
  1001. pi.type = fd.arg_types[i];
  1002. #ifdef DEBUG_ENABLED
  1003. pi.name = fd.arg_names[i];
  1004. #endif
  1005. mi.arguments.push_back(pi);
  1006. }
  1007. mi.default_arguments = fd.default_args;
  1008. PropertyInfo ret;
  1009. #ifdef DEBUG_ENABLED
  1010. ret.type = fd.return_type;
  1011. if (fd.returns)
  1012. ret.name = "ret";
  1013. mi.return_val = ret;
  1014. #endif
  1015. p_list->push_back(mi);
  1016. }
  1017. }
  1018. void Variant::get_constructor_list(Variant::Type p_type, List<MethodInfo> *p_list) {
  1019. ERR_FAIL_INDEX(p_type, VARIANT_MAX);
  1020. //custom constructors
  1021. for (const List<_VariantCall::ConstructData>::Element *E = _VariantCall::construct_funcs[p_type].constructors.front(); E; E = E->next()) {
  1022. const _VariantCall::ConstructData &cd = E->get();
  1023. MethodInfo mi;
  1024. mi.name = Variant::get_type_name(p_type);
  1025. mi.return_val.type = p_type;
  1026. for (int i = 0; i < cd.arg_count; i++) {
  1027. PropertyInfo pi;
  1028. pi.name = cd.arg_names[i];
  1029. pi.type = cd.arg_types[i];
  1030. mi.arguments.push_back(pi);
  1031. }
  1032. p_list->push_back(mi);
  1033. }
  1034. //default constructors
  1035. for (int i = 0; i < VARIANT_MAX; i++) {
  1036. if (i == p_type)
  1037. continue;
  1038. if (!Variant::can_convert(Variant::Type(i), p_type))
  1039. continue;
  1040. MethodInfo mi;
  1041. mi.name = Variant::get_type_name(p_type);
  1042. PropertyInfo pi;
  1043. pi.name = "from";
  1044. pi.type = Variant::Type(i);
  1045. mi.arguments.push_back(pi);
  1046. mi.return_val.type = p_type;
  1047. p_list->push_back(mi);
  1048. }
  1049. }
  1050. void Variant::get_numeric_constants_for_type(Variant::Type p_type, List<StringName> *p_constants) {
  1051. ERR_FAIL_INDEX(p_type, Variant::VARIANT_MAX);
  1052. _VariantCall::ConstantData &cd = _VariantCall::constant_data[p_type];
  1053. #ifdef DEBUG_ENABLED
  1054. for (List<StringName>::Element *E = cd.value_ordered.front(); E; E = E->next()) {
  1055. p_constants->push_back(E->get());
  1056. #else
  1057. for (Map<StringName, int>::Element *E = cd.value.front(); E; E = E->next()) {
  1058. p_constants->push_back(E->key());
  1059. #endif
  1060. }
  1061. }
  1062. bool Variant::has_numeric_constant(Variant::Type p_type, const StringName &p_value) {
  1063. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, false);
  1064. _VariantCall::ConstantData &cd = _VariantCall::constant_data[p_type];
  1065. return cd.value.has(p_value);
  1066. }
  1067. int Variant::get_numeric_constant_value(Variant::Type p_type, const StringName &p_value) {
  1068. ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, 0);
  1069. _VariantCall::ConstantData &cd = _VariantCall::constant_data[p_type];
  1070. Map<StringName, int>::Element *E = cd.value.find(p_value);
  1071. ERR_FAIL_COND_V(!E, 0);
  1072. return E->get();
  1073. }
  1074. void register_variant_methods() {
  1075. _VariantCall::type_funcs = memnew_arr(_VariantCall::TypeFunc, Variant::VARIANT_MAX);
  1076. _VariantCall::construct_funcs = memnew_arr(_VariantCall::ConstructFunc, Variant::VARIANT_MAX);
  1077. _VariantCall::constant_data = memnew_arr(_VariantCall::ConstantData, Variant::VARIANT_MAX);
  1078. #define ADDFUNC0(m_vtype, m_ret, m_class, m_method, m_defarg) \
  1079. _VariantCall::addfunc(Variant::m_vtype, Variant::m_ret, _SCS(#m_method), VCALL(m_class, m_method), m_defarg);
  1080. #define ADDFUNC1(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_defarg) \
  1081. _VariantCall::addfunc(Variant::m_vtype, Variant::m_ret, _SCS(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _SCS(m_argname1)));
  1082. #define ADDFUNC2(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_defarg) \
  1083. _VariantCall::addfunc(Variant::m_vtype, Variant::m_ret, _SCS(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _SCS(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _SCS(m_argname2)));
  1084. #define ADDFUNC3(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_arg3, m_argname3, m_defarg) \
  1085. _VariantCall::addfunc(Variant::m_vtype, Variant::m_ret, _SCS(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _SCS(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _SCS(m_argname2)), _VariantCall::Arg(Variant::m_arg3, _SCS(m_argname3)));
  1086. #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) \
  1087. _VariantCall::addfunc(Variant::m_vtype, Variant::m_ret, _SCS(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _SCS(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _SCS(m_argname2)), _VariantCall::Arg(Variant::m_arg3, _SCS(m_argname3)), _VariantCall::Arg(Variant::m_arg4, _SCS(m_argname4)));
  1088. /* STRING */
  1089. ADDFUNC1(STRING, INT, String, casecmp_to, STRING, "to", varray());
  1090. ADDFUNC1(STRING, INT, String, nocasecmp_to, STRING, "to", varray());
  1091. ADDFUNC0(STRING, INT, String, length, varray());
  1092. ADDFUNC2(STRING, STRING, String, substr, INT, "from", INT, "len", varray());
  1093. ADDFUNC2(STRING, INT, String, find, STRING, "what", INT, "from", varray(0));
  1094. ADDFUNC1(STRING, INT, String, find_last, STRING, "what", varray());
  1095. ADDFUNC2(STRING, INT, String, findn, STRING, "what", INT, "from", varray(0));
  1096. ADDFUNC2(STRING, INT, String, rfind, STRING, "what", INT, "from", varray(-1));
  1097. ADDFUNC2(STRING, INT, String, rfindn, STRING, "what", INT, "from", varray(-1));
  1098. ADDFUNC1(STRING, BOOL, String, match, STRING, "expr", varray());
  1099. ADDFUNC1(STRING, BOOL, String, matchn, STRING, "expr", varray());
  1100. ADDFUNC1(STRING, BOOL, String, begins_with, STRING, "text", varray());
  1101. ADDFUNC1(STRING, BOOL, String, ends_with, STRING, "text", varray());
  1102. ADDFUNC1(STRING, BOOL, String, is_subsequence_of, STRING, "text", varray());
  1103. ADDFUNC1(STRING, BOOL, String, is_subsequence_ofi, STRING, "text", varray());
  1104. ADDFUNC0(STRING, STRING_ARRAY, String, bigrams, varray());
  1105. ADDFUNC1(STRING, REAL, String, similarity, STRING, "text", varray());
  1106. ADDFUNC2(STRING, STRING, String, format, NIL, "values", STRING, "placeholder", varray("{_}"));
  1107. ADDFUNC2(STRING, STRING, String, replace, STRING, "what", STRING, "forwhat", varray());
  1108. ADDFUNC2(STRING, STRING, String, replacen, STRING, "what", STRING, "forwhat", varray());
  1109. ADDFUNC2(STRING, STRING, String, insert, INT, "pos", STRING, "what", varray());
  1110. ADDFUNC0(STRING, STRING, String, capitalize, varray());
  1111. ADDFUNC2(STRING, STRING_ARRAY, String, split, STRING, "divisor", BOOL, "allow_empty", varray(true));
  1112. ADDFUNC2(STRING, REAL_ARRAY, String, split_floats, STRING, "divisor", BOOL, "allow_empty", varray(true));
  1113. ADDFUNC0(STRING, STRING, String, to_upper, varray());
  1114. ADDFUNC0(STRING, STRING, String, to_lower, varray());
  1115. ADDFUNC1(STRING, STRING, String, left, INT, "pos", varray());
  1116. ADDFUNC1(STRING, STRING, String, right, INT, "pos", varray());
  1117. ADDFUNC2(STRING, STRING, String, strip_edges, BOOL, "left", BOOL, "right", varray(true, true));
  1118. ADDFUNC0(STRING, STRING, String, extension, varray());
  1119. ADDFUNC0(STRING, STRING, String, basename, varray());
  1120. ADDFUNC1(STRING, STRING, String, plus_file, STRING, "file", varray());
  1121. ADDFUNC1(STRING, INT, String, ord_at, INT, "at", varray());
  1122. ADDFUNC2(STRING, NIL, String, erase, INT, "pos", INT, "chars", varray());
  1123. ADDFUNC0(STRING, INT, String, hash, varray());
  1124. ADDFUNC0(STRING, STRING, String, md5_text, varray());
  1125. ADDFUNC0(STRING, STRING, String, sha256_text, varray());
  1126. ADDFUNC1(STRING, STRING, String, encrypt_text, STRING, "key", varray());
  1127. ADDFUNC1(STRING, STRING, String, decrypt_text, STRING, "key", varray());
  1128. ADDFUNC0(STRING, RAW_ARRAY, String, md5_buffer, varray());
  1129. ADDFUNC0(STRING, RAW_ARRAY, String, sha256_buffer, varray());
  1130. ADDFUNC0(STRING, BOOL, String, empty, varray());
  1131. ADDFUNC0(STRING, BOOL, String, is_abs_path, varray());
  1132. ADDFUNC0(STRING, BOOL, String, is_rel_path, varray());
  1133. ADDFUNC0(STRING, STRING, String, get_base_dir, varray());
  1134. ADDFUNC0(STRING, STRING, String, get_file, varray());
  1135. ADDFUNC0(STRING, STRING, String, xml_escape, varray());
  1136. ADDFUNC0(STRING, STRING, String, xml_unescape, varray());
  1137. ADDFUNC0(STRING, STRING, String, c_escape, varray());
  1138. ADDFUNC0(STRING, STRING, String, c_unescape, varray());
  1139. ADDFUNC0(STRING, STRING, String, json_escape, varray());
  1140. ADDFUNC0(STRING, STRING, String, percent_encode, varray());
  1141. ADDFUNC0(STRING, STRING, String, percent_decode, varray());
  1142. ADDFUNC0(STRING, BOOL, String, is_valid_identifier, varray());
  1143. ADDFUNC0(STRING, BOOL, String, is_valid_integer, varray());
  1144. ADDFUNC0(STRING, BOOL, String, is_valid_float, varray());
  1145. ADDFUNC0(STRING, BOOL, String, is_valid_html_color, varray());
  1146. ADDFUNC0(STRING, BOOL, String, is_valid_ip_address, varray());
  1147. ADDFUNC0(STRING, INT, String, to_int, varray());
  1148. ADDFUNC0(STRING, REAL, String, to_float, varray());
  1149. ADDFUNC0(STRING, INT, String, hex_to_int, varray());
  1150. ADDFUNC1(STRING, STRING, String, pad_decimals, INT, "digits", varray());
  1151. ADDFUNC1(STRING, STRING, String, pad_zeros, INT, "digits", varray());
  1152. ADDFUNC0(STRING, RAW_ARRAY, String, to_ascii, varray());
  1153. ADDFUNC0(STRING, RAW_ARRAY, String, to_utf8, varray());
  1154. ADDFUNC0(VECTOR2, VECTOR2, Vector2, normalized, varray());
  1155. ADDFUNC0(VECTOR2, REAL, Vector2, length, varray());
  1156. ADDFUNC0(VECTOR2, REAL, Vector2, angle, varray());
  1157. ADDFUNC0(VECTOR2, REAL, Vector2, length_squared, varray());
  1158. ADDFUNC1(VECTOR2, REAL, Vector2, distance_to, VECTOR2, "to", varray());
  1159. ADDFUNC1(VECTOR2, REAL, Vector2, distance_squared_to, VECTOR2, "to", varray());
  1160. ADDFUNC1(VECTOR2, REAL, Vector2, angle_to, VECTOR2, "to", varray());
  1161. ADDFUNC1(VECTOR2, REAL, Vector2, angle_to_point, VECTOR2, "to", varray());
  1162. ADDFUNC2(VECTOR2, VECTOR2, Vector2, linear_interpolate, VECTOR2, "b", REAL, "t", varray());
  1163. ADDFUNC4(VECTOR2, VECTOR2, Vector2, cubic_interpolate, VECTOR2, "b", VECTOR2, "pre_a", VECTOR2, "post_b", REAL, "t", varray());
  1164. ADDFUNC1(VECTOR2, VECTOR2, Vector2, rotated, REAL, "phi", varray());
  1165. ADDFUNC0(VECTOR2, VECTOR2, Vector2, tangent, varray());
  1166. ADDFUNC0(VECTOR2, VECTOR2, Vector2, floor, varray());
  1167. ADDFUNC0(VECTOR2, VECTOR2, Vector2, floorf, varray());
  1168. ADDFUNC1(VECTOR2, VECTOR2, Vector2, snapped, VECTOR2, "by", varray());
  1169. ADDFUNC0(VECTOR2, REAL, Vector2, get_aspect, varray());
  1170. ADDFUNC1(VECTOR2, REAL, Vector2, dot, VECTOR2, "with", varray());
  1171. ADDFUNC1(VECTOR2, VECTOR2, Vector2, slide, VECTOR2, "vec", varray());
  1172. ADDFUNC1(VECTOR2, VECTOR2, Vector2, reflect, VECTOR2, "vec", varray());
  1173. //ADDFUNC1(VECTOR2,REAL,Vector2,cross,VECTOR2,"with",varray());
  1174. ADDFUNC0(VECTOR2, VECTOR2, Vector2, abs, varray());
  1175. ADDFUNC1(VECTOR2, VECTOR2, Vector2, clamped, REAL, "length", varray());
  1176. ADDFUNC0(RECT2, REAL, Rect2, get_area, varray());
  1177. ADDFUNC1(RECT2, BOOL, Rect2, intersects, RECT2, "b", varray());
  1178. ADDFUNC1(RECT2, BOOL, Rect2, encloses, RECT2, "b", varray());
  1179. ADDFUNC0(RECT2, BOOL, Rect2, has_no_area, varray());
  1180. ADDFUNC1(RECT2, RECT2, Rect2, clip, RECT2, "b", varray());
  1181. ADDFUNC1(RECT2, RECT2, Rect2, merge, RECT2, "b", varray());
  1182. ADDFUNC1(RECT2, BOOL, Rect2, has_point, VECTOR2, "point", varray());
  1183. ADDFUNC1(RECT2, RECT2, Rect2, grow, REAL, "by", varray());
  1184. ADDFUNC2(RECT2, RECT2, Rect2, grow_margin, INT, "margin", REAL, "by", varray());
  1185. ADDFUNC4(RECT2, RECT2, Rect2, grow_individual, REAL, "left", REAL, "top", REAL, "right", REAL, " bottom", varray());
  1186. ADDFUNC1(RECT2, RECT2, Rect2, expand, VECTOR2, "to", varray());
  1187. ADDFUNC0(VECTOR3, INT, Vector3, min_axis, varray());
  1188. ADDFUNC0(VECTOR3, INT, Vector3, max_axis, varray());
  1189. ADDFUNC0(VECTOR3, REAL, Vector3, length, varray());
  1190. ADDFUNC0(VECTOR3, REAL, Vector3, length_squared, varray());
  1191. ADDFUNC0(VECTOR3, VECTOR3, Vector3, normalized, varray());
  1192. ADDFUNC0(VECTOR3, VECTOR3, Vector3, inverse, varray());
  1193. ADDFUNC1(VECTOR3, VECTOR3, Vector3, snapped, REAL, "by", varray());
  1194. ADDFUNC2(VECTOR3, VECTOR3, Vector3, rotated, VECTOR3, "axis", REAL, "phi", varray());
  1195. ADDFUNC2(VECTOR3, VECTOR3, Vector3, linear_interpolate, VECTOR3, "b", REAL, "t", varray());
  1196. ADDFUNC4(VECTOR3, VECTOR3, Vector3, cubic_interpolate, VECTOR3, "b", VECTOR3, "pre_a", VECTOR3, "post_b", REAL, "t", varray());
  1197. ADDFUNC1(VECTOR3, REAL, Vector3, dot, VECTOR3, "b", varray());
  1198. ADDFUNC1(VECTOR3, VECTOR3, Vector3, cross, VECTOR3, "b", varray());
  1199. ADDFUNC0(VECTOR3, VECTOR3, Vector3, abs, varray());
  1200. ADDFUNC0(VECTOR3, VECTOR3, Vector3, floor, varray());
  1201. ADDFUNC0(VECTOR3, VECTOR3, Vector3, ceil, varray());
  1202. ADDFUNC1(VECTOR3, REAL, Vector3, distance_to, VECTOR3, "b", varray());
  1203. ADDFUNC1(VECTOR3, REAL, Vector3, distance_squared_to, VECTOR3, "b", varray());
  1204. ADDFUNC1(VECTOR3, REAL, Vector3, angle_to, VECTOR3, "to", varray());
  1205. ADDFUNC1(VECTOR3, VECTOR3, Vector3, slide, VECTOR3, "by", varray());
  1206. ADDFUNC1(VECTOR3, VECTOR3, Vector3, reflect, VECTOR3, "by", varray());
  1207. ADDFUNC0(PLANE, PLANE, Plane, normalized, varray());
  1208. ADDFUNC0(PLANE, VECTOR3, Plane, center, varray());
  1209. ADDFUNC0(PLANE, VECTOR3, Plane, get_any_point, varray());
  1210. ADDFUNC1(PLANE, BOOL, Plane, is_point_over, VECTOR3, "point", varray());
  1211. ADDFUNC1(PLANE, REAL, Plane, distance_to, VECTOR3, "point", varray());
  1212. ADDFUNC2(PLANE, BOOL, Plane, has_point, VECTOR3, "point", REAL, "epsilon", varray(CMP_EPSILON));
  1213. ADDFUNC1(PLANE, VECTOR3, Plane, project, VECTOR3, "point", varray());
  1214. ADDFUNC2(PLANE, VECTOR3, Plane, intersect_3, PLANE, "b", PLANE, "c", varray());
  1215. ADDFUNC2(PLANE, VECTOR3, Plane, intersects_ray, VECTOR3, "from", VECTOR3, "dir", varray());
  1216. ADDFUNC2(PLANE, VECTOR3, Plane, intersects_segment, VECTOR3, "begin", VECTOR3, "end", varray());
  1217. ADDFUNC0(QUAT, REAL, Quat, length, varray());
  1218. ADDFUNC0(QUAT, REAL, Quat, length_squared, varray());
  1219. ADDFUNC0(QUAT, QUAT, Quat, normalized, varray());
  1220. ADDFUNC0(QUAT, QUAT, Quat, inverse, varray());
  1221. ADDFUNC1(QUAT, REAL, Quat, dot, QUAT, "b", varray());
  1222. ADDFUNC1(QUAT, VECTOR3, Quat, xform, VECTOR3, "v", varray());
  1223. ADDFUNC2(QUAT, QUAT, Quat, slerp, QUAT, "b", REAL, "t", varray());
  1224. ADDFUNC2(QUAT, QUAT, Quat, slerpni, QUAT, "b", REAL, "t", varray());
  1225. ADDFUNC4(QUAT, QUAT, Quat, cubic_slerp, QUAT, "b", QUAT, "pre_a", QUAT, "post_b", REAL, "t", varray());
  1226. ADDFUNC0(COLOR, INT, Color, to_32, varray());
  1227. ADDFUNC0(COLOR, INT, Color, to_ARGB32, varray());
  1228. ADDFUNC0(COLOR, REAL, Color, gray, varray());
  1229. ADDFUNC0(COLOR, COLOR, Color, inverted, varray());
  1230. ADDFUNC0(COLOR, COLOR, Color, contrasted, varray());
  1231. ADDFUNC2(COLOR, COLOR, Color, linear_interpolate, COLOR, "b", REAL, "t", varray());
  1232. ADDFUNC1(COLOR, COLOR, Color, blend, COLOR, "over", varray());
  1233. ADDFUNC1(COLOR, STRING, Color, to_html, BOOL, "with_alpha", varray(true));
  1234. ADDFUNC0(IMAGE, INT, Image, get_format, varray());
  1235. ADDFUNC0(IMAGE, INT, Image, get_width, varray());
  1236. ADDFUNC0(IMAGE, INT, Image, get_height, varray());
  1237. ADDFUNC0(IMAGE, BOOL, Image, empty, varray());
  1238. ADDFUNC3(IMAGE, COLOR, Image, get_pixel, INT, "x", INT, "y", INT, "mipmap_level", varray(0));
  1239. ADDFUNC4(IMAGE, NIL, Image, put_pixel, INT, "x", INT, "y", COLOR, "color", INT, "mipmap_level", varray(0));
  1240. ADDFUNC3(IMAGE, IMAGE, Image, brushed, IMAGE, "src", IMAGE, "brush", VECTOR2, "pos", varray(0));
  1241. ADDFUNC1(IMAGE, INT, Image, load, STRING, "path", varray(0));
  1242. ADDFUNC1(IMAGE, INT, Image, save_png, STRING, "path", varray(0));
  1243. ADDFUNC3(IMAGE, NIL, Image, brush_transfer, IMAGE, "src", IMAGE, "brush", VECTOR2, "pos", varray(0));
  1244. ADDFUNC0(IMAGE, RECT2, Image, get_used_rect, varray(0));
  1245. ADDFUNC1(IMAGE, IMAGE, Image, get_rect, RECT2, "area", varray(0));
  1246. ADDFUNC1(IMAGE, IMAGE, Image, compressed, INT, "format", varray(0));
  1247. ADDFUNC0(IMAGE, IMAGE, Image, decompressed, varray(0));
  1248. ADDFUNC3(IMAGE, IMAGE, Image, resized, INT, "x", INT, "y", INT, "interpolation", varray(((int)Image::INTERPOLATE_BILINEAR)));
  1249. ADDFUNC0(IMAGE, RAW_ARRAY, Image, get_data, varray());
  1250. ADDFUNC3(IMAGE, NIL, Image, blit_rect, IMAGE, "src", RECT2, "src_rect", VECTOR2, "dest", varray(0));
  1251. ADDFUNC4(IMAGE, NIL, Image, blit_rect_mask, IMAGE, "src", IMAGE, "mask", RECT2, "src_rect", VECTOR2, "dest", varray(0));
  1252. ADDFUNC3(IMAGE, NIL, Image, blend_rect, IMAGE, "src", RECT2, "src_rect", VECTOR2, "dest", varray(0));
  1253. ADDFUNC4(IMAGE, NIL, Image, blend_rect_mask, IMAGE, "src", IMAGE, "mask", RECT2, "src_rect", VECTOR2, "dest", varray(0));
  1254. ADDFUNC1(IMAGE, NIL, Image, fill, COLOR, "color", varray(0));
  1255. ADDFUNC1(IMAGE, IMAGE, Image, converted, INT, "format", varray(0));
  1256. ADDFUNC0(IMAGE, NIL, Image, fix_alpha_edges, varray());
  1257. ADDFUNC0(_RID, INT, RID, get_id, varray());
  1258. ADDFUNC0(NODE_PATH, BOOL, NodePath, is_absolute, varray());
  1259. ADDFUNC0(NODE_PATH, INT, NodePath, get_name_count, varray());
  1260. ADDFUNC1(NODE_PATH, STRING, NodePath, get_name, INT, "idx", varray());
  1261. ADDFUNC0(NODE_PATH, INT, NodePath, get_subname_count, varray());
  1262. ADDFUNC1(NODE_PATH, STRING, NodePath, get_subname, INT, "idx", varray());
  1263. ADDFUNC0(NODE_PATH, STRING, NodePath, get_property, varray());
  1264. ADDFUNC0(NODE_PATH, BOOL, NodePath, is_empty, varray());
  1265. ADDFUNC0(DICTIONARY, INT, Dictionary, size, varray());
  1266. ADDFUNC0(DICTIONARY, BOOL, Dictionary, empty, varray());
  1267. ADDFUNC0(DICTIONARY, NIL, Dictionary, clear, varray());
  1268. ADDFUNC1(DICTIONARY, BOOL, Dictionary, has, NIL, "key", varray());
  1269. ADDFUNC1(DICTIONARY, BOOL, Dictionary, has_all, ARRAY, "keys", varray());
  1270. ADDFUNC1(DICTIONARY, NIL, Dictionary, erase, NIL, "key", varray());
  1271. ADDFUNC0(DICTIONARY, INT, Dictionary, hash, varray());
  1272. ADDFUNC0(DICTIONARY, ARRAY, Dictionary, keys, varray());
  1273. ADDFUNC0(DICTIONARY, ARRAY, Dictionary, values, varray());
  1274. ADDFUNC1(DICTIONARY, INT, Dictionary, parse_json, STRING, "json", varray());
  1275. ADDFUNC0(DICTIONARY, STRING, Dictionary, to_json, varray());
  1276. ADDFUNC0(ARRAY, INT, Array, size, varray());
  1277. ADDFUNC0(ARRAY, BOOL, Array, empty, varray());
  1278. ADDFUNC0(ARRAY, NIL, Array, clear, varray());
  1279. ADDFUNC0(ARRAY, INT, Array, hash, varray());
  1280. ADDFUNC1(ARRAY, NIL, Array, push_back, NIL, "value", varray());
  1281. ADDFUNC1(ARRAY, NIL, Array, push_front, NIL, "value", varray());
  1282. ADDFUNC1(ARRAY, NIL, Array, append, NIL, "value", varray());
  1283. ADDFUNC1(ARRAY, NIL, Array, resize, INT, "pos", varray());
  1284. ADDFUNC2(ARRAY, NIL, Array, insert, INT, "pos", NIL, "value", varray());
  1285. ADDFUNC1(ARRAY, NIL, Array, remove, INT, "pos", varray());
  1286. ADDFUNC1(ARRAY, NIL, Array, erase, NIL, "value", varray());
  1287. ADDFUNC0(ARRAY, NIL, Array, front, varray());
  1288. ADDFUNC0(ARRAY, NIL, Array, back, varray());
  1289. ADDFUNC2(ARRAY, INT, Array, find, NIL, "what", INT, "from", varray(0));
  1290. ADDFUNC2(ARRAY, INT, Array, rfind, NIL, "what", INT, "from", varray(-1));
  1291. ADDFUNC1(ARRAY, INT, Array, find_last, NIL, "value", varray());
  1292. ADDFUNC1(ARRAY, INT, Array, count, NIL, "value", varray());
  1293. ADDFUNC1(ARRAY, BOOL, Array, has, NIL, "value", varray());
  1294. ADDFUNC0(ARRAY, NIL, Array, pop_back, varray());
  1295. ADDFUNC0(ARRAY, NIL, Array, pop_front, varray());
  1296. ADDFUNC0(ARRAY, NIL, Array, sort, varray());
  1297. ADDFUNC2(ARRAY, NIL, Array, sort_custom, OBJECT, "obj", STRING, "func", varray());
  1298. ADDFUNC0(ARRAY, NIL, Array, invert, varray());
  1299. ADDFUNC0(ARRAY, BOOL, Array, is_shared, varray());
  1300. ADDFUNC0(RAW_ARRAY, INT, ByteArray, size, varray());
  1301. ADDFUNC2(RAW_ARRAY, NIL, ByteArray, set, INT, "idx", INT, "byte", varray());
  1302. ADDFUNC1(RAW_ARRAY, NIL, ByteArray, push_back, INT, "byte", varray());
  1303. ADDFUNC1(RAW_ARRAY, NIL, ByteArray, append, INT, "byte", varray());
  1304. ADDFUNC1(RAW_ARRAY, NIL, ByteArray, append_array, RAW_ARRAY, "array", varray());
  1305. ADDFUNC1(RAW_ARRAY, NIL, ByteArray, remove, INT, "idx", varray());
  1306. ADDFUNC2(RAW_ARRAY, INT, ByteArray, insert, INT, "idx", INT, "byte", varray());
  1307. ADDFUNC1(RAW_ARRAY, NIL, ByteArray, resize, INT, "idx", varray());
  1308. ADDFUNC0(RAW_ARRAY, NIL, ByteArray, invert, varray());
  1309. ADDFUNC0(RAW_ARRAY, STRING, ByteArray, get_string_from_ascii, varray());
  1310. ADDFUNC0(RAW_ARRAY, STRING, ByteArray, get_string_from_utf8, varray());
  1311. ADDFUNC0(INT_ARRAY, INT, IntArray, size, varray());
  1312. ADDFUNC2(INT_ARRAY, NIL, IntArray, set, INT, "idx", INT, "integer", varray());
  1313. ADDFUNC1(INT_ARRAY, NIL, IntArray, push_back, INT, "integer", varray());
  1314. ADDFUNC1(INT_ARRAY, NIL, IntArray, append, INT, "integer", varray());
  1315. ADDFUNC1(INT_ARRAY, NIL, IntArray, append_array, INT_ARRAY, "array", varray());
  1316. ADDFUNC1(INT_ARRAY, NIL, IntArray, remove, INT, "idx", varray());
  1317. ADDFUNC2(INT_ARRAY, INT, IntArray, insert, INT, "idx", INT, "integer", varray());
  1318. ADDFUNC1(INT_ARRAY, NIL, IntArray, resize, INT, "idx", varray());
  1319. ADDFUNC0(INT_ARRAY, NIL, IntArray, invert, varray());
  1320. ADDFUNC0(REAL_ARRAY, INT, RealArray, size, varray());
  1321. ADDFUNC2(REAL_ARRAY, NIL, RealArray, set, INT, "idx", REAL, "value", varray());
  1322. ADDFUNC1(REAL_ARRAY, NIL, RealArray, push_back, REAL, "value", varray());
  1323. ADDFUNC1(REAL_ARRAY, NIL, RealArray, append, REAL, "value", varray());
  1324. ADDFUNC1(REAL_ARRAY, NIL, RealArray, append_array, REAL_ARRAY, "array", varray());
  1325. ADDFUNC1(REAL_ARRAY, NIL, RealArray, remove, INT, "idx", varray());
  1326. ADDFUNC2(REAL_ARRAY, INT, RealArray, insert, INT, "idx", REAL, "value", varray());
  1327. ADDFUNC1(REAL_ARRAY, NIL, RealArray, resize, INT, "idx", varray());
  1328. ADDFUNC0(REAL_ARRAY, NIL, RealArray, invert, varray());
  1329. ADDFUNC0(STRING_ARRAY, INT, StringArray, size, varray());
  1330. ADDFUNC2(STRING_ARRAY, NIL, StringArray, set, INT, "idx", STRING, "string", varray());
  1331. ADDFUNC1(STRING_ARRAY, NIL, StringArray, push_back, STRING, "string", varray());
  1332. ADDFUNC1(STRING_ARRAY, NIL, StringArray, append, STRING, "string", varray());
  1333. ADDFUNC1(STRING_ARRAY, NIL, StringArray, append_array, STRING_ARRAY, "array", varray());
  1334. ADDFUNC1(STRING_ARRAY, NIL, StringArray, remove, INT, "idx", varray());
  1335. ADDFUNC2(STRING_ARRAY, INT, StringArray, insert, INT, "idx", STRING, "string", varray());
  1336. ADDFUNC1(STRING_ARRAY, NIL, StringArray, resize, INT, "idx", varray());
  1337. ADDFUNC0(STRING_ARRAY, NIL, StringArray, invert, varray());
  1338. ADDFUNC0(VECTOR2_ARRAY, INT, Vector2Array, size, varray());
  1339. ADDFUNC2(VECTOR2_ARRAY, NIL, Vector2Array, set, INT, "idx", VECTOR2, "vector2", varray());
  1340. ADDFUNC1(VECTOR2_ARRAY, NIL, Vector2Array, push_back, VECTOR2, "vector2", varray());
  1341. ADDFUNC1(VECTOR2_ARRAY, NIL, Vector2Array, append, VECTOR2, "vector2", varray());
  1342. ADDFUNC1(VECTOR2_ARRAY, NIL, Vector2Array, append_array, VECTOR2_ARRAY, "array", varray());
  1343. ADDFUNC1(VECTOR2_ARRAY, NIL, Vector2Array, remove, INT, "idx", varray());
  1344. ADDFUNC2(VECTOR2_ARRAY, INT, Vector2Array, insert, INT, "idx", VECTOR2, "vector2", varray());
  1345. ADDFUNC1(VECTOR2_ARRAY, NIL, Vector2Array, resize, INT, "idx", varray());
  1346. ADDFUNC0(VECTOR2_ARRAY, NIL, Vector2Array, invert, varray());
  1347. ADDFUNC0(VECTOR3_ARRAY, INT, Vector3Array, size, varray());
  1348. ADDFUNC2(VECTOR3_ARRAY, NIL, Vector3Array, set, INT, "idx", VECTOR3, "vector3", varray());
  1349. ADDFUNC1(VECTOR3_ARRAY, NIL, Vector3Array, push_back, VECTOR3, "vector3", varray());
  1350. ADDFUNC1(VECTOR3_ARRAY, NIL, Vector3Array, append, VECTOR3, "vector3", varray());
  1351. ADDFUNC1(VECTOR3_ARRAY, NIL, Vector3Array, append_array, VECTOR3_ARRAY, "array", varray());
  1352. ADDFUNC1(VECTOR3_ARRAY, NIL, Vector3Array, remove, INT, "idx", varray());
  1353. ADDFUNC2(VECTOR3_ARRAY, INT, Vector3Array, insert, INT, "idx", VECTOR3, "vector3", varray());
  1354. ADDFUNC1(VECTOR3_ARRAY, NIL, Vector3Array, resize, INT, "idx", varray());
  1355. ADDFUNC0(VECTOR3_ARRAY, NIL, Vector3Array, invert, varray());
  1356. ADDFUNC0(COLOR_ARRAY, INT, ColorArray, size, varray());
  1357. ADDFUNC2(COLOR_ARRAY, NIL, ColorArray, set, INT, "idx", COLOR, "color", varray());
  1358. ADDFUNC1(COLOR_ARRAY, NIL, ColorArray, push_back, COLOR, "color", varray());
  1359. ADDFUNC1(COLOR_ARRAY, NIL, ColorArray, append, COLOR, "color", varray());
  1360. ADDFUNC1(COLOR_ARRAY, NIL, ColorArray, append_array, COLOR_ARRAY, "array", varray());
  1361. ADDFUNC1(COLOR_ARRAY, NIL, ColorArray, remove, INT, "idx", varray());
  1362. ADDFUNC2(COLOR_ARRAY, INT, ColorArray, insert, INT, "idx", COLOR, "color", varray());
  1363. ADDFUNC1(COLOR_ARRAY, NIL, ColorArray, resize, INT, "idx", varray());
  1364. ADDFUNC0(COLOR_ARRAY, NIL, ColorArray, invert, varray());
  1365. //pointerbased
  1366. ADDFUNC0(_AABB, REAL, AABB, get_area, varray());
  1367. ADDFUNC0(_AABB, BOOL, AABB, has_no_area, varray());
  1368. ADDFUNC0(_AABB, BOOL, AABB, has_no_surface, varray());
  1369. ADDFUNC1(_AABB, BOOL, AABB, intersects, _AABB, "with", varray());
  1370. ADDFUNC1(_AABB, BOOL, AABB, encloses, _AABB, "with", varray());
  1371. ADDFUNC1(_AABB, _AABB, AABB, merge, _AABB, "with", varray());
  1372. ADDFUNC1(_AABB, _AABB, AABB, intersection, _AABB, "with", varray());
  1373. ADDFUNC1(_AABB, BOOL, AABB, intersects_plane, PLANE, "plane", varray());
  1374. ADDFUNC2(_AABB, BOOL, AABB, intersects_segment, VECTOR3, "from", VECTOR3, "to", varray());
  1375. ADDFUNC1(_AABB, BOOL, AABB, has_point, VECTOR3, "point", varray());
  1376. ADDFUNC1(_AABB, VECTOR3, AABB, get_support, VECTOR3, "dir", varray());
  1377. ADDFUNC0(_AABB, VECTOR3, AABB, get_longest_axis, varray());
  1378. ADDFUNC0(_AABB, INT, AABB, get_longest_axis_index, varray());
  1379. ADDFUNC0(_AABB, REAL, AABB, get_longest_axis_size, varray());
  1380. ADDFUNC0(_AABB, VECTOR3, AABB, get_shortest_axis, varray());
  1381. ADDFUNC0(_AABB, INT, AABB, get_shortest_axis_index, varray());
  1382. ADDFUNC0(_AABB, REAL, AABB, get_shortest_axis_size, varray());
  1383. ADDFUNC1(_AABB, _AABB, AABB, expand, VECTOR3, "to_point", varray());
  1384. ADDFUNC1(_AABB, _AABB, AABB, grow, REAL, "by", varray());
  1385. ADDFUNC1(_AABB, VECTOR3, AABB, get_endpoint, INT, "idx", varray());
  1386. ADDFUNC0(MATRIX32, MATRIX32, Matrix32, inverse, varray());
  1387. ADDFUNC0(MATRIX32, MATRIX32, Matrix32, affine_inverse, varray());
  1388. ADDFUNC0(MATRIX32, REAL, Matrix32, get_rotation, varray());
  1389. ADDFUNC0(MATRIX32, VECTOR2, Matrix32, get_origin, varray());
  1390. ADDFUNC0(MATRIX32, VECTOR2, Matrix32, get_scale, varray());
  1391. ADDFUNC0(MATRIX32, MATRIX32, Matrix32, orthonormalized, varray());
  1392. ADDFUNC1(MATRIX32, MATRIX32, Matrix32, rotated, REAL, "phi", varray());
  1393. ADDFUNC1(MATRIX32, MATRIX32, Matrix32, scaled, VECTOR2, "scale", varray());
  1394. ADDFUNC1(MATRIX32, MATRIX32, Matrix32, translated, VECTOR2, "offset", varray());
  1395. ADDFUNC1(MATRIX32, MATRIX32, Matrix32, xform, NIL, "v", varray());
  1396. ADDFUNC1(MATRIX32, MATRIX32, Matrix32, xform_inv, NIL, "v", varray());
  1397. ADDFUNC1(MATRIX32, MATRIX32, Matrix32, basis_xform, NIL, "v", varray());
  1398. ADDFUNC1(MATRIX32, MATRIX32, Matrix32, basis_xform_inv, NIL, "v", varray());
  1399. ADDFUNC2(MATRIX32, MATRIX32, Matrix32, interpolate_with, MATRIX32, "m", REAL, "c", varray());
  1400. ADDFUNC0(MATRIX3, MATRIX3, Matrix3, inverse, varray());
  1401. ADDFUNC0(MATRIX3, MATRIX3, Matrix3, transposed, varray());
  1402. ADDFUNC0(MATRIX3, MATRIX3, Matrix3, orthonormalized, varray());
  1403. ADDFUNC0(MATRIX3, REAL, Matrix3, determinant, varray());
  1404. ADDFUNC2(MATRIX3, MATRIX3, Matrix3, rotated, VECTOR3, "axis", REAL, "phi", varray());
  1405. ADDFUNC1(MATRIX3, MATRIX3, Matrix3, scaled, VECTOR3, "scale", varray());
  1406. ADDFUNC0(MATRIX3, VECTOR3, Matrix3, get_scale, varray());
  1407. ADDFUNC0(MATRIX3, VECTOR3, Matrix3, get_euler, varray());
  1408. ADDFUNC1(MATRIX3, REAL, Matrix3, tdotx, VECTOR3, "with", varray());
  1409. ADDFUNC1(MATRIX3, REAL, Matrix3, tdoty, VECTOR3, "with", varray());
  1410. ADDFUNC1(MATRIX3, REAL, Matrix3, tdotz, VECTOR3, "with", varray());
  1411. ADDFUNC1(MATRIX3, VECTOR3, Matrix3, xform, VECTOR3, "v", varray());
  1412. ADDFUNC1(MATRIX3, VECTOR3, Matrix3, xform_inv, VECTOR3, "v", varray());
  1413. ADDFUNC0(MATRIX3, INT, Matrix3, get_orthogonal_index, varray());
  1414. ADDFUNC0(TRANSFORM, TRANSFORM, Transform, inverse, varray());
  1415. ADDFUNC0(TRANSFORM, TRANSFORM, Transform, affine_inverse, varray());
  1416. ADDFUNC0(TRANSFORM, TRANSFORM, Transform, orthonormalized, varray());
  1417. ADDFUNC2(TRANSFORM, TRANSFORM, Transform, rotated, VECTOR3, "axis", REAL, "phi", varray());
  1418. ADDFUNC1(TRANSFORM, TRANSFORM, Transform, scaled, VECTOR3, "scale", varray());
  1419. ADDFUNC1(TRANSFORM, TRANSFORM, Transform, translated, VECTOR3, "ofs", varray());
  1420. ADDFUNC2(TRANSFORM, TRANSFORM, Transform, looking_at, VECTOR3, "target", VECTOR3, "up", varray());
  1421. ADDFUNC1(TRANSFORM, NIL, Transform, xform, NIL, "v", varray());
  1422. ADDFUNC1(TRANSFORM, NIL, Transform, xform_inv, NIL, "v", varray());
  1423. #ifdef DEBUG_ENABLED
  1424. _VariantCall::type_funcs[Variant::TRANSFORM].functions["xform"].returns = true;
  1425. _VariantCall::type_funcs[Variant::TRANSFORM].functions["xform_inv"].returns = true;
  1426. #endif
  1427. ADDFUNC0(INPUT_EVENT, BOOL, InputEvent, is_pressed, varray());
  1428. ADDFUNC1(INPUT_EVENT, BOOL, InputEvent, is_action, STRING, "action", varray());
  1429. ADDFUNC1(INPUT_EVENT, BOOL, InputEvent, is_action_pressed, STRING, "action", varray());
  1430. ADDFUNC1(INPUT_EVENT, BOOL, InputEvent, is_action_released, STRING, "action", varray());
  1431. ADDFUNC0(INPUT_EVENT, BOOL, InputEvent, is_echo, varray());
  1432. ADDFUNC2(INPUT_EVENT, NIL, InputEvent, set_as_action, STRING, "action", BOOL, "pressed", varray());
  1433. /* REGISTER CONSTRUCTORS */
  1434. _VariantCall::add_constructor(_VariantCall::Vector2_init1, Variant::VECTOR2, "x", Variant::REAL, "y", Variant::REAL);
  1435. _VariantCall::add_constructor(_VariantCall::Rect2_init1, Variant::RECT2, "pos", Variant::VECTOR2, "size", Variant::VECTOR2);
  1436. _VariantCall::add_constructor(_VariantCall::Rect2_init2, Variant::RECT2, "x", Variant::REAL, "y", Variant::REAL, "width", Variant::REAL, "height", Variant::REAL);
  1437. _VariantCall::add_constructor(_VariantCall::Matrix32_init2, Variant::MATRIX32, "rot", Variant::REAL, "pos", Variant::VECTOR2);
  1438. _VariantCall::add_constructor(_VariantCall::Matrix32_init3, Variant::MATRIX32, "x_axis", Variant::VECTOR2, "y_axis", Variant::VECTOR2, "origin", Variant::VECTOR2);
  1439. _VariantCall::add_constructor(_VariantCall::Vector3_init1, Variant::VECTOR3, "x", Variant::REAL, "y", Variant::REAL, "z", Variant::REAL);
  1440. _VariantCall::add_constructor(_VariantCall::Plane_init1, Variant::PLANE, "a", Variant::REAL, "b", Variant::REAL, "c", Variant::REAL, "d", Variant::REAL);
  1441. _VariantCall::add_constructor(_VariantCall::Plane_init2, Variant::PLANE, "v1", Variant::VECTOR3, "v2", Variant::VECTOR3, "v3", Variant::VECTOR3);
  1442. _VariantCall::add_constructor(_VariantCall::Plane_init3, Variant::PLANE, "normal", Variant::VECTOR3, "d", Variant::REAL);
  1443. _VariantCall::add_constructor(_VariantCall::Quat_init1, Variant::QUAT, "x", Variant::REAL, "y", Variant::REAL, "z", Variant::REAL, "w", Variant::REAL);
  1444. _VariantCall::add_constructor(_VariantCall::Quat_init2, Variant::QUAT, "axis", Variant::VECTOR3, "angle", Variant::REAL);
  1445. _VariantCall::add_constructor(_VariantCall::Color_init1, Variant::COLOR, "r", Variant::REAL, "g", Variant::REAL, "b", Variant::REAL, "a", Variant::REAL);
  1446. _VariantCall::add_constructor(_VariantCall::Color_init2, Variant::COLOR, "r", Variant::REAL, "g", Variant::REAL, "b", Variant::REAL);
  1447. _VariantCall::add_constructor(_VariantCall::AABB_init1, Variant::_AABB, "pos", Variant::VECTOR3, "size", Variant::VECTOR3);
  1448. _VariantCall::add_constructor(_VariantCall::Matrix3_init1, Variant::MATRIX3, "x_axis", Variant::VECTOR3, "y_axis", Variant::VECTOR3, "z_axis", Variant::VECTOR3);
  1449. _VariantCall::add_constructor(_VariantCall::Matrix3_init2, Variant::MATRIX3, "axis", Variant::VECTOR3, "phi", Variant::REAL);
  1450. _VariantCall::add_constructor(_VariantCall::Transform_init1, Variant::TRANSFORM, "x_axis", Variant::VECTOR3, "y_axis", Variant::VECTOR3, "z_axis", Variant::VECTOR3, "origin", Variant::VECTOR3);
  1451. _VariantCall::add_constructor(_VariantCall::Transform_init2, Variant::TRANSFORM, "basis", Variant::MATRIX3, "origin", Variant::VECTOR3);
  1452. _VariantCall::add_constructor(_VariantCall::Image_init1, Variant::IMAGE, "width", Variant::INT, "height", Variant::INT, "mipmaps", Variant::BOOL, "format", Variant::INT);
  1453. /* REGISTER CONSTANTS */
  1454. _VariantCall::add_constant(Variant::VECTOR3, "AXIS_X", Vector3::AXIS_X);
  1455. _VariantCall::add_constant(Variant::VECTOR3, "AXIS_Y", Vector3::AXIS_Y);
  1456. _VariantCall::add_constant(Variant::VECTOR3, "AXIS_Z", Vector3::AXIS_Z);
  1457. _VariantCall::add_constant(Variant::INPUT_EVENT, "NONE", InputEvent::NONE);
  1458. _VariantCall::add_constant(Variant::INPUT_EVENT, "KEY", InputEvent::KEY);
  1459. _VariantCall::add_constant(Variant::INPUT_EVENT, "MOUSE_MOTION", InputEvent::MOUSE_MOTION);
  1460. _VariantCall::add_constant(Variant::INPUT_EVENT, "MOUSE_BUTTON", InputEvent::MOUSE_BUTTON);
  1461. _VariantCall::add_constant(Variant::INPUT_EVENT, "JOYSTICK_MOTION", InputEvent::JOYSTICK_MOTION);
  1462. _VariantCall::add_constant(Variant::INPUT_EVENT, "JOYSTICK_BUTTON", InputEvent::JOYSTICK_BUTTON);
  1463. _VariantCall::add_constant(Variant::INPUT_EVENT, "SCREEN_TOUCH", InputEvent::SCREEN_TOUCH);
  1464. _VariantCall::add_constant(Variant::INPUT_EVENT, "SCREEN_DRAG", InputEvent::SCREEN_DRAG);
  1465. _VariantCall::add_constant(Variant::INPUT_EVENT, "ACTION", InputEvent::ACTION);
  1466. _VariantCall::add_constant(Variant::IMAGE, "COMPRESS_BC", Image::COMPRESS_BC);
  1467. _VariantCall::add_constant(Variant::IMAGE, "COMPRESS_PVRTC2", Image::COMPRESS_PVRTC2);
  1468. _VariantCall::add_constant(Variant::IMAGE, "COMPRESS_PVRTC4", Image::COMPRESS_PVRTC4);
  1469. _VariantCall::add_constant(Variant::IMAGE, "COMPRESS_ETC", Image::COMPRESS_ETC);
  1470. _VariantCall::add_constant(Variant::IMAGE, "FORMAT_GRAYSCALE", Image::FORMAT_GRAYSCALE);
  1471. _VariantCall::add_constant(Variant::IMAGE, "FORMAT_INTENSITY", Image::FORMAT_INTENSITY);
  1472. _VariantCall::add_constant(Variant::IMAGE, "FORMAT_GRAYSCALE_ALPHA", Image::FORMAT_GRAYSCALE_ALPHA);
  1473. _VariantCall::add_constant(Variant::IMAGE, "FORMAT_RGB", Image::FORMAT_RGB);
  1474. _VariantCall::add_constant(Variant::IMAGE, "FORMAT_RGBA", Image::FORMAT_RGBA);
  1475. _VariantCall::add_constant(Variant::IMAGE, "FORMAT_INDEXED", Image::FORMAT_INDEXED);
  1476. _VariantCall::add_constant(Variant::IMAGE, "FORMAT_INDEXED_ALPHA", Image::FORMAT_INDEXED_ALPHA);
  1477. _VariantCall::add_constant(Variant::IMAGE, "FORMAT_YUV_422", Image::FORMAT_YUV_422);
  1478. _VariantCall::add_constant(Variant::IMAGE, "FORMAT_YUV_444", Image::FORMAT_YUV_444);
  1479. _VariantCall::add_constant(Variant::IMAGE, "FORMAT_BC1", Image::FORMAT_BC1);
  1480. _VariantCall::add_constant(Variant::IMAGE, "FORMAT_BC2", Image::FORMAT_BC2);
  1481. _VariantCall::add_constant(Variant::IMAGE, "FORMAT_BC3", Image::FORMAT_BC3);
  1482. _VariantCall::add_constant(Variant::IMAGE, "FORMAT_BC4", Image::FORMAT_BC4);
  1483. _VariantCall::add_constant(Variant::IMAGE, "FORMAT_BC5", Image::FORMAT_BC5);
  1484. _VariantCall::add_constant(Variant::IMAGE, "FORMAT_PVRTC2", Image::FORMAT_PVRTC2);
  1485. _VariantCall::add_constant(Variant::IMAGE, "FORMAT_PVRTC2_ALPHA", Image::FORMAT_PVRTC2_ALPHA);
  1486. _VariantCall::add_constant(Variant::IMAGE, "FORMAT_PVRTC4", Image::FORMAT_PVRTC4);
  1487. _VariantCall::add_constant(Variant::IMAGE, "FORMAT_PVRTC4_ALPHA", Image::FORMAT_PVRTC4_ALPHA);
  1488. _VariantCall::add_constant(Variant::IMAGE, "FORMAT_ETC", Image::FORMAT_ETC);
  1489. _VariantCall::add_constant(Variant::IMAGE, "FORMAT_ATC", Image::FORMAT_ATC);
  1490. _VariantCall::add_constant(Variant::IMAGE, "FORMAT_ATC_ALPHA_EXPLICIT", Image::FORMAT_ATC_ALPHA_EXPLICIT);
  1491. _VariantCall::add_constant(Variant::IMAGE, "FORMAT_ATC_ALPHA_INTERPOLATED", Image::FORMAT_ATC_ALPHA_INTERPOLATED);
  1492. _VariantCall::add_constant(Variant::IMAGE, "FORMAT_CUSTOM", Image::FORMAT_CUSTOM);
  1493. _VariantCall::add_constant(Variant::IMAGE, "INTERPOLATE_NEAREST", Image::INTERPOLATE_NEAREST);
  1494. _VariantCall::add_constant(Variant::IMAGE, "INTERPOLATE_BILINEAR", Image::INTERPOLATE_BILINEAR);
  1495. _VariantCall::add_constant(Variant::IMAGE, "INTERPOLATE_CUBIC", Image::INTERPOLATE_CUBIC);
  1496. }
  1497. void unregister_variant_methods() {
  1498. memdelete_arr(_VariantCall::type_funcs);
  1499. memdelete_arr(_VariantCall::construct_funcs);
  1500. memdelete_arr(_VariantCall::constant_data);
  1501. }