variant_call.cpp 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515
  1. /*************************************************************************/
  2. /* variant_call.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #include "variant.h"
  30. #include "object.h"
  31. #include "os/os.h"
  32. #include "core_string_names.h"
  33. #include "script_language.h"
  34. typedef void (*VariantFunc)(Variant& r_ret,Variant& p_self,const Variant** p_args);
  35. typedef void (*VariantConstructFunc)(Variant& r_ret,const Variant** p_args);
  36. VARIANT_ENUM_CAST(Image::CompressMode);
  37. //VARIANT_ENUM_CAST(Image::Format);
  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. #ifdef DEBUG_ENABLED
  47. Vector<StringName> arg_names;
  48. Variant::Type return_type;
  49. bool returns;
  50. #endif
  51. VariantFunc func;
  52. _FORCE_INLINE_ bool verify_arguments(const Variant **p_args,Variant::CallError &r_error) {
  53. if (arg_count==0)
  54. return true;
  55. Variant::Type *tptr = &arg_types[0];
  56. for(int i=0;i<arg_count;i++) {
  57. if (!tptr[i] || tptr[i]==p_args[i]->type)
  58. continue; // all good
  59. if (!Variant::can_convert(p_args[i]->type,tptr[i])) {
  60. r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
  61. r_error.argument=i;
  62. r_error.expected=tptr[i];
  63. return false;
  64. }
  65. }
  66. return true;
  67. }
  68. _FORCE_INLINE_ void call(Variant& r_ret,Variant& p_self,const Variant** p_args,int p_argcount,Variant::CallError &r_error) {
  69. #ifdef DEBUG_ENABLED
  70. if(p_argcount>arg_count) {
  71. r_error.error=Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
  72. r_error.argument=arg_count;
  73. return;
  74. } else
  75. #endif
  76. if (p_argcount<arg_count) {
  77. int def_argcount = default_args.size();
  78. #ifdef DEBUG_ENABLED
  79. if (p_argcount<(arg_count-def_argcount)) {
  80. r_error.error=Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  81. r_error.argument=arg_count-def_argcount;
  82. return;
  83. }
  84. #endif
  85. ERR_FAIL_COND(p_argcount>VARIANT_ARG_MAX);
  86. const Variant *newargs[VARIANT_ARG_MAX];
  87. for(int i=0;i<p_argcount;i++)
  88. newargs[i]=p_args[i];
  89. int defargcount=def_argcount;
  90. for(int i=p_argcount;i<arg_count;i++)
  91. newargs[i]=&default_args[defargcount-(i-p_argcount)-1]; //default arguments
  92. #ifdef DEBUG_ENABLED
  93. if (!verify_arguments(newargs,r_error))
  94. return;
  95. #endif
  96. func(r_ret,p_self,newargs);
  97. } else {
  98. #ifdef DEBUG_ENABLED
  99. if (!verify_arguments(p_args,r_error))
  100. return;
  101. #endif
  102. func(r_ret,p_self,p_args);
  103. }
  104. }
  105. };
  106. struct TypeFunc {
  107. Map<StringName,FuncData> functions;
  108. };
  109. static TypeFunc* type_funcs;
  110. struct Arg {
  111. StringName name;
  112. Variant::Type type;
  113. Arg() { type=Variant::NIL;}
  114. Arg(Variant::Type p_type,const StringName &p_name) { name=p_name; type=p_type; }
  115. };
  116. // void addfunc(Variant::Type p_type, const StringName& p_name,VariantFunc p_func);
  117. static void addfunc(Variant::Type p_type, Variant::Type p_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()) {
  118. FuncData funcdata;
  119. funcdata.func=p_func;
  120. funcdata.default_args=p_defaultarg;
  121. #ifdef DEBUG_ENABLED
  122. funcdata.return_type=p_return;
  123. funcdata.returns=p_return!=Variant::NIL;
  124. #endif
  125. if (p_argtype1.name) {
  126. funcdata.arg_types.push_back(p_argtype1.type);
  127. #ifdef DEBUG_ENABLED
  128. funcdata.arg_names.push_back(p_argtype1.name);
  129. #endif
  130. } else
  131. goto end;
  132. if (p_argtype2.name) {
  133. funcdata.arg_types.push_back(p_argtype2.type);
  134. #ifdef DEBUG_ENABLED
  135. funcdata.arg_names.push_back(p_argtype2.name);
  136. #endif
  137. } else
  138. goto end;
  139. if (p_argtype3.name) {
  140. funcdata.arg_types.push_back(p_argtype3.type);
  141. #ifdef DEBUG_ENABLED
  142. funcdata.arg_names.push_back(p_argtype3.name);
  143. #endif
  144. } else
  145. goto end;
  146. if (p_argtype4.name) {
  147. funcdata.arg_types.push_back(p_argtype4.type);
  148. #ifdef DEBUG_ENABLED
  149. funcdata.arg_names.push_back(p_argtype4.name);
  150. #endif
  151. } else
  152. goto end;
  153. if (p_argtype5.name) {
  154. funcdata.arg_types.push_back(p_argtype5.type);
  155. #ifdef DEBUG_ENABLED
  156. funcdata.arg_names.push_back(p_argtype5.name);
  157. #endif
  158. } else
  159. goto end;
  160. end:
  161. funcdata.arg_count=funcdata.arg_types.size();
  162. type_funcs[p_type].functions[p_name]=funcdata;
  163. }
  164. #define VCALL_LOCALMEM0(m_type,m_method)\
  165. 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(); }
  166. #define VCALL_LOCALMEM0R(m_type,m_method)\
  167. 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(); }
  168. #define VCALL_LOCALMEM1(m_type,m_method)\
  169. 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]); }
  170. #define VCALL_LOCALMEM1R(m_type,m_method)\
  171. 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]); }
  172. #define VCALL_LOCALMEM2(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(*p_args[0],*p_args[1]); }
  174. #define VCALL_LOCALMEM2R(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(*p_args[0],*p_args[1]); }
  176. #define VCALL_LOCALMEM3(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],*p_args[1],*p_args[2]); }
  178. #define VCALL_LOCALMEM3R(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],*p_args[1],*p_args[2]); }
  180. #define VCALL_LOCALMEM4(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],*p_args[2],*p_args[3]); }
  182. #define VCALL_LOCALMEM4R(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],*p_args[2],*p_args[3]); }
  184. #define VCALL_LOCALMEM5(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],*p_args[3],*p_args[4]); }
  186. #define VCALL_LOCALMEM5R(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],*p_args[3],*p_args[4]); }
  188. // built-in functions of localmem based types
  189. VCALL_LOCALMEM1R(String,casecmp_to);
  190. VCALL_LOCALMEM1R(String,nocasecmp_to);
  191. VCALL_LOCALMEM0R(String,length);
  192. VCALL_LOCALMEM2R(String,substr);
  193. VCALL_LOCALMEM2R(String,find);
  194. VCALL_LOCALMEM1R(String,find_last);
  195. VCALL_LOCALMEM2R(String,findn);
  196. VCALL_LOCALMEM2R(String,rfind);
  197. VCALL_LOCALMEM2R(String,rfindn);
  198. VCALL_LOCALMEM1R(String,match);
  199. VCALL_LOCALMEM1R(String,matchn);
  200. VCALL_LOCALMEM1R(String,begins_with);
  201. VCALL_LOCALMEM2R(String,replace);
  202. VCALL_LOCALMEM2R(String,replacen);
  203. VCALL_LOCALMEM2R(String,insert);
  204. VCALL_LOCALMEM0R(String,capitalize);
  205. VCALL_LOCALMEM2R(String,split);
  206. VCALL_LOCALMEM2R(String,split_floats);
  207. VCALL_LOCALMEM0R(String,to_upper);
  208. VCALL_LOCALMEM0R(String,to_lower);
  209. VCALL_LOCALMEM1R(String,left);
  210. VCALL_LOCALMEM1R(String,right);
  211. VCALL_LOCALMEM0R(String,strip_edges);
  212. VCALL_LOCALMEM0R(String,extension);
  213. VCALL_LOCALMEM0R(String,basename);
  214. VCALL_LOCALMEM1R(String,plus_file);
  215. VCALL_LOCALMEM1R(String,ord_at);
  216. //VCALL_LOCALMEM2R(String,erase);
  217. VCALL_LOCALMEM0R(String,hash);
  218. VCALL_LOCALMEM0R(String,empty);
  219. VCALL_LOCALMEM0R(String,is_abs_path);
  220. VCALL_LOCALMEM0R(String,is_rel_path);
  221. VCALL_LOCALMEM0R(String,get_base_dir);
  222. VCALL_LOCALMEM0R(String,get_file);
  223. VCALL_LOCALMEM0R(String,xml_escape);
  224. VCALL_LOCALMEM0R(String,xml_unescape);
  225. VCALL_LOCALMEM0R(String,percent_encode);
  226. VCALL_LOCALMEM0R(String,percent_decode);
  227. VCALL_LOCALMEM0R(String,is_valid_identifier);
  228. VCALL_LOCALMEM0R(String,is_valid_integer);
  229. VCALL_LOCALMEM0R(String,is_valid_float);
  230. VCALL_LOCALMEM0R(String,is_valid_html_color);
  231. VCALL_LOCALMEM0R(String,is_valid_ip_address);
  232. VCALL_LOCALMEM0R(String,to_int);
  233. VCALL_LOCALMEM0R(String,to_float);
  234. VCALL_LOCALMEM0R(String,hex_to_int);
  235. VCALL_LOCALMEM1R(String,pad_decimals);
  236. VCALL_LOCALMEM1R(String,pad_zeros);
  237. VCALL_LOCALMEM0R(Vector2,normalized);
  238. VCALL_LOCALMEM0R(Vector2,length);
  239. VCALL_LOCALMEM0R(Vector2,length_squared);
  240. VCALL_LOCALMEM1R(Vector2,distance_to);
  241. VCALL_LOCALMEM1R(Vector2,distance_squared_to);
  242. VCALL_LOCALMEM1R(Vector2,angle_to);
  243. VCALL_LOCALMEM2R(Vector2,linear_interpolate);
  244. VCALL_LOCALMEM4R(Vector2,cubic_interpolate);
  245. VCALL_LOCALMEM1R(Vector2,rotated);
  246. VCALL_LOCALMEM0R(Vector2,tangent);
  247. VCALL_LOCALMEM0R(Vector2,floor);
  248. VCALL_LOCALMEM1R(Vector2,snapped);
  249. VCALL_LOCALMEM0R(Vector2,get_aspect);
  250. VCALL_LOCALMEM1R(Vector2,dot);
  251. VCALL_LOCALMEM1R(Vector2,slide);
  252. VCALL_LOCALMEM1R(Vector2,reflect);
  253. // VCALL_LOCALMEM1R(Vector2,cross);
  254. VCALL_LOCALMEM0R(Rect2,get_area);
  255. VCALL_LOCALMEM1R(Rect2,intersects);
  256. VCALL_LOCALMEM1R(Rect2,encloses);
  257. VCALL_LOCALMEM0R(Rect2,has_no_area);
  258. VCALL_LOCALMEM1R(Rect2,clip);
  259. VCALL_LOCALMEM1R(Rect2,merge);
  260. VCALL_LOCALMEM1R(Rect2,has_point);
  261. VCALL_LOCALMEM1R(Rect2,grow);
  262. VCALL_LOCALMEM1R(Rect2,expand);
  263. VCALL_LOCALMEM0R(Vector3, min_axis);
  264. VCALL_LOCALMEM0R(Vector3, max_axis);
  265. VCALL_LOCALMEM0R(Vector3, length);
  266. VCALL_LOCALMEM0R(Vector3, length_squared);
  267. VCALL_LOCALMEM0R(Vector3, normalized);
  268. VCALL_LOCALMEM0R(Vector3, inverse);
  269. VCALL_LOCALMEM1R(Vector3, snapped);
  270. VCALL_LOCALMEM2R(Vector3, rotated);
  271. VCALL_LOCALMEM2R(Vector3, linear_interpolate);
  272. VCALL_LOCALMEM4R(Vector3, cubic_interpolate);
  273. VCALL_LOCALMEM1R(Vector3, dot);
  274. VCALL_LOCALMEM1R(Vector3, cross);
  275. VCALL_LOCALMEM0R(Vector3, abs);
  276. VCALL_LOCALMEM1R(Vector3, distance_to);
  277. VCALL_LOCALMEM1R(Vector3, distance_squared_to);
  278. VCALL_LOCALMEM0R(Plane,normalized);
  279. VCALL_LOCALMEM0R(Plane,center);
  280. VCALL_LOCALMEM0R(Plane,get_any_point);
  281. VCALL_LOCALMEM1R(Plane,is_point_over);
  282. VCALL_LOCALMEM1R(Plane,distance_to);
  283. VCALL_LOCALMEM2R(Plane,has_point);
  284. VCALL_LOCALMEM1R(Plane,project);
  285. //return vector3 if intersected, nil if not
  286. static void _call_Plane_intersect_3(Variant& r_ret,Variant& p_self,const Variant** p_args) {
  287. Vector3 result;
  288. if (reinterpret_cast<Plane*>(p_self._data._mem)->intersect_3(*p_args[0],*p_args[1],&result))
  289. r_ret=result;
  290. else
  291. r_ret=Variant();
  292. }
  293. static void _call_Plane_intersects_ray(Variant& r_ret,Variant& p_self,const Variant** p_args) {
  294. Vector3 result;
  295. if (reinterpret_cast<Plane*>(p_self._data._mem)->intersects_ray(*p_args[0],*p_args[1],&result))
  296. r_ret=result;
  297. else
  298. r_ret=Variant();
  299. }
  300. static void _call_Plane_intersects_segment(Variant& r_ret,Variant& p_self,const Variant** p_args) {
  301. Vector3 result;
  302. if (reinterpret_cast<Plane*>(p_self._data._mem)->intersects_segment(*p_args[0],*p_args[1],&result))
  303. r_ret=result;
  304. else
  305. r_ret=Variant();
  306. }
  307. static void _call_Vector2_floorf(Variant& r_ret,Variant& p_self,const Variant** p_args) {
  308. r_ret = reinterpret_cast<Vector2*>(p_self._data._mem)->floor();
  309. };
  310. VCALL_LOCALMEM0R(Quat,length);
  311. VCALL_LOCALMEM0R(Quat,length_squared);
  312. VCALL_LOCALMEM0R(Quat,normalized);
  313. VCALL_LOCALMEM0R(Quat,inverse);
  314. VCALL_LOCALMEM1R(Quat,dot);
  315. VCALL_LOCALMEM2R(Quat,slerp);
  316. VCALL_LOCALMEM2R(Quat,slerpni);
  317. VCALL_LOCALMEM4R(Quat,cubic_slerp);
  318. VCALL_LOCALMEM0R(Color,to_32);
  319. VCALL_LOCALMEM0R(Color,to_ARGB32);
  320. VCALL_LOCALMEM0R(Color,gray);
  321. VCALL_LOCALMEM0R(Color,inverted);
  322. VCALL_LOCALMEM0R(Color,contrasted);
  323. VCALL_LOCALMEM2R(Color,linear_interpolate);
  324. VCALL_LOCALMEM1R(Color,blend);
  325. VCALL_LOCALMEM1R(Color,to_html);
  326. VCALL_LOCALMEM0R(RID,get_id);
  327. VCALL_LOCALMEM0R(NodePath,is_absolute);
  328. VCALL_LOCALMEM0R(NodePath,get_name_count);
  329. VCALL_LOCALMEM1R(NodePath,get_name);
  330. VCALL_LOCALMEM0R(NodePath,get_subname_count);
  331. VCALL_LOCALMEM1R(NodePath,get_subname);
  332. VCALL_LOCALMEM0R(NodePath,get_property);
  333. VCALL_LOCALMEM0R(NodePath,is_empty);
  334. VCALL_LOCALMEM0R(Dictionary,size);
  335. VCALL_LOCALMEM0R(Dictionary,empty);
  336. VCALL_LOCALMEM0(Dictionary,clear);
  337. VCALL_LOCALMEM1R(Dictionary,has);
  338. VCALL_LOCALMEM1(Dictionary,erase);
  339. VCALL_LOCALMEM0R(Dictionary,hash);
  340. VCALL_LOCALMEM0R(Dictionary,keys);
  341. VCALL_LOCALMEM1R(Dictionary,parse_json);
  342. VCALL_LOCALMEM0R(Dictionary,to_json);
  343. VCALL_LOCALMEM2(Array,set);
  344. VCALL_LOCALMEM1R(Array,get);
  345. VCALL_LOCALMEM0R(Array,size);
  346. VCALL_LOCALMEM0R(Array,empty);
  347. VCALL_LOCALMEM0(Array,clear);
  348. VCALL_LOCALMEM0R(Array,hash);
  349. VCALL_LOCALMEM1(Array,push_back);
  350. VCALL_LOCALMEM1(Array,append);
  351. VCALL_LOCALMEM1(Array,resize);
  352. VCALL_LOCALMEM2(Array,insert);
  353. VCALL_LOCALMEM1(Array,remove);
  354. VCALL_LOCALMEM1R(Array,find);
  355. VCALL_LOCALMEM1(Array,erase);
  356. VCALL_LOCALMEM0(Array,sort);
  357. VCALL_LOCALMEM2(Array,sort_custom);
  358. VCALL_LOCALMEM0(Array,invert);
  359. static void _call_ByteArray_get_string_from_ascii(Variant& r_ret,Variant& p_self,const Variant** p_args) {
  360. ByteArray* ba = reinterpret_cast<ByteArray*>(p_self._data._mem);
  361. String s;
  362. if (ba->size()>=0) {
  363. ByteArray::Read r = ba->read();
  364. CharString cs;
  365. cs.resize(ba->size()+1);
  366. copymem(cs.ptr(),r.ptr(),ba->size());
  367. cs[ba->size()]=0;
  368. s = cs.get_data();
  369. }
  370. r_ret=s;
  371. }
  372. static void _call_ByteArray_get_string_from_utf8(Variant& r_ret,Variant& p_self,const Variant** p_args) {
  373. ByteArray* ba = reinterpret_cast<ByteArray*>(p_self._data._mem);
  374. String s;
  375. if (ba->size()>=0) {
  376. ByteArray::Read r = ba->read();
  377. s.parse_utf8((const char*)r.ptr(),ba->size());
  378. }
  379. r_ret=s;
  380. }
  381. VCALL_LOCALMEM0R(ByteArray,size);
  382. VCALL_LOCALMEM2(ByteArray,set);
  383. VCALL_LOCALMEM1R(ByteArray,get);
  384. VCALL_LOCALMEM1(ByteArray,push_back);
  385. VCALL_LOCALMEM1(ByteArray,resize);
  386. VCALL_LOCALMEM1(ByteArray,append);
  387. VCALL_LOCALMEM1(ByteArray,append_array);
  388. VCALL_LOCALMEM0R(IntArray,size);
  389. VCALL_LOCALMEM2(IntArray,set);
  390. VCALL_LOCALMEM1R(IntArray,get);
  391. VCALL_LOCALMEM1(IntArray,push_back);
  392. VCALL_LOCALMEM1(IntArray,resize);
  393. VCALL_LOCALMEM1(IntArray,append);
  394. VCALL_LOCALMEM1(IntArray,append_array);
  395. VCALL_LOCALMEM0R(RealArray,size);
  396. VCALL_LOCALMEM2(RealArray,set);
  397. VCALL_LOCALMEM1R(RealArray,get);
  398. VCALL_LOCALMEM1(RealArray,push_back);
  399. VCALL_LOCALMEM1(RealArray,resize);
  400. VCALL_LOCALMEM1(RealArray,append);
  401. VCALL_LOCALMEM1(RealArray,append_array);
  402. VCALL_LOCALMEM0R(StringArray,size);
  403. VCALL_LOCALMEM2(StringArray,set);
  404. VCALL_LOCALMEM1R(StringArray,get);
  405. VCALL_LOCALMEM1(StringArray,push_back);
  406. VCALL_LOCALMEM1(StringArray,resize);
  407. VCALL_LOCALMEM1(StringArray,append);
  408. VCALL_LOCALMEM1(StringArray,append_array);
  409. VCALL_LOCALMEM0R(Vector2Array,size);
  410. VCALL_LOCALMEM2(Vector2Array,set);
  411. VCALL_LOCALMEM1R(Vector2Array,get);
  412. VCALL_LOCALMEM1(Vector2Array,push_back);
  413. VCALL_LOCALMEM1(Vector2Array,resize);
  414. VCALL_LOCALMEM1(Vector2Array,append);
  415. VCALL_LOCALMEM1(Vector2Array,append_array);
  416. VCALL_LOCALMEM0R(Vector3Array,size);
  417. VCALL_LOCALMEM2(Vector3Array,set);
  418. VCALL_LOCALMEM1R(Vector3Array,get);
  419. VCALL_LOCALMEM1(Vector3Array,push_back);
  420. VCALL_LOCALMEM1(Vector3Array,resize);
  421. VCALL_LOCALMEM1(Vector3Array,append);
  422. VCALL_LOCALMEM1(Vector3Array,append_array);
  423. VCALL_LOCALMEM0R(ColorArray,size);
  424. VCALL_LOCALMEM2(ColorArray,set);
  425. VCALL_LOCALMEM1R(ColorArray,get);
  426. VCALL_LOCALMEM1(ColorArray,push_back);
  427. VCALL_LOCALMEM1(ColorArray,resize);
  428. VCALL_LOCALMEM1(ColorArray,append);
  429. VCALL_LOCALMEM1(ColorArray,append_array);
  430. #define VCALL_PTR0(m_type,m_method)\
  431. 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(); }
  432. #define VCALL_PTR0R(m_type,m_method)\
  433. 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(); }
  434. #define VCALL_PTR1(m_type,m_method)\
  435. 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]); }
  436. #define VCALL_PTR1R(m_type,m_method)\
  437. 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]); }
  438. #define VCALL_PTR2(m_type,m_method)\
  439. 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]); }
  440. #define VCALL_PTR2R(m_type,m_method)\
  441. 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]); }
  442. #define VCALL_PTR3(m_type,m_method)\
  443. 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]); }
  444. #define VCALL_PTR3R(m_type,m_method)\
  445. 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]); }
  446. #define VCALL_PTR4(m_type,m_method)\
  447. 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]); }
  448. #define VCALL_PTR4R(m_type,m_method)\
  449. 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]); }
  450. #define VCALL_PTR5(m_type,m_method)\
  451. 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]); }
  452. #define VCALL_PTR5R(m_type,m_method)\
  453. 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]); }
  454. VCALL_PTR0R(Image,get_format);
  455. VCALL_PTR0R(Image,get_width);
  456. VCALL_PTR0R(Image,get_height);
  457. VCALL_PTR0R(Image,empty);
  458. VCALL_PTR3R(Image,get_pixel);
  459. VCALL_PTR0R(Image,get_used_rect);
  460. VCALL_PTR3R(Image,brushed);
  461. VCALL_PTR1R(Image,load);
  462. VCALL_PTR3(Image,brush_transfer);
  463. VCALL_PTR1R(Image,get_rect);
  464. VCALL_PTR1R(Image,compressed);
  465. VCALL_PTR3R(Image, resized);
  466. VCALL_PTR0R(Image, get_data);
  467. VCALL_PTR3(Image, blit_rect);
  468. VCALL_PTR0R( AABB, get_area );
  469. VCALL_PTR0R( AABB, has_no_area );
  470. VCALL_PTR0R( AABB, has_no_surface );
  471. VCALL_PTR1R( AABB, intersects );
  472. VCALL_PTR1R( AABB, encloses );
  473. VCALL_PTR1R( AABB, merge );
  474. VCALL_PTR1R( AABB, intersection );
  475. VCALL_PTR1R( AABB, intersects_plane );
  476. VCALL_PTR1R( AABB, has_point );
  477. VCALL_PTR1R( AABB, get_support );
  478. VCALL_PTR0R( AABB, get_longest_axis );
  479. VCALL_PTR0R( AABB, get_longest_axis_index );
  480. VCALL_PTR0R( AABB, get_longest_axis_size );
  481. VCALL_PTR0R( AABB, get_shortest_axis );
  482. VCALL_PTR0R( AABB, get_shortest_axis_index );
  483. VCALL_PTR0R( AABB, get_shortest_axis_size );
  484. VCALL_PTR1R( AABB, expand );
  485. VCALL_PTR1R( AABB, grow );
  486. VCALL_PTR1R( AABB, get_endpoint );
  487. VCALL_PTR0R( Matrix32, inverse );
  488. VCALL_PTR0R( Matrix32, affine_inverse );
  489. VCALL_PTR0R( Matrix32, get_rotation );
  490. VCALL_PTR0R( Matrix32, get_origin );
  491. VCALL_PTR0R( Matrix32, get_scale );
  492. VCALL_PTR0R( Matrix32, orthonormalized );
  493. VCALL_PTR1R( Matrix32, rotated );
  494. VCALL_PTR1R( Matrix32, scaled );
  495. VCALL_PTR1R( Matrix32, translated );
  496. VCALL_PTR2R( Matrix32, interpolate_with );
  497. static void _call_Matrix32_xform(Variant& r_ret,Variant& p_self,const Variant** p_args) {
  498. switch(p_args[0]->type) {
  499. case Variant::VECTOR2: r_ret=reinterpret_cast<Matrix32*>(p_self._data._ptr)->xform( p_args[0]->operator Vector2()); return;
  500. case Variant::RECT2: r_ret=reinterpret_cast<Matrix32*>(p_self._data._ptr)->xform( p_args[0]->operator Rect2()); return;
  501. default: r_ret=Variant();
  502. }
  503. }
  504. static void _call_Matrix32_xform_inv(Variant& r_ret,Variant& p_self,const Variant** p_args) {
  505. switch(p_args[0]->type) {
  506. case Variant::VECTOR2: r_ret=reinterpret_cast<Matrix32*>(p_self._data._ptr)->xform_inv( p_args[0]->operator Vector2()); return;
  507. case Variant::RECT2: r_ret=reinterpret_cast<Matrix32*>(p_self._data._ptr)->xform_inv( p_args[0]->operator Rect2()); return;
  508. default: r_ret=Variant();
  509. }
  510. }
  511. VCALL_PTR0R( Matrix3, inverse );
  512. VCALL_PTR0R( Matrix3, transposed );
  513. VCALL_PTR0R( Matrix3, determinant );
  514. VCALL_PTR2R( Matrix3, rotated );
  515. VCALL_PTR1R( Matrix3, scaled );
  516. VCALL_PTR0R( Matrix3, get_scale );
  517. VCALL_PTR0R( Matrix3, get_euler );
  518. VCALL_PTR1R( Matrix3, tdotx );
  519. VCALL_PTR1R( Matrix3, tdoty );
  520. VCALL_PTR1R( Matrix3, tdotz );
  521. VCALL_PTR1R( Matrix3, xform );
  522. VCALL_PTR1R( Matrix3, xform_inv );
  523. VCALL_PTR0R( Matrix3, get_orthogonal_index );
  524. VCALL_PTR0R( Matrix3, orthonormalized );
  525. VCALL_PTR0R( Transform, inverse );
  526. VCALL_PTR0R( Transform, affine_inverse );
  527. VCALL_PTR2R( Transform, rotated );
  528. VCALL_PTR1R( Transform, scaled );
  529. VCALL_PTR1R( Transform, translated );
  530. VCALL_PTR0R( Transform, orthonormalized );
  531. VCALL_PTR2R( Transform, looking_at );
  532. static void _call_Transform_xform(Variant& r_ret,Variant& p_self,const Variant** p_args) {
  533. switch(p_args[0]->type) {
  534. case Variant::VECTOR3: r_ret=reinterpret_cast<Transform*>(p_self._data._ptr)->xform( p_args[0]->operator Vector3()); return;
  535. case Variant::PLANE: r_ret=reinterpret_cast<Transform*>(p_self._data._ptr)->xform( p_args[0]->operator Plane()); return;
  536. case Variant::_AABB: r_ret=reinterpret_cast<Transform*>(p_self._data._ptr)->xform( p_args[0]->operator AABB()); return;
  537. default: r_ret=Variant();
  538. }
  539. }
  540. static void _call_Transform_xform_inv(Variant& r_ret,Variant& p_self,const Variant** p_args) {
  541. switch(p_args[0]->type) {
  542. case Variant::VECTOR3: r_ret=reinterpret_cast<Transform*>(p_self._data._ptr)->xform_inv( p_args[0]->operator Vector3()); return;
  543. case Variant::PLANE: r_ret=reinterpret_cast<Transform*>(p_self._data._ptr)->xform_inv( p_args[0]->operator Plane()); return;
  544. case Variant::_AABB: r_ret=reinterpret_cast<Transform*>(p_self._data._ptr)->xform_inv( p_args[0]->operator AABB()); return;
  545. default: r_ret=Variant();
  546. }
  547. }
  548. /*
  549. VCALL_PTR0( Transform, invert );
  550. VCALL_PTR0( Transform, affine_invert );
  551. VCALL_PTR2( Transform, rotate );
  552. VCALL_PTR1( Transform, scale );
  553. VCALL_PTR1( Transform, translate );
  554. VCALL_PTR0( Transform, orthonormalize ); */
  555. VCALL_PTR0R( InputEvent, is_pressed );
  556. VCALL_PTR1R( InputEvent, is_action );
  557. VCALL_PTR0R( InputEvent, is_echo );
  558. struct ConstructData {
  559. int arg_count;
  560. Vector<Variant::Type> arg_types;
  561. Vector<String> arg_names;
  562. VariantConstructFunc func;
  563. };
  564. struct ConstructFunc {
  565. List<ConstructData> constructors;
  566. };
  567. static ConstructFunc* construct_funcs;
  568. static void Vector2_init1(Variant& r_ret,const Variant** p_args) {
  569. r_ret=Vector2(*p_args[0],*p_args[1]);
  570. }
  571. static void Rect2_init1(Variant& r_ret,const Variant** p_args) {
  572. r_ret=Rect2(*p_args[0],*p_args[1]);
  573. }
  574. static void Rect2_init2(Variant& r_ret,const Variant** p_args) {
  575. r_ret=Rect2(*p_args[0],*p_args[1],*p_args[2],*p_args[3]);
  576. }
  577. static void Matrix32_init3(Variant& r_ret,const Variant** p_args) {
  578. Matrix32 m;
  579. m[0]=*p_args[0];
  580. m[1]=*p_args[1];
  581. m[2]=*p_args[2];
  582. r_ret=m;
  583. }
  584. static void Vector3_init1(Variant& r_ret,const Variant** p_args) {
  585. r_ret=Vector3(*p_args[0],*p_args[1],*p_args[2]);
  586. }
  587. static void Plane_init1(Variant& r_ret,const Variant** p_args) {
  588. r_ret=Plane(*p_args[0],*p_args[1],*p_args[2],*p_args[3]);
  589. }
  590. static void Plane_init2(Variant& r_ret,const Variant** p_args) {
  591. r_ret=Plane(*p_args[0],*p_args[1],*p_args[2]);
  592. }
  593. static void Plane_init3(Variant& r_ret,const Variant** p_args) {
  594. r_ret=Plane(p_args[0]->operator Vector3(),p_args[1]->operator real_t());
  595. }
  596. static void Plane_init4(Variant& r_ret,const Variant** p_args) {
  597. r_ret=Plane(p_args[0]->operator Vector3(),p_args[1]->operator Vector3());
  598. }
  599. static void Quat_init1(Variant& r_ret,const Variant** p_args) {
  600. r_ret=Quat(*p_args[0],*p_args[1],*p_args[2],*p_args[3]);
  601. }
  602. static void Color_init1(Variant& r_ret,const Variant** p_args) {
  603. r_ret=Color(*p_args[0],*p_args[1],*p_args[2],*p_args[3]);
  604. }
  605. static void Color_init2(Variant& r_ret,const Variant** p_args) {
  606. r_ret=Color(*p_args[0],*p_args[1],*p_args[2]);
  607. }
  608. static void Color_init3(Variant& r_ret,const Variant** p_args) {
  609. r_ret=Color::html(*p_args[0]);
  610. }
  611. static void Color_init4(Variant& r_ret,const Variant** p_args) {
  612. r_ret=Color::hex(*p_args[0]);
  613. }
  614. static void AABB_init1(Variant& r_ret,const Variant** p_args) {
  615. r_ret=AABB(*p_args[0],*p_args[1]);
  616. }
  617. static void Matrix3_init1(Variant& r_ret,const Variant** p_args) {
  618. Matrix3 m;
  619. m.set_axis(0,*p_args[0]);
  620. m.set_axis(1,*p_args[1]);
  621. m.set_axis(2,*p_args[2]);
  622. r_ret=m;
  623. }
  624. static void Matrix3_init2(Variant& r_ret,const Variant** p_args) {
  625. r_ret=Matrix3(p_args[0]->operator Vector3(),p_args[1]->operator real_t());
  626. }
  627. static void Transform_init1(Variant& r_ret,const Variant** p_args) {
  628. Transform t;
  629. t.basis.set_axis(0,*p_args[0]);
  630. t.basis.set_axis(1,*p_args[1]);
  631. t.basis.set_axis(2,*p_args[2]);
  632. t.origin=*p_args[3];
  633. r_ret=t;
  634. }
  635. static void Transform_init2(Variant& r_ret,const Variant** p_args) {
  636. r_ret=Transform(p_args[0]->operator Matrix3(),p_args[1]->operator Vector3());
  637. }
  638. static void add_constructor(VariantConstructFunc p_func,const Variant::Type p_type,
  639. const String& p_name1="", const Variant::Type p_type1=Variant::NIL,
  640. const String& p_name2="", const Variant::Type p_type2=Variant::NIL,
  641. const String& p_name3="", const Variant::Type p_type3=Variant::NIL,
  642. const String& p_name4="", const Variant::Type p_type4=Variant::NIL ) {
  643. ConstructData cd;
  644. cd.func=p_func;
  645. cd.arg_count=0;
  646. if (p_name1=="")
  647. goto end;
  648. cd.arg_count++;
  649. cd.arg_names.push_back(p_name1);
  650. cd.arg_types.push_back(p_type1);
  651. if (p_name2=="")
  652. goto end;
  653. cd.arg_count++;
  654. cd.arg_names.push_back(p_name2);
  655. cd.arg_types.push_back(p_type2);
  656. if (p_name3=="")
  657. goto end;
  658. cd.arg_count++;
  659. cd.arg_names.push_back(p_name3);
  660. cd.arg_types.push_back(p_type3);
  661. if (p_name4=="")
  662. goto end;
  663. cd.arg_count++;
  664. cd.arg_names.push_back(p_name4);
  665. cd.arg_types.push_back(p_type4);
  666. end:
  667. construct_funcs[p_type].constructors.push_back(cd);
  668. }
  669. struct ConstantData {
  670. Map<StringName,int> value;
  671. };
  672. static ConstantData* constant_data;
  673. };
  674. _VariantCall::TypeFunc* _VariantCall::type_funcs=NULL;
  675. _VariantCall::ConstructFunc* _VariantCall::construct_funcs=NULL;
  676. _VariantCall::ConstantData* _VariantCall::constant_data=NULL;
  677. Variant Variant::call(const StringName& p_method,const Variant** p_args,int p_argcount,CallError &r_error) {
  678. Variant ret;
  679. if (type==Variant::OBJECT) {
  680. //call object
  681. Object *obj = _get_obj().obj;
  682. if (!obj) {
  683. r_error.error=CallError::CALL_ERROR_INSTANCE_IS_NULL;
  684. return ret;
  685. }
  686. #ifdef DEBUG_ENABLED
  687. if (ScriptDebugger::get_singleton() && _get_obj().ref.is_null()) {
  688. //only if debugging!
  689. if (!ObjectDB::instance_validate(obj)) {
  690. r_error.error=CallError::CALL_ERROR_INSTANCE_IS_NULL;
  691. return ret;
  692. }
  693. }
  694. #endif
  695. return _get_obj().obj->call(p_method,p_args,p_argcount,r_error);
  696. //else if (type==Variant::METHOD) {
  697. } else {
  698. r_error.error=Variant::CallError::CALL_OK;
  699. Map<StringName,_VariantCall::FuncData>::Element *E=_VariantCall::type_funcs[type].functions.find(p_method);
  700. #ifdef DEBUG_ENABLED
  701. if (!E) {
  702. r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
  703. return Variant();
  704. }
  705. #endif
  706. _VariantCall::FuncData& funcdata = E->get();
  707. funcdata.call(ret,*this,p_args,p_argcount,r_error);
  708. }
  709. return ret;
  710. }
  711. #define VCALL(m_type,m_method) _VariantCall::_call_##m_type##_##m_method
  712. Variant Variant::construct(const Variant::Type p_type,const Variant** p_args,int p_argcount,CallError &r_error) {
  713. r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
  714. ERR_FAIL_INDEX_V(p_type,VARIANT_MAX,Variant());
  715. r_error.error=Variant::CallError::CALL_OK;
  716. if (p_argcount==0) { //generic construct
  717. switch(p_type) {
  718. case NIL: return Variant();
  719. // atomic types
  720. case BOOL: return Variant( false );
  721. case INT: return 0;
  722. case REAL: return 0.0f;
  723. case STRING: return String();
  724. // math types
  725. case VECTOR2: return Vector2(); // 5
  726. case RECT2: return Rect2();
  727. case VECTOR3: return Vector3();
  728. case MATRIX32: return Matrix32();
  729. case PLANE: return Plane();
  730. case QUAT: return Quat();
  731. case _AABB: return AABB(); //sorry naming convention fail :( not like it's used often // 10
  732. case MATRIX3: return Matrix3();
  733. case TRANSFORM: return Transform();
  734. // misc types
  735. case COLOR: return Color();
  736. case IMAGE: return Image();;
  737. case NODE_PATH: return NodePath();; // 15
  738. case _RID: return RID();;
  739. case OBJECT: return (Object*)NULL;
  740. case INPUT_EVENT: return InputEvent();;
  741. case DICTIONARY: return Dictionary();;
  742. case ARRAY: return Array();; // 20
  743. case RAW_ARRAY: return ByteArray();;
  744. case INT_ARRAY: return IntArray();;
  745. case REAL_ARRAY: return RealArray();;
  746. case STRING_ARRAY: return StringArray();;
  747. case VECTOR2_ARRAY: return Vector2Array();; // 25
  748. case VECTOR3_ARRAY: return Vector3Array();; // 25
  749. case COLOR_ARRAY: return ColorArray();;
  750. default: return Variant();
  751. }
  752. } else if (p_argcount>1) {
  753. _VariantCall::ConstructFunc & c = _VariantCall::construct_funcs[p_type];
  754. for(List<_VariantCall::ConstructData>::Element *E=c.constructors.front();E;E=E->next()) {
  755. const _VariantCall::ConstructData &cd = E->get();
  756. if (cd.arg_count!=p_argcount)
  757. continue;
  758. //validate parameters
  759. for(int i=0;i<cd.arg_count;i++) {
  760. if (!Variant::can_convert(p_args[i]->type,cd.arg_types[i])) {
  761. r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; //no such constructor
  762. r_error.argument=i;
  763. r_error.expected=cd.arg_types[i];
  764. return Variant();
  765. }
  766. }
  767. Variant v;
  768. cd.func(v,p_args);
  769. return v;
  770. }
  771. } else if (p_argcount==1 && p_args[0]->type==p_type) {
  772. return *p_args[0]; //copy construct
  773. } else if (p_argcount==1 && Variant::can_convert(p_args[0]->type,p_type)) {
  774. //near match construct
  775. switch(p_type) {
  776. case NIL: {
  777. return Variant();
  778. } break;
  779. case BOOL: { return Variant(bool(*p_args[0])); }
  780. case INT: { return (int(*p_args[0])); }
  781. case REAL: { return real_t(*p_args[0]); }
  782. case STRING: { return String(*p_args[0]); }
  783. case VECTOR2: { return Vector2(*p_args[0]); }
  784. case RECT2: return (Rect2(*p_args[0]));
  785. case VECTOR3: return (Vector3(*p_args[0]));
  786. case PLANE: return (Plane(*p_args[0]));
  787. case QUAT: return (Quat(*p_args[0]));
  788. case _AABB: return (AABB(*p_args[0])); //sorry naming convention fail :( not like it's used often // 10
  789. case MATRIX3: return (Matrix3(p_args[0]->operator Matrix3()));
  790. case TRANSFORM: return (Transform(p_args[0]->operator Transform()));
  791. // misc types
  792. case COLOR: return p_args[0]->type == Variant::STRING ? Color::html(*p_args[0]) : Color::hex(*p_args[0]);
  793. case IMAGE: return (Image(*p_args[0]));
  794. case NODE_PATH: return (NodePath(p_args[0]->operator NodePath())); // 15
  795. case _RID: return (RID(*p_args[0]));
  796. case OBJECT: return ((Object*)(p_args[0]->operator Object *()));
  797. case INPUT_EVENT: return (InputEvent(*p_args[0]));
  798. case DICTIONARY: return p_args[0]->operator Dictionary();
  799. case ARRAY: return p_args[0]->operator Array();
  800. // arrays
  801. case RAW_ARRAY: return (ByteArray(*p_args[0]));
  802. case INT_ARRAY: return (IntArray(*p_args[0]));
  803. case REAL_ARRAY: return (RealArray(*p_args[0]));
  804. case STRING_ARRAY: return (StringArray(*p_args[0]));
  805. case VECTOR2_ARRAY: return (Vector2Array(*p_args[0])); // 25
  806. case VECTOR3_ARRAY: return (Vector3Array(*p_args[0])); // 25
  807. case COLOR_ARRAY: return (Color(*p_args[0]));
  808. default: return Variant();
  809. }
  810. }
  811. r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD; //no such constructor
  812. return Variant();
  813. }
  814. void Variant::get_method_list(List<MethodInfo> *p_list) const {
  815. const _VariantCall::TypeFunc &fd = _VariantCall::type_funcs[type];
  816. for (const Map<StringName,_VariantCall::FuncData>::Element *E=fd.functions.front();E;E=E->next()) {
  817. const _VariantCall::FuncData &fd = E->get();
  818. MethodInfo mi;
  819. mi.name=E->key();
  820. for(int i=0;i<fd.arg_types.size();i++) {
  821. PropertyInfo pi;
  822. pi.type=fd.arg_types[i];
  823. #ifdef DEBUG_ENABLED
  824. pi.name=fd.arg_names[i];
  825. #endif
  826. mi.arguments.push_back(pi);
  827. }
  828. mi.default_arguments=fd.default_args;
  829. PropertyInfo ret;
  830. #ifdef DEBUG_ENABLED
  831. ret.type=fd.return_type;
  832. if (fd.returns)
  833. ret.name="ret";
  834. mi.return_val=ret;
  835. #endif
  836. p_list->push_back(mi);
  837. }
  838. }
  839. void Variant::get_constructor_list(Variant::Type p_type, List<MethodInfo> *p_list) {
  840. ERR_FAIL_INDEX(p_type,VARIANT_MAX);
  841. //custom constructors
  842. for(const List<_VariantCall::ConstructData>::Element *E=_VariantCall::construct_funcs[p_type].constructors.front();E;E=E->next()) {
  843. const _VariantCall::ConstructData &cd = E->get();
  844. MethodInfo mi;
  845. mi.name=Variant::get_type_name(p_type);
  846. for(int i=0;i<cd.arg_count;i++) {
  847. PropertyInfo pi;
  848. pi.name=cd.arg_names[i];
  849. pi.type=cd.arg_types[i];
  850. mi.arguments.push_back(pi);
  851. }
  852. p_list->push_back(mi);
  853. }
  854. //default constructors
  855. for(int i=0;i<VARIANT_MAX;i++) {
  856. if (i==p_type)
  857. continue;
  858. if (!Variant::can_convert(Variant::Type(i),p_type))
  859. continue;
  860. MethodInfo mi;
  861. mi.name=Variant::get_type_name(p_type);
  862. PropertyInfo pi;
  863. pi.name="from";
  864. pi.type=Variant::Type(i);
  865. mi.arguments.push_back(pi);
  866. p_list->push_back(mi);
  867. }
  868. }
  869. void Variant::get_numeric_constants_for_type(Variant::Type p_type, List<StringName> *p_constants) {
  870. ERR_FAIL_INDEX(p_type,Variant::VARIANT_MAX);
  871. _VariantCall::ConstantData& cd = _VariantCall::constant_data[p_type];
  872. for(Map<StringName,int>::Element *E=cd.value.front();E;E=E->next()) {
  873. p_constants->push_back(E->key());
  874. }
  875. }
  876. bool Variant::has_numeric_constant(Variant::Type p_type, const StringName& p_value) {
  877. ERR_FAIL_INDEX_V(p_type,Variant::VARIANT_MAX,false);
  878. _VariantCall::ConstantData& cd = _VariantCall::constant_data[p_type];
  879. return cd.value.has(p_value);
  880. }
  881. int Variant::get_numeric_constant_value(Variant::Type p_type, const StringName& p_value) {
  882. ERR_FAIL_INDEX_V(p_type,Variant::VARIANT_MAX,0);
  883. _VariantCall::ConstantData& cd = _VariantCall::constant_data[p_type];
  884. Map<StringName,int>::Element *E = cd.value.find(p_value);
  885. ERR_FAIL_COND_V(!E,0);
  886. return E->get();
  887. }
  888. void register_variant_methods() {
  889. _VariantCall::type_funcs = memnew_arr(_VariantCall::TypeFunc,Variant::VARIANT_MAX );
  890. _VariantCall::construct_funcs = memnew_arr(_VariantCall::ConstructFunc,Variant::VARIANT_MAX );
  891. _VariantCall::constant_data = memnew_arr(_VariantCall::ConstantData, Variant::VARIANT_MAX);
  892. #define ADDFUNC0(m_vtype,m_ret,m_class,m_method,m_defarg)\
  893. _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_class,m_method),m_defarg);
  894. #define ADDFUNC1(m_vtype,m_ret,m_class,m_method,m_arg1,m_argname1,m_defarg)\
  895. _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_class,m_method),m_defarg,_VariantCall::Arg(Variant::m_arg1,_SCS(m_argname1)) );
  896. #define ADDFUNC2(m_vtype,m_ret,m_class,m_method,m_arg1,m_argname1,m_arg2,m_argname2,m_defarg)\
  897. _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_class,m_method),m_defarg,_VariantCall::Arg(Variant::m_arg1,_SCS(m_argname1)),_VariantCall::Arg(Variant::m_arg2,_SCS(m_argname2)));
  898. #define ADDFUNC3(m_vtype,m_ret,m_class,m_method,m_arg1,m_argname1,m_arg2,m_argname2,m_arg3,m_argname3,m_defarg)\
  899. _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_class,m_method),m_defarg,_VariantCall::Arg(Variant::m_arg1,_SCS(m_argname1)),_VariantCall::Arg(Variant::m_arg2,_SCS(m_argname2)),_VariantCall::Arg(Variant::m_arg3,_SCS(m_argname3)));
  900. #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)\
  901. _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_class,m_method),m_defarg,_VariantCall::Arg(Variant::m_arg1,_SCS(m_argname1)),_VariantCall::Arg(Variant::m_arg2,_SCS(m_argname2)),_VariantCall::Arg(Variant::m_arg3,_SCS(m_argname3)),_VariantCall::Arg(Variant::m_arg4,_SCS(m_argname4)));
  902. /* STRING */
  903. ADDFUNC1(STRING,INT,String,casecmp_to,STRING,"to",varray());
  904. ADDFUNC1(STRING,INT,String,nocasecmp_to,STRING,"to",varray());
  905. ADDFUNC0(STRING,INT,String,length,varray());
  906. ADDFUNC2(STRING,STRING,String,substr,INT,"from",INT,"len",varray());
  907. ADDFUNC2(STRING,INT,String,find,STRING,"what",INT,"from",varray(0));
  908. ADDFUNC1(STRING,INT,String,find_last,STRING,"what",varray());
  909. ADDFUNC2(STRING,INT,String,findn,STRING,"what",INT,"from",varray(0));
  910. ADDFUNC2(STRING,INT,String,rfind,STRING,"what",INT,"from",varray(-1));
  911. ADDFUNC2(STRING,INT,String,rfindn,STRING,"what",INT,"from",varray(-1));
  912. ADDFUNC1(STRING,BOOL,String,match,STRING,"expr",varray());
  913. ADDFUNC1(STRING,BOOL,String,matchn,STRING,"expr",varray());
  914. ADDFUNC1(STRING,BOOL,String,begins_with,STRING,"text",varray());
  915. ADDFUNC2(STRING,STRING,String,replace,STRING,"what",STRING,"forwhat",varray());
  916. ADDFUNC2(STRING,STRING,String,replacen,STRING,"what",STRING,"forwhat",varray());
  917. ADDFUNC2(STRING,STRING,String,insert,INT,"pos",STRING,"what",varray());
  918. ADDFUNC0(STRING,STRING,String,capitalize,varray());
  919. ADDFUNC2(STRING,STRING_ARRAY,String,split,STRING,"divisor",BOOL,"allow_empty",varray(true));
  920. ADDFUNC2(STRING,REAL_ARRAY,String,split_floats,STRING,"divisor",BOOL,"allow_empty",varray(true));
  921. ADDFUNC0(STRING,STRING,String,to_upper,varray());
  922. ADDFUNC0(STRING,STRING,String,to_lower,varray());
  923. ADDFUNC1(STRING,STRING,String,left,INT,"pos",varray());
  924. ADDFUNC1(STRING,STRING,String,right,INT,"pos",varray());
  925. ADDFUNC0(STRING,STRING,String,strip_edges,varray());
  926. ADDFUNC0(STRING,STRING,String,extension,varray());
  927. ADDFUNC0(STRING,STRING,String,basename,varray());
  928. ADDFUNC1(STRING,STRING,String,plus_file,STRING,"file",varray());
  929. ADDFUNC1(STRING,STRING,String,ord_at,INT,"at",varray());
  930. // ADDFUNC2(STRING,String,erase,INT,INT,varray());
  931. ADDFUNC0(STRING,INT,String,hash,varray());
  932. ADDFUNC0(STRING,BOOL,String,empty,varray());
  933. ADDFUNC0(STRING,BOOL,String,is_abs_path,varray());
  934. ADDFUNC0(STRING,BOOL,String,is_rel_path,varray());
  935. ADDFUNC0(STRING,STRING,String,get_base_dir,varray());
  936. ADDFUNC0(STRING,STRING,String,get_file,varray());
  937. ADDFUNC0(STRING,STRING,String,xml_escape,varray());
  938. ADDFUNC0(STRING,STRING,String,xml_unescape,varray());
  939. ADDFUNC0(STRING,STRING,String,percent_encode,varray());
  940. ADDFUNC0(STRING,STRING,String,percent_decode,varray());
  941. ADDFUNC0(STRING,BOOL,String,is_valid_identifier,varray());
  942. ADDFUNC0(STRING,BOOL,String,is_valid_integer,varray());
  943. ADDFUNC0(STRING,BOOL,String,is_valid_float,varray());
  944. ADDFUNC0(STRING,BOOL,String,is_valid_html_color,varray());
  945. ADDFUNC0(STRING,BOOL,String,is_valid_ip_address,varray());
  946. ADDFUNC0(STRING,INT,String,to_int,varray());
  947. ADDFUNC0(STRING,REAL,String,to_float,varray());
  948. ADDFUNC0(STRING,INT,String,hex_to_int,varray());
  949. ADDFUNC1(STRING,STRING,String,pad_decimals,INT,"digits",varray());
  950. ADDFUNC1(STRING,STRING,String,pad_zeros,INT,"digits",varray());
  951. ADDFUNC0(VECTOR2,VECTOR2,Vector2,normalized,varray());
  952. ADDFUNC0(VECTOR2,REAL,Vector2,length,varray());
  953. ADDFUNC0(VECTOR2,REAL,Vector2,length_squared,varray());
  954. ADDFUNC1(VECTOR2,REAL,Vector2,distance_to,VECTOR2,"to",varray());
  955. ADDFUNC1(VECTOR2,REAL,Vector2,distance_squared_to,VECTOR2,"to",varray());
  956. ADDFUNC1(VECTOR2,REAL,Vector2,angle_to,VECTOR2,"to",varray());
  957. ADDFUNC2(VECTOR2,VECTOR2,Vector2,linear_interpolate,VECTOR2,"b",REAL,"t",varray());
  958. ADDFUNC4(VECTOR2,VECTOR2,Vector2,cubic_interpolate,VECTOR2,"b",VECTOR2,"pre_a",VECTOR2,"post_b",REAL,"t",varray());
  959. ADDFUNC1(VECTOR2,VECTOR2,Vector2,rotated,REAL,"phi",varray());
  960. ADDFUNC0(VECTOR2,VECTOR2,Vector2,tangent,varray());
  961. ADDFUNC0(VECTOR2,VECTOR2,Vector2,floor,varray());
  962. ADDFUNC0(VECTOR2,VECTOR2,Vector2,floorf,varray());
  963. ADDFUNC1(VECTOR2,VECTOR2,Vector2,snapped,VECTOR2,"by",varray());
  964. ADDFUNC0(VECTOR2,REAL,Vector2,get_aspect,varray());
  965. ADDFUNC1(VECTOR2,REAL,Vector2,dot,VECTOR2,"with",varray());
  966. ADDFUNC1(VECTOR2,REAL,Vector2,slide,VECTOR2,"vec",varray());
  967. ADDFUNC1(VECTOR2,REAL,Vector2,reflect,VECTOR2,"vec",varray());
  968. //ADDFUNC1(VECTOR2,REAL,Vector2,cross,VECTOR2,"with",varray());
  969. ADDFUNC0(RECT2,REAL,Rect2,get_area,varray());
  970. ADDFUNC1(RECT2,BOOL,Rect2,intersects,RECT2,"b",varray());
  971. ADDFUNC1(RECT2,BOOL,Rect2,encloses,RECT2,"b",varray());
  972. ADDFUNC0(RECT2,BOOL,Rect2,has_no_area,varray());
  973. ADDFUNC1(RECT2,RECT2,Rect2,clip,RECT2,"b",varray());
  974. ADDFUNC1(RECT2,RECT2,Rect2,merge,RECT2,"b",varray());
  975. ADDFUNC1(RECT2,BOOL,Rect2,has_point,VECTOR2,"point",varray());
  976. ADDFUNC1(RECT2,RECT2,Rect2,grow,REAL,"by",varray());
  977. ADDFUNC1(RECT2,RECT2,Rect2,expand,VECTOR2,"to",varray());
  978. ADDFUNC0(VECTOR3,INT,Vector3,min_axis,varray());
  979. ADDFUNC0(VECTOR3,INT,Vector3,max_axis,varray());
  980. ADDFUNC0(VECTOR3,REAL,Vector3,length,varray());
  981. ADDFUNC0(VECTOR3,REAL,Vector3,length_squared,varray());
  982. ADDFUNC0(VECTOR3,VECTOR3,Vector3,normalized,varray());
  983. ADDFUNC0(VECTOR3,VECTOR3,Vector3,inverse,varray());
  984. ADDFUNC1(VECTOR3,VECTOR3,Vector3,snapped,REAL,"by",varray());
  985. ADDFUNC2(VECTOR3,VECTOR3,Vector3,rotated,VECTOR3,"axis",REAL,"phi",varray());
  986. ADDFUNC2(VECTOR3,VECTOR3,Vector3,linear_interpolate,VECTOR3,"b",REAL,"t",varray());
  987. ADDFUNC4(VECTOR3,VECTOR3,Vector3,cubic_interpolate,VECTOR3,"b",VECTOR3,"pre_a",VECTOR3,"post_b",REAL,"t",varray());
  988. ADDFUNC1(VECTOR3,REAL,Vector3,dot,VECTOR3,"b",varray());
  989. ADDFUNC1(VECTOR3,VECTOR3,Vector3,cross,VECTOR3,"b",varray());
  990. ADDFUNC0(VECTOR3,VECTOR3,Vector3,abs,varray());
  991. ADDFUNC1(VECTOR3,REAL,Vector3,distance_to,VECTOR3,"b",varray());
  992. ADDFUNC1(VECTOR3,REAL,Vector3,distance_squared_to,VECTOR3,"b",varray());
  993. ADDFUNC0(PLANE,PLANE,Plane,normalized,varray());
  994. ADDFUNC0(PLANE,VECTOR3,Plane,center,varray());
  995. ADDFUNC0(PLANE,VECTOR3,Plane,get_any_point,varray());
  996. ADDFUNC1(PLANE,BOOL,Plane,is_point_over,VECTOR3,"point",varray());
  997. ADDFUNC1(PLANE,REAL,Plane,distance_to,VECTOR3,"point",varray());
  998. ADDFUNC2(PLANE,BOOL,Plane,has_point,VECTOR3,"point",REAL,"epsilon",varray(CMP_EPSILON));
  999. ADDFUNC1(PLANE,VECTOR3,Plane,project,VECTOR3,"point",varray());
  1000. ADDFUNC2(PLANE,VECTOR3,Plane,intersect_3,PLANE,"b",PLANE,"c",varray());
  1001. ADDFUNC2(PLANE,VECTOR3,Plane,intersects_ray,VECTOR3,"from",VECTOR3,"dir",varray());
  1002. ADDFUNC2(PLANE,VECTOR3,Plane,intersects_segment,VECTOR3,"begin",VECTOR3,"end",varray());
  1003. ADDFUNC0(QUAT,REAL,Quat,length,varray());
  1004. ADDFUNC0(QUAT,REAL,Quat,length_squared,varray());
  1005. ADDFUNC0(QUAT,QUAT,Quat,normalized,varray());
  1006. ADDFUNC0(QUAT,QUAT,Quat,inverse,varray());
  1007. ADDFUNC1(QUAT,REAL,Quat,dot,QUAT,"b",varray());
  1008. ADDFUNC2(QUAT,QUAT,Quat,slerp,QUAT,"b",REAL,"t",varray());
  1009. ADDFUNC2(QUAT,QUAT,Quat,slerpni,QUAT,"b",REAL,"t",varray());
  1010. ADDFUNC4(QUAT,QUAT,Quat,cubic_slerp,QUAT,"b",QUAT,"pre_a",QUAT,"post_b",REAL,"t",varray());
  1011. ADDFUNC0(COLOR,INT,Color,to_32,varray());
  1012. ADDFUNC0(COLOR,INT,Color,to_ARGB32,varray());
  1013. ADDFUNC0(COLOR,REAL,Color,gray,varray());
  1014. ADDFUNC0(COLOR,COLOR,Color,inverted,varray());
  1015. ADDFUNC0(COLOR,COLOR,Color,contrasted,varray());
  1016. ADDFUNC2(COLOR,COLOR,Color,linear_interpolate,COLOR,"b",REAL,"t",varray());
  1017. ADDFUNC1(COLOR,COLOR,Color,blend,COLOR,"over",varray());
  1018. ADDFUNC1(COLOR,STRING,Color,to_html,BOOL,"with_alpha",varray(true));
  1019. ADDFUNC0(IMAGE, INT, Image, get_format, varray());
  1020. ADDFUNC0(IMAGE, INT, Image, get_width, varray());
  1021. ADDFUNC0(IMAGE, INT, Image, get_height, varray());
  1022. ADDFUNC0(IMAGE, BOOL, Image, empty, varray());
  1023. ADDFUNC3(IMAGE, COLOR, Image, get_pixel, INT, "x", INT, "y", INT, "mipmap_level", varray(0));
  1024. ADDFUNC3(IMAGE, IMAGE, Image, brushed, IMAGE, "src", IMAGE, "brush", VECTOR2, "pos", varray(0));
  1025. ADDFUNC1(IMAGE, INT, Image, load, STRING, "path", varray(0));
  1026. ADDFUNC3(IMAGE, NIL, Image, brush_transfer, IMAGE, "src", IMAGE, "brush", VECTOR2, "pos", varray(0));
  1027. ADDFUNC0(IMAGE, RECT2, Image, get_used_rect, varray(0));
  1028. ADDFUNC1(IMAGE, IMAGE, Image, get_rect, RECT2, "area", varray(0));
  1029. ADDFUNC1(IMAGE, IMAGE, Image, compressed, INT, "format", varray(0));
  1030. ADDFUNC3(IMAGE, IMAGE, Image, resized, INT, "x", INT, "y", INT, "interpolation", varray(((int)Image::INTERPOLATE_BILINEAR)));
  1031. ADDFUNC0(IMAGE, RAW_ARRAY, Image, get_data, varray());
  1032. ADDFUNC3(IMAGE, NIL, Image, blit_rect, IMAGE, "src", RECT2, "src_rect", VECTOR2, "dest", varray(0));
  1033. ADDFUNC0(_RID,INT,RID,get_id,varray());
  1034. ADDFUNC0(NODE_PATH,BOOL,NodePath,is_absolute,varray());
  1035. ADDFUNC0(NODE_PATH,INT,NodePath,get_name_count,varray());
  1036. ADDFUNC1(NODE_PATH,STRING,NodePath,get_name,INT,"idx",varray());
  1037. ADDFUNC0(NODE_PATH,INT,NodePath,get_subname_count,varray());
  1038. ADDFUNC1(NODE_PATH,STRING,NodePath,get_subname,INT,"idx",varray());
  1039. ADDFUNC0(NODE_PATH,STRING,NodePath,get_property,varray());
  1040. ADDFUNC0(NODE_PATH,BOOL,NodePath,is_empty,varray());
  1041. ADDFUNC0(DICTIONARY,INT,Dictionary,size,varray());
  1042. ADDFUNC0(DICTIONARY,BOOL,Dictionary,empty,varray());
  1043. ADDFUNC0(DICTIONARY,NIL,Dictionary,clear,varray());
  1044. ADDFUNC1(DICTIONARY,BOOL,Dictionary,has,NIL,"value",varray());
  1045. ADDFUNC1(DICTIONARY,NIL,Dictionary,erase,NIL,"value",varray());
  1046. ADDFUNC0(DICTIONARY,INT,Dictionary,hash,varray());
  1047. ADDFUNC0(DICTIONARY,ARRAY,Dictionary,keys,varray());
  1048. ADDFUNC1(DICTIONARY,INT,Dictionary,parse_json,STRING,"json",varray());
  1049. ADDFUNC0(DICTIONARY,STRING,Dictionary,to_json,varray());
  1050. ADDFUNC0(ARRAY,INT,Array,size,varray());
  1051. ADDFUNC0(ARRAY,BOOL,Array,empty,varray());
  1052. ADDFUNC0(ARRAY,NIL,Array,clear,varray());
  1053. ADDFUNC0(ARRAY,INT,Array,hash,varray());
  1054. ADDFUNC1(ARRAY,NIL,Array,push_back,NIL,"value",varray());
  1055. ADDFUNC1(ARRAY,NIL,Array,append,NIL,"value",varray());
  1056. ADDFUNC1(ARRAY,NIL,Array,resize,INT,"pos",varray());
  1057. ADDFUNC2(ARRAY,NIL,Array,insert,INT,"pos",NIL,"value",varray());
  1058. ADDFUNC1(ARRAY,NIL,Array,remove,INT,"pos",varray());
  1059. ADDFUNC1(ARRAY,NIL,Array,erase,NIL,"value",varray());
  1060. ADDFUNC1(ARRAY,INT,Array,find,NIL,"value",varray());
  1061. ADDFUNC0(ARRAY,NIL,Array,sort,varray());
  1062. ADDFUNC2(ARRAY,NIL,Array,sort_custom,OBJECT,"obj",STRING,"func",varray());
  1063. ADDFUNC0(ARRAY,NIL,Array,invert,varray());
  1064. ADDFUNC0(RAW_ARRAY,INT,ByteArray,size,varray());
  1065. ADDFUNC2(RAW_ARRAY,NIL,ByteArray,set,INT,"idx",INT,"byte",varray());
  1066. ADDFUNC1(RAW_ARRAY,INT,ByteArray,get,INT,"idx",varray());
  1067. ADDFUNC1(RAW_ARRAY,NIL,ByteArray,push_back,INT,"byte",varray());
  1068. ADDFUNC1(RAW_ARRAY,NIL,ByteArray,resize,INT,"idx",varray());
  1069. ADDFUNC0(RAW_ARRAY,STRING,ByteArray,get_string_from_ascii,varray());
  1070. ADDFUNC0(RAW_ARRAY,STRING,ByteArray,get_string_from_utf8,varray());
  1071. ADDFUNC0(INT_ARRAY,INT,IntArray,size,varray());
  1072. ADDFUNC2(INT_ARRAY,NIL,IntArray,set,INT,"idx",INT,"integer",varray());
  1073. ADDFUNC1(INT_ARRAY,INT,IntArray,get,INT,"idx",varray());
  1074. ADDFUNC1(INT_ARRAY,NIL,IntArray,push_back,INT,"integer",varray());
  1075. ADDFUNC1(INT_ARRAY,NIL,IntArray,resize,INT,"idx",varray());
  1076. ADDFUNC0(REAL_ARRAY,INT,RealArray,size,varray());
  1077. ADDFUNC2(REAL_ARRAY,NIL,RealArray,set,INT,"idx",REAL,"value",varray());
  1078. ADDFUNC1(REAL_ARRAY,REAL,RealArray,get,INT,"idx",varray());
  1079. ADDFUNC1(REAL_ARRAY,NIL,RealArray,push_back,REAL,"value",varray());
  1080. ADDFUNC1(REAL_ARRAY,NIL,RealArray,resize,INT,"idx",varray());
  1081. ADDFUNC0(STRING_ARRAY,INT,StringArray,size,varray());
  1082. ADDFUNC2(STRING_ARRAY,NIL,StringArray,set,INT,"idx",STRING,"string",varray());
  1083. ADDFUNC1(STRING_ARRAY,STRING,StringArray,get,INT,"idx",varray());
  1084. ADDFUNC1(STRING_ARRAY,NIL,StringArray,push_back,STRING,"string",varray());
  1085. ADDFUNC1(STRING_ARRAY,NIL,StringArray,resize,INT,"idx",varray());
  1086. ADDFUNC0(VECTOR2_ARRAY,INT,Vector2Array,size,varray());
  1087. ADDFUNC2(VECTOR2_ARRAY,NIL,Vector2Array,set,INT,"idx",VECTOR2,"vector2",varray());
  1088. ADDFUNC1(VECTOR2_ARRAY,VECTOR2,Vector2Array,get,INT,"idx",varray());
  1089. ADDFUNC1(VECTOR2_ARRAY,NIL,Vector2Array,push_back,VECTOR2,"vector2",varray());
  1090. ADDFUNC1(VECTOR2_ARRAY,NIL,Vector2Array,resize,INT,"idx",varray());
  1091. ADDFUNC0(VECTOR3_ARRAY,INT,Vector3Array,size,varray());
  1092. ADDFUNC2(VECTOR3_ARRAY,NIL,Vector3Array,set,INT,"idx",VECTOR3,"vector3",varray());
  1093. ADDFUNC1(VECTOR3_ARRAY,VECTOR3,Vector3Array,get,INT,"idx",varray());
  1094. ADDFUNC1(VECTOR3_ARRAY,NIL,Vector3Array,push_back,VECTOR3,"vector3",varray());
  1095. ADDFUNC1(VECTOR3_ARRAY,NIL,Vector3Array,resize,INT,"idx",varray());
  1096. ADDFUNC0(COLOR_ARRAY,INT,ColorArray,size,varray());
  1097. ADDFUNC2(COLOR_ARRAY,NIL,ColorArray,set,INT,"idx",COLOR,"color",varray());
  1098. ADDFUNC1(COLOR_ARRAY,COLOR,ColorArray,get,INT,"idx",varray());
  1099. ADDFUNC1(COLOR_ARRAY,NIL,ColorArray,push_back,COLOR,"color",varray());
  1100. ADDFUNC1(COLOR_ARRAY,NIL,ColorArray,resize,INT,"idx",varray());
  1101. //pointerbased
  1102. ADDFUNC0(_AABB,REAL,AABB,get_area,varray());
  1103. ADDFUNC0(_AABB,BOOL,AABB,has_no_area,varray());
  1104. ADDFUNC0(_AABB,BOOL,AABB,has_no_surface,varray());
  1105. ADDFUNC1(_AABB,BOOL,AABB,intersects,_AABB,"with",varray());
  1106. ADDFUNC1(_AABB,BOOL,AABB,encloses,_AABB,"with",varray());
  1107. ADDFUNC1(_AABB,_AABB,AABB,merge,_AABB,"with",varray());
  1108. ADDFUNC1(_AABB,_AABB,AABB,intersection,_AABB,"with",varray());
  1109. ADDFUNC1(_AABB,BOOL,AABB,intersects_plane,PLANE,"plane",varray());
  1110. ADDFUNC1(_AABB,BOOL,AABB,has_point,VECTOR3,"point",varray());
  1111. ADDFUNC1(_AABB,VECTOR3,AABB,get_support,VECTOR3,"dir",varray());
  1112. ADDFUNC0(_AABB,VECTOR3,AABB,get_longest_axis,varray());
  1113. ADDFUNC0(_AABB,INT,AABB,get_longest_axis_index,varray());
  1114. ADDFUNC0(_AABB,REAL,AABB,get_longest_axis_size,varray());
  1115. ADDFUNC0(_AABB,VECTOR3,AABB,get_shortest_axis,varray());
  1116. ADDFUNC0(_AABB,INT,AABB,get_shortest_axis_index,varray());
  1117. ADDFUNC0(_AABB,REAL,AABB,get_shortest_axis_size,varray());
  1118. ADDFUNC1(_AABB,_AABB,AABB,expand,VECTOR3,"to_point",varray());
  1119. ADDFUNC1(_AABB,_AABB,AABB,grow,REAL,"by",varray());
  1120. ADDFUNC1(_AABB,VECTOR3,AABB,get_endpoint,INT,"idx",varray());
  1121. ADDFUNC0(MATRIX32,MATRIX32,Matrix32,inverse,varray());
  1122. ADDFUNC0(MATRIX32,MATRIX32,Matrix32,affine_inverse,varray());
  1123. ADDFUNC0(MATRIX32,REAL,Matrix32,get_rotation,varray());
  1124. ADDFUNC0(MATRIX32,VECTOR2,Matrix32,get_origin,varray());
  1125. ADDFUNC0(MATRIX32,VECTOR2,Matrix32,get_scale,varray());
  1126. ADDFUNC0(MATRIX32,MATRIX32,Matrix32,orthonormalized,varray());
  1127. ADDFUNC1(MATRIX32,MATRIX32,Matrix32,rotated,REAL,"phi",varray());
  1128. ADDFUNC1(MATRIX32,MATRIX32,Matrix32,scaled,VECTOR2,"scale",varray());
  1129. ADDFUNC1(MATRIX32,MATRIX32,Matrix32,translated,VECTOR2,"offset",varray());
  1130. ADDFUNC1(MATRIX32,MATRIX32,Matrix32,xform,NIL,"v",varray());
  1131. ADDFUNC1(MATRIX32,MATRIX32,Matrix32,xform_inv,NIL,"v",varray());
  1132. ADDFUNC2(MATRIX32,MATRIX32,Matrix32,interpolate_with,MATRIX32,"m",REAL,"c",varray());
  1133. ADDFUNC0(MATRIX3,MATRIX3,Matrix3,inverse,varray());
  1134. ADDFUNC0(MATRIX3,MATRIX3,Matrix3,transposed,varray());
  1135. ADDFUNC0(MATRIX3,MATRIX3,Matrix3,orthonormalized,varray());
  1136. ADDFUNC0(MATRIX3,REAL,Matrix3,determinant,varray());
  1137. ADDFUNC2(MATRIX3,MATRIX3,Matrix3,rotated,VECTOR3,"axis",REAL,"phi",varray());
  1138. ADDFUNC1(MATRIX3,MATRIX3,Matrix3,scaled,VECTOR3,"scale",varray());
  1139. ADDFUNC0(MATRIX3,VECTOR3,Matrix3,get_scale,varray());
  1140. ADDFUNC0(MATRIX3,VECTOR3,Matrix3,get_euler,varray());
  1141. ADDFUNC1(MATRIX3,REAL,Matrix3,tdotx,VECTOR3,"with",varray());
  1142. ADDFUNC1(MATRIX3,REAL,Matrix3,tdoty,VECTOR3,"with",varray());
  1143. ADDFUNC1(MATRIX3,REAL,Matrix3,tdotz,VECTOR3,"with",varray());
  1144. ADDFUNC1(MATRIX3,VECTOR3,Matrix3,xform,VECTOR3,"v",varray());
  1145. ADDFUNC1(MATRIX3,VECTOR3,Matrix3,xform_inv,VECTOR3,"v",varray());
  1146. ADDFUNC0(MATRIX3,INT,Matrix3,get_orthogonal_index,varray());
  1147. ADDFUNC0(TRANSFORM,TRANSFORM,Transform,inverse,varray());
  1148. ADDFUNC0(TRANSFORM,TRANSFORM,Transform,affine_inverse,varray());
  1149. ADDFUNC0(TRANSFORM,TRANSFORM,Transform,orthonormalized,varray());
  1150. ADDFUNC2(TRANSFORM,TRANSFORM,Transform,rotated,VECTOR3,"axis",REAL,"phi",varray());
  1151. ADDFUNC1(TRANSFORM,TRANSFORM,Transform,scaled,VECTOR3,"scale",varray());
  1152. ADDFUNC1(TRANSFORM,TRANSFORM,Transform,translated,VECTOR3,"ofs",varray());
  1153. ADDFUNC2(TRANSFORM,TRANSFORM,Transform,looking_at,VECTOR3,"target",VECTOR3,"up",varray());
  1154. ADDFUNC1(TRANSFORM,NIL,Transform,xform,NIL,"v",varray());
  1155. ADDFUNC1(TRANSFORM,NIL,Transform,xform_inv,NIL,"v",varray());
  1156. #ifdef DEBUG_ENABLED
  1157. _VariantCall::type_funcs[Variant::TRANSFORM].functions["xform"].returns=true;
  1158. _VariantCall::type_funcs[Variant::TRANSFORM].functions["xform_inv"].returns=true;
  1159. #endif
  1160. ADDFUNC0(INPUT_EVENT,BOOL,InputEvent,is_pressed,varray());
  1161. ADDFUNC1(INPUT_EVENT,BOOL,InputEvent,is_action,STRING,"action",varray());
  1162. ADDFUNC0(INPUT_EVENT,BOOL,InputEvent,is_echo,varray());
  1163. /* REGISTER CONSTRUCTORS */
  1164. _VariantCall::add_constructor(_VariantCall::Vector2_init1,Variant::VECTOR2,"x",Variant::REAL,"y",Variant::REAL);
  1165. _VariantCall::add_constructor(_VariantCall::Rect2_init1,Variant::RECT2,"pos",Variant::VECTOR2,"size",Variant::VECTOR2);
  1166. _VariantCall::add_constructor(_VariantCall::Rect2_init2,Variant::RECT2,"x",Variant::REAL,"y",Variant::REAL,"width",Variant::REAL,"height",Variant::REAL);
  1167. _VariantCall::add_constructor(_VariantCall::Matrix32_init3,Variant::MATRIX32,"x_axis",Variant::VECTOR2,"y_axis",Variant::VECTOR2,"origin",Variant::VECTOR2);
  1168. _VariantCall::add_constructor(_VariantCall::Vector3_init1,Variant::VECTOR3,"x",Variant::REAL,"y",Variant::REAL,"z",Variant::REAL);
  1169. _VariantCall::add_constructor(_VariantCall::Plane_init1,Variant::PLANE,"a",Variant::REAL,"b",Variant::REAL,"c",Variant::REAL,"d",Variant::REAL);
  1170. _VariantCall::add_constructor(_VariantCall::Plane_init2,Variant::PLANE,"v1",Variant::VECTOR3,"v2",Variant::VECTOR3,"v3",Variant::VECTOR3);
  1171. _VariantCall::add_constructor(_VariantCall::Plane_init3,Variant::PLANE,"normal",Variant::VECTOR3,"d",Variant::REAL);
  1172. _VariantCall::add_constructor(_VariantCall::Quat_init1,Variant::QUAT,"x",Variant::REAL,"y",Variant::REAL,"z",Variant::REAL,"w",Variant::REAL);
  1173. _VariantCall::add_constructor(_VariantCall::Color_init1,Variant::COLOR,"r",Variant::REAL,"g",Variant::REAL,"b",Variant::REAL,"a",Variant::REAL);
  1174. _VariantCall::add_constructor(_VariantCall::Color_init2,Variant::COLOR,"r",Variant::REAL,"g",Variant::REAL,"b",Variant::REAL);
  1175. _VariantCall::add_constructor(_VariantCall::AABB_init1,Variant::_AABB,"pos",Variant::VECTOR3,"size",Variant::VECTOR3);
  1176. _VariantCall::add_constructor(_VariantCall::Matrix3_init1,Variant::MATRIX3,"x_axis",Variant::VECTOR3,"y_axis",Variant::VECTOR3,"z_axis",Variant::VECTOR3);
  1177. _VariantCall::add_constructor(_VariantCall::Matrix3_init2,Variant::MATRIX3,"axis",Variant::VECTOR3,"phi",Variant::REAL);
  1178. _VariantCall::add_constructor(_VariantCall::Transform_init1,Variant::TRANSFORM,"x_axis",Variant::VECTOR3,"y_axis",Variant::VECTOR3,"z_axis",Variant::VECTOR3,"origin",Variant::VECTOR3);
  1179. _VariantCall::add_constructor(_VariantCall::Transform_init2,Variant::TRANSFORM,"basis",Variant::MATRIX3,"origin",Variant::VECTOR3);
  1180. /* REGISTER CONSTANTS */
  1181. _VariantCall::constant_data[Variant::VECTOR3].value["AXIS_X"]=Vector3::AXIS_X;
  1182. _VariantCall::constant_data[Variant::VECTOR3].value["AXIS_Y"]=Vector3::AXIS_Y;
  1183. _VariantCall::constant_data[Variant::VECTOR3].value["AXIS_Z"]=Vector3::AXIS_Z;
  1184. _VariantCall::constant_data[Variant::INPUT_EVENT].value["NONE"]=InputEvent::NONE;
  1185. _VariantCall::constant_data[Variant::INPUT_EVENT].value["KEY"]=InputEvent::KEY;
  1186. _VariantCall::constant_data[Variant::INPUT_EVENT].value["MOUSE_MOTION"]=InputEvent::MOUSE_MOTION;
  1187. _VariantCall::constant_data[Variant::INPUT_EVENT].value["MOUSE_BUTTON"]=InputEvent::MOUSE_BUTTON;
  1188. _VariantCall::constant_data[Variant::INPUT_EVENT].value["JOYSTICK_MOTION"]=InputEvent::JOYSTICK_MOTION;
  1189. _VariantCall::constant_data[Variant::INPUT_EVENT].value["JOYSTICK_BUTTON"]=InputEvent::JOYSTICK_BUTTON;
  1190. _VariantCall::constant_data[Variant::INPUT_EVENT].value["SCREEN_TOUCH"]=InputEvent::SCREEN_TOUCH;
  1191. _VariantCall::constant_data[Variant::INPUT_EVENT].value["SCREEN_DRAG"]=InputEvent::SCREEN_DRAG;
  1192. _VariantCall::constant_data[Variant::INPUT_EVENT].value["ACTION"]=InputEvent::ACTION;
  1193. _VariantCall::constant_data[Variant::IMAGE].value["COMPRESS_BC"]=Image::COMPRESS_BC;
  1194. _VariantCall::constant_data[Variant::IMAGE].value["COMPRESS_PVRTC2"]=Image::COMPRESS_PVRTC2;
  1195. _VariantCall::constant_data[Variant::IMAGE].value["COMPRESS_PVRTC4"]=Image::COMPRESS_PVRTC4;
  1196. _VariantCall::constant_data[Variant::IMAGE].value["COMPRESS_ETC"]=Image::COMPRESS_ETC;
  1197. _VariantCall::constant_data[Variant::IMAGE].value["FORMAT_GRAYSCALE"]=Image::FORMAT_GRAYSCALE;
  1198. _VariantCall::constant_data[Variant::IMAGE].value["FORMAT_INTENSITY"]=Image::FORMAT_INTENSITY;
  1199. _VariantCall::constant_data[Variant::IMAGE].value["FORMAT_GRAYSCALE_ALPHA"]=Image::FORMAT_GRAYSCALE_ALPHA;
  1200. _VariantCall::constant_data[Variant::IMAGE].value["FORMAT_RGB"]=Image::FORMAT_RGB;
  1201. _VariantCall::constant_data[Variant::IMAGE].value["FORMAT_RGBA"]=Image::FORMAT_RGBA;
  1202. _VariantCall::constant_data[Variant::IMAGE].value["FORMAT_INDEXED"]=Image::FORMAT_INDEXED;
  1203. _VariantCall::constant_data[Variant::IMAGE].value["FORMAT_INDEXED_ALPHA"]=Image::FORMAT_INDEXED_ALPHA;
  1204. _VariantCall::constant_data[Variant::IMAGE].value["FORMAT_YUV_422"]=Image::FORMAT_YUV_422;
  1205. _VariantCall::constant_data[Variant::IMAGE].value["FORMAT_YUV_444"]=Image::FORMAT_YUV_444;
  1206. _VariantCall::constant_data[Variant::IMAGE].value["FORMAT_BC1"]=Image::FORMAT_BC1;
  1207. _VariantCall::constant_data[Variant::IMAGE].value["FORMAT_BC2"]=Image::FORMAT_BC2;
  1208. _VariantCall::constant_data[Variant::IMAGE].value["FORMAT_BC3"]=Image::FORMAT_BC3;
  1209. _VariantCall::constant_data[Variant::IMAGE].value["FORMAT_BC4"]=Image::FORMAT_BC4;
  1210. _VariantCall::constant_data[Variant::IMAGE].value["FORMAT_BC5"]=Image::FORMAT_BC5;
  1211. _VariantCall::constant_data[Variant::IMAGE].value["FORMAT_PVRTC2"]=Image::FORMAT_PVRTC2;
  1212. _VariantCall::constant_data[Variant::IMAGE].value["FORMAT_PVRTC2_ALPHA"]=Image::FORMAT_PVRTC2_ALPHA;
  1213. _VariantCall::constant_data[Variant::IMAGE].value["FORMAT_PVRTC4"]=Image::FORMAT_PVRTC4;
  1214. _VariantCall::constant_data[Variant::IMAGE].value["FORMAT_PVRTC4_ALPHA"]=Image::FORMAT_PVRTC4_ALPHA;
  1215. _VariantCall::constant_data[Variant::IMAGE].value["FORMAT_ETC"]=Image::FORMAT_ETC;
  1216. _VariantCall::constant_data[Variant::IMAGE].value["FORMAT_ATC"]=Image::FORMAT_ATC;
  1217. _VariantCall::constant_data[Variant::IMAGE].value["FORMAT_ATC_ALPHA_EXPLICIT"]=Image::FORMAT_ATC_ALPHA_EXPLICIT;
  1218. _VariantCall::constant_data[Variant::IMAGE].value["FORMAT_ATC_ALPHA_INTERPOLATED"]=Image::FORMAT_ATC_ALPHA_INTERPOLATED;
  1219. _VariantCall::constant_data[Variant::IMAGE].value["FORMAT_CUSTOM"]=Image::FORMAT_CUSTOM;
  1220. }
  1221. void unregister_variant_methods() {
  1222. memdelete_arr(_VariantCall::type_funcs);
  1223. memdelete_arr(_VariantCall::construct_funcs);
  1224. memdelete_arr( _VariantCall::constant_data );
  1225. }