variant_call.cpp 94 KB

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