variant_call.cpp 92 KB

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