variant_call.cpp 79 KB

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