variant_call.cpp 79 KB

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