variant_call.cpp 79 KB

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