lua_generated_bindings.cpp 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739
  1. // auto generated bindings, don't manually edit
  2. #include "lua_generated_bindings.h"
  3. #include "lua_boxed_numerics.h"
  4. #include <GCS_MAVLink/GCS.h>
  5. #include <AP_Relay/AP_Relay.h>
  6. #include <AP_Terrain/AP_Terrain.h>
  7. #include <AP_RangeFinder/AP_RangeFinder.h>
  8. #include <AP_Notify/AP_Notify.h>
  9. #include <AP_Math/AP_Math.h>
  10. #include <AP_GPS/AP_GPS.h>
  11. #include <AP_BattMonitor/AP_BattMonitor.h>
  12. #include <AP_Arming/AP_Arming.h>
  13. #include <AP_AHRS/AP_AHRS.h>
  14. #include <AP_Common/Location.h>
  15. #if !defined(AP_TERRAIN_AVAILABLE) || (AP_TERRAIN_AVAILABLE != 1)
  16. #error Scripting requires terrain to be available
  17. #endif // !defined(AP_TERRAIN_AVAILABLE) || (AP_TERRAIN_AVAILABLE != 1)
  18. static int binding_argcheck(lua_State *L, int expected_arg_count) {
  19. const int args = lua_gettop(L);
  20. if (args > expected_arg_count) {
  21. return luaL_argerror(L, args, "too many arguments");
  22. } else if (args < expected_arg_count) {
  23. return luaL_argerror(L, args, "too few arguments");
  24. }
  25. return 0;
  26. }
  27. int new_Vector2f(lua_State *L) {
  28. luaL_checkstack(L, 2, "Out of stack");
  29. void *ud = lua_newuserdata(L, sizeof(Vector2f));
  30. memset(ud, 0, sizeof(Vector2f));
  31. new (ud) Vector2f();
  32. luaL_getmetatable(L, "Vector2f");
  33. lua_setmetatable(L, -2);
  34. return 1;
  35. }
  36. int new_Vector3f(lua_State *L) {
  37. luaL_checkstack(L, 2, "Out of stack");
  38. void *ud = lua_newuserdata(L, sizeof(Vector3f));
  39. memset(ud, 0, sizeof(Vector3f));
  40. new (ud) Vector3f();
  41. luaL_getmetatable(L, "Vector3f");
  42. lua_setmetatable(L, -2);
  43. return 1;
  44. }
  45. int new_Location(lua_State *L) {
  46. luaL_checkstack(L, 2, "Out of stack");
  47. void *ud = lua_newuserdata(L, sizeof(Location));
  48. memset(ud, 0, sizeof(Location));
  49. new (ud) Location();
  50. luaL_getmetatable(L, "Location");
  51. lua_setmetatable(L, -2);
  52. return 1;
  53. }
  54. Vector2f * check_Vector2f(lua_State *L, int arg) {
  55. void *data = luaL_checkudata(L, arg, "Vector2f");
  56. return (Vector2f *)data;
  57. }
  58. Vector3f * check_Vector3f(lua_State *L, int arg) {
  59. void *data = luaL_checkudata(L, arg, "Vector3f");
  60. return (Vector3f *)data;
  61. }
  62. Location * check_Location(lua_State *L, int arg) {
  63. void *data = luaL_checkudata(L, arg, "Location");
  64. return (Location *)data;
  65. }
  66. static int Vector2f_y(lua_State *L) {
  67. Vector2f *ud = check_Vector2f(L, 1);
  68. switch(lua_gettop(L)) {
  69. case 1:
  70. lua_pushnumber(L, ud->y);
  71. return 1;
  72. case 2: {
  73. const float raw_data_2 = luaL_checknumber(L, 2);
  74. luaL_argcheck(L, ((raw_data_2 >= MAX(-FLT_MAX, -INFINITY)) && (raw_data_2 <= MIN(FLT_MAX, INFINITY))), 2, "y out of range");
  75. const float data_2 = raw_data_2;
  76. ud->y = data_2;
  77. return 0;
  78. }
  79. default:
  80. return luaL_argerror(L, lua_gettop(L), "too many arguments");
  81. }
  82. }
  83. static int Vector2f_x(lua_State *L) {
  84. Vector2f *ud = check_Vector2f(L, 1);
  85. switch(lua_gettop(L)) {
  86. case 1:
  87. lua_pushnumber(L, ud->x);
  88. return 1;
  89. case 2: {
  90. const float raw_data_2 = luaL_checknumber(L, 2);
  91. luaL_argcheck(L, ((raw_data_2 >= MAX(-FLT_MAX, -INFINITY)) && (raw_data_2 <= MIN(FLT_MAX, INFINITY))), 2, "x out of range");
  92. const float data_2 = raw_data_2;
  93. ud->x = data_2;
  94. return 0;
  95. }
  96. default:
  97. return luaL_argerror(L, lua_gettop(L), "too many arguments");
  98. }
  99. }
  100. static int Vector3f_z(lua_State *L) {
  101. Vector3f *ud = check_Vector3f(L, 1);
  102. switch(lua_gettop(L)) {
  103. case 1:
  104. lua_pushnumber(L, ud->z);
  105. return 1;
  106. case 2: {
  107. const float raw_data_2 = luaL_checknumber(L, 2);
  108. luaL_argcheck(L, ((raw_data_2 >= MAX(-FLT_MAX, -INFINITY)) && (raw_data_2 <= MIN(FLT_MAX, INFINITY))), 2, "z out of range");
  109. const float data_2 = raw_data_2;
  110. ud->z = data_2;
  111. return 0;
  112. }
  113. default:
  114. return luaL_argerror(L, lua_gettop(L), "too many arguments");
  115. }
  116. }
  117. static int Vector3f_y(lua_State *L) {
  118. Vector3f *ud = check_Vector3f(L, 1);
  119. switch(lua_gettop(L)) {
  120. case 1:
  121. lua_pushnumber(L, ud->y);
  122. return 1;
  123. case 2: {
  124. const float raw_data_2 = luaL_checknumber(L, 2);
  125. luaL_argcheck(L, ((raw_data_2 >= MAX(-FLT_MAX, -INFINITY)) && (raw_data_2 <= MIN(FLT_MAX, INFINITY))), 2, "y out of range");
  126. const float data_2 = raw_data_2;
  127. ud->y = data_2;
  128. return 0;
  129. }
  130. default:
  131. return luaL_argerror(L, lua_gettop(L), "too many arguments");
  132. }
  133. }
  134. static int Vector3f_x(lua_State *L) {
  135. Vector3f *ud = check_Vector3f(L, 1);
  136. switch(lua_gettop(L)) {
  137. case 1:
  138. lua_pushnumber(L, ud->x);
  139. return 1;
  140. case 2: {
  141. const float raw_data_2 = luaL_checknumber(L, 2);
  142. luaL_argcheck(L, ((raw_data_2 >= MAX(-FLT_MAX, -INFINITY)) && (raw_data_2 <= MIN(FLT_MAX, INFINITY))), 2, "x out of range");
  143. const float data_2 = raw_data_2;
  144. ud->x = data_2;
  145. return 0;
  146. }
  147. default:
  148. return luaL_argerror(L, lua_gettop(L), "too many arguments");
  149. }
  150. }
  151. static int Location_loiter_xtrack(lua_State *L) {
  152. Location *ud = check_Location(L, 1);
  153. switch(lua_gettop(L)) {
  154. case 1:
  155. lua_pushinteger(L, ud->loiter_xtrack);
  156. return 1;
  157. case 2: {
  158. const bool data_2 = static_cast<bool>(lua_toboolean(L, 2));
  159. ud->loiter_xtrack = data_2;
  160. return 0;
  161. }
  162. default:
  163. return luaL_argerror(L, lua_gettop(L), "too many arguments");
  164. }
  165. }
  166. static int Location_origin_alt(lua_State *L) {
  167. Location *ud = check_Location(L, 1);
  168. switch(lua_gettop(L)) {
  169. case 1:
  170. lua_pushinteger(L, ud->origin_alt);
  171. return 1;
  172. case 2: {
  173. const bool data_2 = static_cast<bool>(lua_toboolean(L, 2));
  174. ud->origin_alt = data_2;
  175. return 0;
  176. }
  177. default:
  178. return luaL_argerror(L, lua_gettop(L), "too many arguments");
  179. }
  180. }
  181. static int Location_terrain_alt(lua_State *L) {
  182. Location *ud = check_Location(L, 1);
  183. switch(lua_gettop(L)) {
  184. case 1:
  185. lua_pushinteger(L, ud->terrain_alt);
  186. return 1;
  187. case 2: {
  188. const bool data_2 = static_cast<bool>(lua_toboolean(L, 2));
  189. ud->terrain_alt = data_2;
  190. return 0;
  191. }
  192. default:
  193. return luaL_argerror(L, lua_gettop(L), "too many arguments");
  194. }
  195. }
  196. static int Location_relative_alt(lua_State *L) {
  197. Location *ud = check_Location(L, 1);
  198. switch(lua_gettop(L)) {
  199. case 1:
  200. lua_pushinteger(L, ud->relative_alt);
  201. return 1;
  202. case 2: {
  203. const bool data_2 = static_cast<bool>(lua_toboolean(L, 2));
  204. ud->relative_alt = data_2;
  205. return 0;
  206. }
  207. default:
  208. return luaL_argerror(L, lua_gettop(L), "too many arguments");
  209. }
  210. }
  211. static int Location_lng(lua_State *L) {
  212. Location *ud = check_Location(L, 1);
  213. switch(lua_gettop(L)) {
  214. case 1:
  215. lua_pushinteger(L, ud->lng);
  216. return 1;
  217. case 2: {
  218. const lua_Integer raw_data_2 = luaL_checkinteger(L, 2);
  219. luaL_argcheck(L, ((raw_data_2 >= MAX(-1800000000, INT32_MIN)) && (raw_data_2 <= MIN(1800000000, INT32_MAX))), 2, "lng out of range");
  220. const int32_t data_2 = raw_data_2;
  221. ud->lng = data_2;
  222. return 0;
  223. }
  224. default:
  225. return luaL_argerror(L, lua_gettop(L), "too many arguments");
  226. }
  227. }
  228. static int Location_lat(lua_State *L) {
  229. Location *ud = check_Location(L, 1);
  230. switch(lua_gettop(L)) {
  231. case 1:
  232. lua_pushinteger(L, ud->lat);
  233. return 1;
  234. case 2: {
  235. const lua_Integer raw_data_2 = luaL_checkinteger(L, 2);
  236. luaL_argcheck(L, ((raw_data_2 >= MAX(-900000000, INT32_MIN)) && (raw_data_2 <= MIN(900000000, INT32_MAX))), 2, "lat out of range");
  237. const int32_t data_2 = raw_data_2;
  238. ud->lat = data_2;
  239. return 0;
  240. }
  241. default:
  242. return luaL_argerror(L, lua_gettop(L), "too many arguments");
  243. }
  244. }
  245. static int Vector2f_is_zero(lua_State *L) {
  246. binding_argcheck(L, 1);
  247. Vector2f * ud = check_Vector2f(L, 1);
  248. const bool data = ud->is_zero();
  249. lua_pushboolean(L, data);
  250. return 1;
  251. }
  252. static int Vector2f_is_inf(lua_State *L) {
  253. binding_argcheck(L, 1);
  254. Vector2f * ud = check_Vector2f(L, 1);
  255. const bool data = ud->is_inf();
  256. lua_pushboolean(L, data);
  257. return 1;
  258. }
  259. static int Vector2f_is_nan(lua_State *L) {
  260. binding_argcheck(L, 1);
  261. Vector2f * ud = check_Vector2f(L, 1);
  262. const bool data = ud->is_nan();
  263. lua_pushboolean(L, data);
  264. return 1;
  265. }
  266. static int Vector2f_normalize(lua_State *L) {
  267. binding_argcheck(L, 1);
  268. Vector2f * ud = check_Vector2f(L, 1);
  269. ud->normalize();
  270. return 0;
  271. }
  272. static int Vector2f_length(lua_State *L) {
  273. binding_argcheck(L, 1);
  274. Vector2f * ud = check_Vector2f(L, 1);
  275. const float data = ud->length();
  276. lua_pushnumber(L, data);
  277. return 1;
  278. }
  279. static int Vector2f___add(lua_State *L) {
  280. binding_argcheck(L, 2);
  281. Vector2f *ud = check_Vector2f(L, 1);
  282. Vector2f *ud2 = check_Vector2f(L, 2);
  283. new_Vector2f(L);
  284. *check_Vector2f(L, -1) = *ud + *ud2;;
  285. return 1;
  286. }
  287. static int Vector2f___sub(lua_State *L) {
  288. binding_argcheck(L, 2);
  289. Vector2f *ud = check_Vector2f(L, 1);
  290. Vector2f *ud2 = check_Vector2f(L, 2);
  291. new_Vector2f(L);
  292. *check_Vector2f(L, -1) = *ud - *ud2;;
  293. return 1;
  294. }
  295. static int Vector3f_is_zero(lua_State *L) {
  296. binding_argcheck(L, 1);
  297. Vector3f * ud = check_Vector3f(L, 1);
  298. const bool data = ud->is_zero();
  299. lua_pushboolean(L, data);
  300. return 1;
  301. }
  302. static int Vector3f_is_inf(lua_State *L) {
  303. binding_argcheck(L, 1);
  304. Vector3f * ud = check_Vector3f(L, 1);
  305. const bool data = ud->is_inf();
  306. lua_pushboolean(L, data);
  307. return 1;
  308. }
  309. static int Vector3f_is_nan(lua_State *L) {
  310. binding_argcheck(L, 1);
  311. Vector3f * ud = check_Vector3f(L, 1);
  312. const bool data = ud->is_nan();
  313. lua_pushboolean(L, data);
  314. return 1;
  315. }
  316. static int Vector3f_normalize(lua_State *L) {
  317. binding_argcheck(L, 1);
  318. Vector3f * ud = check_Vector3f(L, 1);
  319. ud->normalize();
  320. return 0;
  321. }
  322. static int Vector3f_length(lua_State *L) {
  323. binding_argcheck(L, 1);
  324. Vector3f * ud = check_Vector3f(L, 1);
  325. const float data = ud->length();
  326. lua_pushnumber(L, data);
  327. return 1;
  328. }
  329. static int Vector3f___add(lua_State *L) {
  330. binding_argcheck(L, 2);
  331. Vector3f *ud = check_Vector3f(L, 1);
  332. Vector3f *ud2 = check_Vector3f(L, 2);
  333. new_Vector3f(L);
  334. *check_Vector3f(L, -1) = *ud + *ud2;;
  335. return 1;
  336. }
  337. static int Vector3f___sub(lua_State *L) {
  338. binding_argcheck(L, 2);
  339. Vector3f *ud = check_Vector3f(L, 1);
  340. Vector3f *ud2 = check_Vector3f(L, 2);
  341. new_Vector3f(L);
  342. *check_Vector3f(L, -1) = *ud - *ud2;;
  343. return 1;
  344. }
  345. static int Location_get_vector_from_origin_NEU(lua_State *L) {
  346. binding_argcheck(L, 1);
  347. Location * ud = check_Location(L, 1);
  348. Vector3f data_5002 = {};
  349. const bool data = ud->get_vector_from_origin_NEU(
  350. data_5002);
  351. if (data) {
  352. new_Vector3f(L);
  353. *check_Vector3f(L, -1) = data_5002;
  354. } else {
  355. lua_pushnil(L);
  356. }
  357. return 1;
  358. }
  359. static int Location_offset(lua_State *L) {
  360. binding_argcheck(L, 3);
  361. Location * ud = check_Location(L, 1);
  362. const float raw_data_2 = luaL_checknumber(L, 2);
  363. luaL_argcheck(L, ((raw_data_2 >= MAX(-FLT_MAX, -INFINITY)) && (raw_data_2 <= MIN(FLT_MAX, INFINITY))), 2, "argument out of range");
  364. const float data_2 = raw_data_2;
  365. const float raw_data_3 = luaL_checknumber(L, 3);
  366. luaL_argcheck(L, ((raw_data_3 >= MAX(-FLT_MAX, -INFINITY)) && (raw_data_3 <= MIN(FLT_MAX, INFINITY))), 3, "argument out of range");
  367. const float data_3 = raw_data_3;
  368. ud->offset(
  369. data_2,
  370. data_3);
  371. return 0;
  372. }
  373. static int Location_get_distance(lua_State *L) {
  374. binding_argcheck(L, 2);
  375. Location * ud = check_Location(L, 1);
  376. Location & data_2 = *check_Location(L, 2);
  377. const float data = ud->get_distance(
  378. data_2);
  379. lua_pushnumber(L, data);
  380. return 1;
  381. }
  382. const luaL_Reg Vector2f_meta[] = {
  383. {"y", Vector2f_y},
  384. {"x", Vector2f_x},
  385. {"is_zero", Vector2f_is_zero},
  386. {"is_inf", Vector2f_is_inf},
  387. {"is_nan", Vector2f_is_nan},
  388. {"normalize", Vector2f_normalize},
  389. {"length", Vector2f_length},
  390. {"__add", Vector2f___add},
  391. {"__sub", Vector2f___sub},
  392. {NULL, NULL}
  393. };
  394. const luaL_Reg Vector3f_meta[] = {
  395. {"z", Vector3f_z},
  396. {"y", Vector3f_y},
  397. {"x", Vector3f_x},
  398. {"is_zero", Vector3f_is_zero},
  399. {"is_inf", Vector3f_is_inf},
  400. {"is_nan", Vector3f_is_nan},
  401. {"normalize", Vector3f_normalize},
  402. {"length", Vector3f_length},
  403. {"__add", Vector3f___add},
  404. {"__sub", Vector3f___sub},
  405. {NULL, NULL}
  406. };
  407. const luaL_Reg Location_meta[] = {
  408. {"loiter_xtrack", Location_loiter_xtrack},
  409. {"origin_alt", Location_origin_alt},
  410. {"terrain_alt", Location_terrain_alt},
  411. {"relative_alt", Location_relative_alt},
  412. {"lng", Location_lng},
  413. {"lat", Location_lat},
  414. {"get_vector_from_origin_NEU", Location_get_vector_from_origin_NEU},
  415. {"offset", Location_offset},
  416. {"get_distance", Location_get_distance},
  417. {NULL, NULL}
  418. };
  419. static int GCS_send_text(lua_State *L) {
  420. GCS * ud = GCS::get_singleton();
  421. if (ud == nullptr) {
  422. return luaL_argerror(L, 1, "gcs not supported on this firmware");
  423. }
  424. binding_argcheck(L, 3);
  425. const lua_Integer raw_data_2 = luaL_checkinteger(L, 2);
  426. luaL_argcheck(L, ((raw_data_2 >= static_cast<int32_t>(MAV_SEVERITY_EMERGENCY)) && (raw_data_2 <= static_cast<int32_t>(MAV_SEVERITY_DEBUG))), 2, "argument out of range");
  427. const MAV_SEVERITY data_2 = static_cast<MAV_SEVERITY>(raw_data_2);
  428. const char * data_3 = luaL_checkstring(L, 3);
  429. ud->send_text(
  430. data_2,
  431. "%s",
  432. data_3);
  433. return 0;
  434. }
  435. static int AP_Relay_toggle(lua_State *L) {
  436. AP_Relay * ud = AP_Relay::get_singleton();
  437. if (ud == nullptr) {
  438. return luaL_argerror(L, 1, "relay not supported on this firmware");
  439. }
  440. binding_argcheck(L, 2);
  441. const lua_Integer raw_data_2 = luaL_checkinteger(L, 2);
  442. luaL_argcheck(L, ((raw_data_2 >= MAX(0, 0)) && (raw_data_2 <= MIN(AP_RELAY_NUM_RELAYS, UINT8_MAX))), 2, "argument out of range");
  443. const uint8_t data_2 = static_cast<uint8_t>(raw_data_2);
  444. ud->toggle(
  445. data_2);
  446. return 0;
  447. }
  448. static int AP_Relay_enabled(lua_State *L) {
  449. AP_Relay * ud = AP_Relay::get_singleton();
  450. if (ud == nullptr) {
  451. return luaL_argerror(L, 1, "relay not supported on this firmware");
  452. }
  453. binding_argcheck(L, 2);
  454. const lua_Integer raw_data_2 = luaL_checkinteger(L, 2);
  455. luaL_argcheck(L, ((raw_data_2 >= MAX(0, 0)) && (raw_data_2 <= MIN(AP_RELAY_NUM_RELAYS, UINT8_MAX))), 2, "argument out of range");
  456. const uint8_t data_2 = static_cast<uint8_t>(raw_data_2);
  457. const bool data = ud->enabled(
  458. data_2);
  459. lua_pushboolean(L, data);
  460. return 1;
  461. }
  462. static int AP_Relay_off(lua_State *L) {
  463. AP_Relay * ud = AP_Relay::get_singleton();
  464. if (ud == nullptr) {
  465. return luaL_argerror(L, 1, "relay not supported on this firmware");
  466. }
  467. binding_argcheck(L, 2);
  468. const lua_Integer raw_data_2 = luaL_checkinteger(L, 2);
  469. luaL_argcheck(L, ((raw_data_2 >= MAX(0, 0)) && (raw_data_2 <= MIN(AP_RELAY_NUM_RELAYS, UINT8_MAX))), 2, "argument out of range");
  470. const uint8_t data_2 = static_cast<uint8_t>(raw_data_2);
  471. ud->off(
  472. data_2);
  473. return 0;
  474. }
  475. static int AP_Relay_on(lua_State *L) {
  476. AP_Relay * ud = AP_Relay::get_singleton();
  477. if (ud == nullptr) {
  478. return luaL_argerror(L, 1, "relay not supported on this firmware");
  479. }
  480. binding_argcheck(L, 2);
  481. const lua_Integer raw_data_2 = luaL_checkinteger(L, 2);
  482. luaL_argcheck(L, ((raw_data_2 >= MAX(0, 0)) && (raw_data_2 <= MIN(AP_RELAY_NUM_RELAYS, UINT8_MAX))), 2, "argument out of range");
  483. const uint8_t data_2 = static_cast<uint8_t>(raw_data_2);
  484. ud->on(
  485. data_2);
  486. return 0;
  487. }
  488. static int AP_Terrain_height_above_terrain(lua_State *L) {
  489. AP_Terrain * ud = AP_Terrain::get_singleton();
  490. if (ud == nullptr) {
  491. return luaL_argerror(L, 1, "terrain not supported on this firmware");
  492. }
  493. binding_argcheck(L, 2);
  494. float data_5002 = {};
  495. const bool data_3 = static_cast<bool>(lua_toboolean(L, 3));
  496. const bool data = ud->height_above_terrain(
  497. data_5002,
  498. data_3);
  499. if (data) {
  500. lua_pushnumber(L, data_5002);
  501. } else {
  502. lua_pushnil(L);
  503. }
  504. return 1;
  505. }
  506. static int AP_Terrain_height_terrain_difference_home(lua_State *L) {
  507. AP_Terrain * ud = AP_Terrain::get_singleton();
  508. if (ud == nullptr) {
  509. return luaL_argerror(L, 1, "terrain not supported on this firmware");
  510. }
  511. binding_argcheck(L, 2);
  512. float data_5002 = {};
  513. const bool data_3 = static_cast<bool>(lua_toboolean(L, 3));
  514. const bool data = ud->height_terrain_difference_home(
  515. data_5002,
  516. data_3);
  517. if (data) {
  518. lua_pushnumber(L, data_5002);
  519. } else {
  520. lua_pushnil(L);
  521. }
  522. return 1;
  523. }
  524. static int AP_Terrain_height_amsl(lua_State *L) {
  525. AP_Terrain * ud = AP_Terrain::get_singleton();
  526. if (ud == nullptr) {
  527. return luaL_argerror(L, 1, "terrain not supported on this firmware");
  528. }
  529. binding_argcheck(L, 3);
  530. Location & data_2 = *check_Location(L, 2);
  531. float data_5003 = {};
  532. const bool data_4 = static_cast<bool>(lua_toboolean(L, 4));
  533. const bool data = ud->height_amsl(
  534. data_2,
  535. data_5003,
  536. data_4);
  537. if (data) {
  538. lua_pushnumber(L, data_5003);
  539. } else {
  540. lua_pushnil(L);
  541. }
  542. return 1;
  543. }
  544. static int AP_Terrain_status(lua_State *L) {
  545. AP_Terrain * ud = AP_Terrain::get_singleton();
  546. if (ud == nullptr) {
  547. return luaL_argerror(L, 1, "terrain not supported on this firmware");
  548. }
  549. binding_argcheck(L, 1);
  550. const uint8_t data = ud->status();
  551. lua_pushinteger(L, data);
  552. return 1;
  553. }
  554. static int AP_Terrain_enabled(lua_State *L) {
  555. AP_Terrain * ud = AP_Terrain::get_singleton();
  556. if (ud == nullptr) {
  557. return luaL_argerror(L, 1, "terrain not supported on this firmware");
  558. }
  559. binding_argcheck(L, 1);
  560. const bool data = ud->enabled();
  561. lua_pushboolean(L, data);
  562. return 1;
  563. }
  564. static int RangeFinder_num_sensors(lua_State *L) {
  565. RangeFinder * ud = RangeFinder::get_singleton();
  566. if (ud == nullptr) {
  567. return luaL_argerror(L, 1, "rangefinder not supported on this firmware");
  568. }
  569. binding_argcheck(L, 1);
  570. const uint8_t data = ud->num_sensors();
  571. lua_pushinteger(L, data);
  572. return 1;
  573. }
  574. static int AP_Notify_play_tune(lua_State *L) {
  575. AP_Notify * ud = AP_Notify::get_singleton();
  576. if (ud == nullptr) {
  577. return luaL_argerror(L, 1, "AP_Notify not supported on this firmware");
  578. }
  579. binding_argcheck(L, 2);
  580. const char * data_2 = luaL_checkstring(L, 2);
  581. ud->play_tune(
  582. data_2);
  583. return 0;
  584. }
  585. static int AP_GPS_first_unconfigured_gps(lua_State *L) {
  586. AP_GPS * ud = AP_GPS::get_singleton();
  587. if (ud == nullptr) {
  588. return luaL_argerror(L, 1, "gps not supported on this firmware");
  589. }
  590. binding_argcheck(L, 1);
  591. uint8_t data_5002 = {};
  592. const bool data = ud->first_unconfigured_gps(
  593. data_5002);
  594. if (data) {
  595. lua_pushinteger(L, data_5002);
  596. } else {
  597. lua_pushnil(L);
  598. }
  599. return 1;
  600. }
  601. static int AP_GPS_get_antenna_offset(lua_State *L) {
  602. AP_GPS * ud = AP_GPS::get_singleton();
  603. if (ud == nullptr) {
  604. return luaL_argerror(L, 1, "gps not supported on this firmware");
  605. }
  606. binding_argcheck(L, 2);
  607. const lua_Integer raw_data_2 = luaL_checkinteger(L, 2);
  608. luaL_argcheck(L, ((raw_data_2 >= MAX(0, 0)) && (raw_data_2 <= MIN(ud->num_sensors(), UINT8_MAX))), 2, "argument out of range");
  609. const uint8_t data_2 = static_cast<uint8_t>(raw_data_2);
  610. const Vector3f &data = ud->get_antenna_offset(
  611. data_2);
  612. new_Vector3f(L);
  613. *check_Vector3f(L, -1) = data;
  614. return 1;
  615. }
  616. static int AP_GPS_have_vertical_velocity(lua_State *L) {
  617. AP_GPS * ud = AP_GPS::get_singleton();
  618. if (ud == nullptr) {
  619. return luaL_argerror(L, 1, "gps not supported on this firmware");
  620. }
  621. binding_argcheck(L, 2);
  622. const lua_Integer raw_data_2 = luaL_checkinteger(L, 2);
  623. luaL_argcheck(L, ((raw_data_2 >= MAX(0, 0)) && (raw_data_2 <= MIN(ud->num_sensors(), UINT8_MAX))), 2, "argument out of range");
  624. const uint8_t data_2 = static_cast<uint8_t>(raw_data_2);
  625. const bool data = ud->have_vertical_velocity(
  626. data_2);
  627. lua_pushboolean(L, data);
  628. return 1;
  629. }
  630. static int AP_GPS_last_message_time_ms(lua_State *L) {
  631. AP_GPS * ud = AP_GPS::get_singleton();
  632. if (ud == nullptr) {
  633. return luaL_argerror(L, 1, "gps not supported on this firmware");
  634. }
  635. binding_argcheck(L, 2);
  636. const lua_Integer raw_data_2 = luaL_checkinteger(L, 2);
  637. luaL_argcheck(L, ((raw_data_2 >= MAX(0, 0)) && (raw_data_2 <= MIN(ud->num_sensors(), UINT8_MAX))), 2, "argument out of range");
  638. const uint8_t data_2 = static_cast<uint8_t>(raw_data_2);
  639. const uint32_t data = ud->last_message_time_ms(
  640. data_2);
  641. new_uint32_t(L);
  642. *static_cast<uint32_t *>(luaL_checkudata(L, -1, "uint32_t")) = data;
  643. return 1;
  644. }
  645. static int AP_GPS_last_fix_time_ms(lua_State *L) {
  646. AP_GPS * ud = AP_GPS::get_singleton();
  647. if (ud == nullptr) {
  648. return luaL_argerror(L, 1, "gps not supported on this firmware");
  649. }
  650. binding_argcheck(L, 2);
  651. const lua_Integer raw_data_2 = luaL_checkinteger(L, 2);
  652. luaL_argcheck(L, ((raw_data_2 >= MAX(0, 0)) && (raw_data_2 <= MIN(ud->num_sensors(), UINT8_MAX))), 2, "argument out of range");
  653. const uint8_t data_2 = static_cast<uint8_t>(raw_data_2);
  654. const uint32_t data = ud->last_fix_time_ms(
  655. data_2);
  656. new_uint32_t(L);
  657. *static_cast<uint32_t *>(luaL_checkudata(L, -1, "uint32_t")) = data;
  658. return 1;
  659. }
  660. static int AP_GPS_get_vdop(lua_State *L) {
  661. AP_GPS * ud = AP_GPS::get_singleton();
  662. if (ud == nullptr) {
  663. return luaL_argerror(L, 1, "gps not supported on this firmware");
  664. }
  665. binding_argcheck(L, 2);
  666. const lua_Integer raw_data_2 = luaL_checkinteger(L, 2);
  667. luaL_argcheck(L, ((raw_data_2 >= MAX(0, 0)) && (raw_data_2 <= MIN(ud->num_sensors(), UINT8_MAX))), 2, "argument out of range");
  668. const uint8_t data_2 = static_cast<uint8_t>(raw_data_2);
  669. const uint16_t data = ud->get_vdop(
  670. data_2);
  671. lua_pushinteger(L, data);
  672. return 1;
  673. }
  674. static int AP_GPS_get_hdop(lua_State *L) {
  675. AP_GPS * ud = AP_GPS::get_singleton();
  676. if (ud == nullptr) {
  677. return luaL_argerror(L, 1, "gps not supported on this firmware");
  678. }
  679. binding_argcheck(L, 2);
  680. const lua_Integer raw_data_2 = luaL_checkinteger(L, 2);
  681. luaL_argcheck(L, ((raw_data_2 >= MAX(0, 0)) && (raw_data_2 <= MIN(ud->num_sensors(), UINT8_MAX))), 2, "argument out of range");
  682. const uint8_t data_2 = static_cast<uint8_t>(raw_data_2);
  683. const uint16_t data = ud->get_hdop(
  684. data_2);
  685. lua_pushinteger(L, data);
  686. return 1;
  687. }
  688. static int AP_GPS_time_week_ms(lua_State *L) {
  689. AP_GPS * ud = AP_GPS::get_singleton();
  690. if (ud == nullptr) {
  691. return luaL_argerror(L, 1, "gps not supported on this firmware");
  692. }
  693. binding_argcheck(L, 2);
  694. const lua_Integer raw_data_2 = luaL_checkinteger(L, 2);
  695. luaL_argcheck(L, ((raw_data_2 >= MAX(0, 0)) && (raw_data_2 <= MIN(ud->num_sensors(), UINT8_MAX))), 2, "argument out of range");
  696. const uint8_t data_2 = static_cast<uint8_t>(raw_data_2);
  697. const uint32_t data = ud->time_week_ms(
  698. data_2);
  699. new_uint32_t(L);
  700. *static_cast<uint32_t *>(luaL_checkudata(L, -1, "uint32_t")) = data;
  701. return 1;
  702. }
  703. static int AP_GPS_time_week(lua_State *L) {
  704. AP_GPS * ud = AP_GPS::get_singleton();
  705. if (ud == nullptr) {
  706. return luaL_argerror(L, 1, "gps not supported on this firmware");
  707. }
  708. binding_argcheck(L, 2);
  709. const lua_Integer raw_data_2 = luaL_checkinteger(L, 2);
  710. luaL_argcheck(L, ((raw_data_2 >= MAX(0, 0)) && (raw_data_2 <= MIN(ud->num_sensors(), UINT8_MAX))), 2, "argument out of range");
  711. const uint8_t data_2 = static_cast<uint8_t>(raw_data_2);
  712. const uint16_t data = ud->time_week(
  713. data_2);
  714. lua_pushinteger(L, data);
  715. return 1;
  716. }
  717. static int AP_GPS_num_sats(lua_State *L) {
  718. AP_GPS * ud = AP_GPS::get_singleton();
  719. if (ud == nullptr) {
  720. return luaL_argerror(L, 1, "gps not supported on this firmware");
  721. }
  722. binding_argcheck(L, 2);
  723. const lua_Integer raw_data_2 = luaL_checkinteger(L, 2);
  724. luaL_argcheck(L, ((raw_data_2 >= MAX(0, 0)) && (raw_data_2 <= MIN(ud->num_sensors(), UINT8_MAX))), 2, "argument out of range");
  725. const uint8_t data_2 = static_cast<uint8_t>(raw_data_2);
  726. const uint8_t data = ud->num_sats(
  727. data_2);
  728. lua_pushinteger(L, data);
  729. return 1;
  730. }
  731. static int AP_GPS_ground_course(lua_State *L) {
  732. AP_GPS * ud = AP_GPS::get_singleton();
  733. if (ud == nullptr) {
  734. return luaL_argerror(L, 1, "gps not supported on this firmware");
  735. }
  736. binding_argcheck(L, 2);
  737. const lua_Integer raw_data_2 = luaL_checkinteger(L, 2);
  738. luaL_argcheck(L, ((raw_data_2 >= MAX(0, 0)) && (raw_data_2 <= MIN(ud->num_sensors(), UINT8_MAX))), 2, "argument out of range");
  739. const uint8_t data_2 = static_cast<uint8_t>(raw_data_2);
  740. const float data = ud->ground_course(
  741. data_2);
  742. lua_pushnumber(L, data);
  743. return 1;
  744. }
  745. static int AP_GPS_ground_speed(lua_State *L) {
  746. AP_GPS * ud = AP_GPS::get_singleton();
  747. if (ud == nullptr) {
  748. return luaL_argerror(L, 1, "gps not supported on this firmware");
  749. }
  750. binding_argcheck(L, 2);
  751. const lua_Integer raw_data_2 = luaL_checkinteger(L, 2);
  752. luaL_argcheck(L, ((raw_data_2 >= MAX(0, 0)) && (raw_data_2 <= MIN(ud->num_sensors(), UINT8_MAX))), 2, "argument out of range");
  753. const uint8_t data_2 = static_cast<uint8_t>(raw_data_2);
  754. const float data = ud->ground_speed(
  755. data_2);
  756. lua_pushnumber(L, data);
  757. return 1;
  758. }
  759. static int AP_GPS_velocity(lua_State *L) {
  760. AP_GPS * ud = AP_GPS::get_singleton();
  761. if (ud == nullptr) {
  762. return luaL_argerror(L, 1, "gps not supported on this firmware");
  763. }
  764. binding_argcheck(L, 2);
  765. const lua_Integer raw_data_2 = luaL_checkinteger(L, 2);
  766. luaL_argcheck(L, ((raw_data_2 >= MAX(0, 0)) && (raw_data_2 <= MIN(ud->num_sensors(), UINT8_MAX))), 2, "argument out of range");
  767. const uint8_t data_2 = static_cast<uint8_t>(raw_data_2);
  768. const Vector3f &data = ud->velocity(
  769. data_2);
  770. new_Vector3f(L);
  771. *check_Vector3f(L, -1) = data;
  772. return 1;
  773. }
  774. static int AP_GPS_vertical_accuracy(lua_State *L) {
  775. AP_GPS * ud = AP_GPS::get_singleton();
  776. if (ud == nullptr) {
  777. return luaL_argerror(L, 1, "gps not supported on this firmware");
  778. }
  779. binding_argcheck(L, 2);
  780. const lua_Integer raw_data_2 = luaL_checkinteger(L, 2);
  781. luaL_argcheck(L, ((raw_data_2 >= MAX(0, 0)) && (raw_data_2 <= MIN(ud->num_sensors(), UINT8_MAX))), 2, "argument out of range");
  782. const uint8_t data_2 = static_cast<uint8_t>(raw_data_2);
  783. float data_5003 = {};
  784. const bool data = ud->vertical_accuracy(
  785. data_2,
  786. data_5003);
  787. if (data) {
  788. lua_pushnumber(L, data_5003);
  789. } else {
  790. lua_pushnil(L);
  791. }
  792. return 1;
  793. }
  794. static int AP_GPS_horizontal_accuracy(lua_State *L) {
  795. AP_GPS * ud = AP_GPS::get_singleton();
  796. if (ud == nullptr) {
  797. return luaL_argerror(L, 1, "gps not supported on this firmware");
  798. }
  799. binding_argcheck(L, 2);
  800. const lua_Integer raw_data_2 = luaL_checkinteger(L, 2);
  801. luaL_argcheck(L, ((raw_data_2 >= MAX(0, 0)) && (raw_data_2 <= MIN(ud->num_sensors(), UINT8_MAX))), 2, "argument out of range");
  802. const uint8_t data_2 = static_cast<uint8_t>(raw_data_2);
  803. float data_5003 = {};
  804. const bool data = ud->horizontal_accuracy(
  805. data_2,
  806. data_5003);
  807. if (data) {
  808. lua_pushnumber(L, data_5003);
  809. } else {
  810. lua_pushnil(L);
  811. }
  812. return 1;
  813. }
  814. static int AP_GPS_speed_accuracy(lua_State *L) {
  815. AP_GPS * ud = AP_GPS::get_singleton();
  816. if (ud == nullptr) {
  817. return luaL_argerror(L, 1, "gps not supported on this firmware");
  818. }
  819. binding_argcheck(L, 2);
  820. const lua_Integer raw_data_2 = luaL_checkinteger(L, 2);
  821. luaL_argcheck(L, ((raw_data_2 >= MAX(0, 0)) && (raw_data_2 <= MIN(ud->num_sensors(), UINT8_MAX))), 2, "argument out of range");
  822. const uint8_t data_2 = static_cast<uint8_t>(raw_data_2);
  823. float data_5003 = {};
  824. const bool data = ud->speed_accuracy(
  825. data_2,
  826. data_5003);
  827. if (data) {
  828. lua_pushnumber(L, data_5003);
  829. } else {
  830. lua_pushnil(L);
  831. }
  832. return 1;
  833. }
  834. static int AP_GPS_location(lua_State *L) {
  835. AP_GPS * ud = AP_GPS::get_singleton();
  836. if (ud == nullptr) {
  837. return luaL_argerror(L, 1, "gps not supported on this firmware");
  838. }
  839. binding_argcheck(L, 2);
  840. const lua_Integer raw_data_2 = luaL_checkinteger(L, 2);
  841. luaL_argcheck(L, ((raw_data_2 >= MAX(0, 0)) && (raw_data_2 <= MIN(ud->num_sensors(), UINT8_MAX))), 2, "argument out of range");
  842. const uint8_t data_2 = static_cast<uint8_t>(raw_data_2);
  843. const Location &data = ud->location(
  844. data_2);
  845. new_Location(L);
  846. *check_Location(L, -1) = data;
  847. return 1;
  848. }
  849. static int AP_GPS_status(lua_State *L) {
  850. AP_GPS * ud = AP_GPS::get_singleton();
  851. if (ud == nullptr) {
  852. return luaL_argerror(L, 1, "gps not supported on this firmware");
  853. }
  854. binding_argcheck(L, 2);
  855. const lua_Integer raw_data_2 = luaL_checkinteger(L, 2);
  856. luaL_argcheck(L, ((raw_data_2 >= MAX(0, 0)) && (raw_data_2 <= MIN(ud->num_sensors(), UINT8_MAX))), 2, "argument out of range");
  857. const uint8_t data_2 = static_cast<uint8_t>(raw_data_2);
  858. const uint8_t data = ud->status(
  859. data_2);
  860. lua_pushinteger(L, data);
  861. return 1;
  862. }
  863. static int AP_GPS_primary_sensor(lua_State *L) {
  864. AP_GPS * ud = AP_GPS::get_singleton();
  865. if (ud == nullptr) {
  866. return luaL_argerror(L, 1, "gps not supported on this firmware");
  867. }
  868. binding_argcheck(L, 1);
  869. const uint8_t data = ud->primary_sensor();
  870. lua_pushinteger(L, data);
  871. return 1;
  872. }
  873. static int AP_GPS_num_sensors(lua_State *L) {
  874. AP_GPS * ud = AP_GPS::get_singleton();
  875. if (ud == nullptr) {
  876. return luaL_argerror(L, 1, "gps not supported on this firmware");
  877. }
  878. binding_argcheck(L, 1);
  879. const uint8_t data = ud->num_sensors();
  880. lua_pushinteger(L, data);
  881. return 1;
  882. }
  883. static int AP_BattMonitor_get_temperature(lua_State *L) {
  884. AP_BattMonitor * ud = AP_BattMonitor::get_singleton();
  885. if (ud == nullptr) {
  886. return luaL_argerror(L, 1, "battery not supported on this firmware");
  887. }
  888. binding_argcheck(L, 2);
  889. float data_5002 = {};
  890. const lua_Integer raw_data_3 = luaL_checkinteger(L, 3);
  891. luaL_argcheck(L, ((raw_data_3 >= MAX(0, 0)) && (raw_data_3 <= MIN(ud->num_instances(), UINT8_MAX))), 3, "argument out of range");
  892. const uint8_t data_3 = static_cast<uint8_t>(raw_data_3);
  893. const bool data = ud->get_temperature(
  894. data_5002,
  895. data_3);
  896. if (data) {
  897. lua_pushnumber(L, data_5002);
  898. } else {
  899. lua_pushnil(L);
  900. }
  901. return 1;
  902. }
  903. static int AP_BattMonitor_overpower_detected(lua_State *L) {
  904. AP_BattMonitor * ud = AP_BattMonitor::get_singleton();
  905. if (ud == nullptr) {
  906. return luaL_argerror(L, 1, "battery not supported on this firmware");
  907. }
  908. binding_argcheck(L, 2);
  909. const lua_Integer raw_data_2 = luaL_checkinteger(L, 2);
  910. luaL_argcheck(L, ((raw_data_2 >= MAX(0, 0)) && (raw_data_2 <= MIN(ud->num_instances(), UINT8_MAX))), 2, "argument out of range");
  911. const uint8_t data_2 = static_cast<uint8_t>(raw_data_2);
  912. const bool data = ud->overpower_detected(
  913. data_2);
  914. lua_pushboolean(L, data);
  915. return 1;
  916. }
  917. static int AP_BattMonitor_has_failsafed(lua_State *L) {
  918. AP_BattMonitor * ud = AP_BattMonitor::get_singleton();
  919. if (ud == nullptr) {
  920. return luaL_argerror(L, 1, "battery not supported on this firmware");
  921. }
  922. binding_argcheck(L, 1);
  923. const bool data = ud->has_failsafed();
  924. lua_pushboolean(L, data);
  925. return 1;
  926. }
  927. static int AP_BattMonitor_pack_capacity_mah(lua_State *L) {
  928. AP_BattMonitor * ud = AP_BattMonitor::get_singleton();
  929. if (ud == nullptr) {
  930. return luaL_argerror(L, 1, "battery not supported on this firmware");
  931. }
  932. binding_argcheck(L, 2);
  933. const lua_Integer raw_data_2 = luaL_checkinteger(L, 2);
  934. luaL_argcheck(L, ((raw_data_2 >= MAX(0, 0)) && (raw_data_2 <= MIN(ud->num_instances(), UINT8_MAX))), 2, "argument out of range");
  935. const uint8_t data_2 = static_cast<uint8_t>(raw_data_2);
  936. const int32_t data = ud->pack_capacity_mah(
  937. data_2);
  938. lua_pushinteger(L, data);
  939. return 1;
  940. }
  941. static int AP_BattMonitor_capacity_remaining_pct(lua_State *L) {
  942. AP_BattMonitor * ud = AP_BattMonitor::get_singleton();
  943. if (ud == nullptr) {
  944. return luaL_argerror(L, 1, "battery not supported on this firmware");
  945. }
  946. binding_argcheck(L, 2);
  947. const lua_Integer raw_data_2 = luaL_checkinteger(L, 2);
  948. luaL_argcheck(L, ((raw_data_2 >= MAX(0, 0)) && (raw_data_2 <= MIN(ud->num_instances(), UINT8_MAX))), 2, "argument out of range");
  949. const uint8_t data_2 = static_cast<uint8_t>(raw_data_2);
  950. const uint8_t data = ud->capacity_remaining_pct(
  951. data_2);
  952. lua_pushinteger(L, data);
  953. return 1;
  954. }
  955. static int AP_BattMonitor_consumed_wh(lua_State *L) {
  956. AP_BattMonitor * ud = AP_BattMonitor::get_singleton();
  957. if (ud == nullptr) {
  958. return luaL_argerror(L, 1, "battery not supported on this firmware");
  959. }
  960. binding_argcheck(L, 2);
  961. float data_5002 = {};
  962. const lua_Integer raw_data_3 = luaL_checkinteger(L, 3);
  963. luaL_argcheck(L, ((raw_data_3 >= MAX(0, 0)) && (raw_data_3 <= MIN(ud->num_instances(), UINT8_MAX))), 3, "argument out of range");
  964. const uint8_t data_3 = static_cast<uint8_t>(raw_data_3);
  965. const bool data = ud->consumed_wh(
  966. data_5002,
  967. data_3);
  968. if (data) {
  969. lua_pushnumber(L, data_5002);
  970. } else {
  971. lua_pushnil(L);
  972. }
  973. return 1;
  974. }
  975. static int AP_BattMonitor_consumed_mah(lua_State *L) {
  976. AP_BattMonitor * ud = AP_BattMonitor::get_singleton();
  977. if (ud == nullptr) {
  978. return luaL_argerror(L, 1, "battery not supported on this firmware");
  979. }
  980. binding_argcheck(L, 2);
  981. float data_5002 = {};
  982. const lua_Integer raw_data_3 = luaL_checkinteger(L, 3);
  983. luaL_argcheck(L, ((raw_data_3 >= MAX(0, 0)) && (raw_data_3 <= MIN(ud->num_instances(), UINT8_MAX))), 3, "argument out of range");
  984. const uint8_t data_3 = static_cast<uint8_t>(raw_data_3);
  985. const bool data = ud->consumed_mah(
  986. data_5002,
  987. data_3);
  988. if (data) {
  989. lua_pushnumber(L, data_5002);
  990. } else {
  991. lua_pushnil(L);
  992. }
  993. return 1;
  994. }
  995. static int AP_BattMonitor_current_amps(lua_State *L) {
  996. AP_BattMonitor * ud = AP_BattMonitor::get_singleton();
  997. if (ud == nullptr) {
  998. return luaL_argerror(L, 1, "battery not supported on this firmware");
  999. }
  1000. binding_argcheck(L, 2);
  1001. float data_5002 = {};
  1002. const lua_Integer raw_data_3 = luaL_checkinteger(L, 3);
  1003. luaL_argcheck(L, ((raw_data_3 >= MAX(0, 0)) && (raw_data_3 <= MIN(ud->num_instances(), UINT8_MAX))), 3, "argument out of range");
  1004. const uint8_t data_3 = static_cast<uint8_t>(raw_data_3);
  1005. const bool data = ud->current_amps(
  1006. data_5002,
  1007. data_3);
  1008. if (data) {
  1009. lua_pushnumber(L, data_5002);
  1010. } else {
  1011. lua_pushnil(L);
  1012. }
  1013. return 1;
  1014. }
  1015. static int AP_BattMonitor_voltage_resting_estimate(lua_State *L) {
  1016. AP_BattMonitor * ud = AP_BattMonitor::get_singleton();
  1017. if (ud == nullptr) {
  1018. return luaL_argerror(L, 1, "battery not supported on this firmware");
  1019. }
  1020. binding_argcheck(L, 2);
  1021. const lua_Integer raw_data_2 = luaL_checkinteger(L, 2);
  1022. luaL_argcheck(L, ((raw_data_2 >= MAX(0, 0)) && (raw_data_2 <= MIN(ud->num_instances(), UINT8_MAX))), 2, "argument out of range");
  1023. const uint8_t data_2 = static_cast<uint8_t>(raw_data_2);
  1024. const float data = ud->voltage_resting_estimate(
  1025. data_2);
  1026. lua_pushnumber(L, data);
  1027. return 1;
  1028. }
  1029. static int AP_BattMonitor_voltage(lua_State *L) {
  1030. AP_BattMonitor * ud = AP_BattMonitor::get_singleton();
  1031. if (ud == nullptr) {
  1032. return luaL_argerror(L, 1, "battery not supported on this firmware");
  1033. }
  1034. binding_argcheck(L, 2);
  1035. const lua_Integer raw_data_2 = luaL_checkinteger(L, 2);
  1036. luaL_argcheck(L, ((raw_data_2 >= MAX(0, 0)) && (raw_data_2 <= MIN(ud->num_instances(), UINT8_MAX))), 2, "argument out of range");
  1037. const uint8_t data_2 = static_cast<uint8_t>(raw_data_2);
  1038. const float data = ud->voltage(
  1039. data_2);
  1040. lua_pushnumber(L, data);
  1041. return 1;
  1042. }
  1043. static int AP_BattMonitor_healthy(lua_State *L) {
  1044. AP_BattMonitor * ud = AP_BattMonitor::get_singleton();
  1045. if (ud == nullptr) {
  1046. return luaL_argerror(L, 1, "battery not supported on this firmware");
  1047. }
  1048. binding_argcheck(L, 2);
  1049. const lua_Integer raw_data_2 = luaL_checkinteger(L, 2);
  1050. luaL_argcheck(L, ((raw_data_2 >= MAX(0, 0)) && (raw_data_2 <= MIN(ud->num_instances(), UINT8_MAX))), 2, "argument out of range");
  1051. const uint8_t data_2 = static_cast<uint8_t>(raw_data_2);
  1052. const bool data = ud->healthy(
  1053. data_2);
  1054. lua_pushboolean(L, data);
  1055. return 1;
  1056. }
  1057. static int AP_BattMonitor_num_instances(lua_State *L) {
  1058. AP_BattMonitor * ud = AP_BattMonitor::get_singleton();
  1059. if (ud == nullptr) {
  1060. return luaL_argerror(L, 1, "battery not supported on this firmware");
  1061. }
  1062. binding_argcheck(L, 1);
  1063. const uint8_t data = ud->num_instances();
  1064. lua_pushinteger(L, data);
  1065. return 1;
  1066. }
  1067. static int AP_Arming_arm(lua_State *L) {
  1068. AP_Arming * ud = AP_Arming::get_singleton();
  1069. if (ud == nullptr) {
  1070. return luaL_argerror(L, 1, "arming not supported on this firmware");
  1071. }
  1072. binding_argcheck(L, 1);
  1073. const bool data = ud->arm( AP_Arming::Method::SCRIPTING);
  1074. lua_pushboolean(L, data);
  1075. return 1;
  1076. }
  1077. static int AP_Arming_is_armed(lua_State *L) {
  1078. AP_Arming * ud = AP_Arming::get_singleton();
  1079. if (ud == nullptr) {
  1080. return luaL_argerror(L, 1, "arming not supported on this firmware");
  1081. }
  1082. binding_argcheck(L, 1);
  1083. const bool data = ud->is_armed();
  1084. lua_pushboolean(L, data);
  1085. return 1;
  1086. }
  1087. static int AP_Arming_disarm(lua_State *L) {
  1088. AP_Arming * ud = AP_Arming::get_singleton();
  1089. if (ud == nullptr) {
  1090. return luaL_argerror(L, 1, "arming not supported on this firmware");
  1091. }
  1092. binding_argcheck(L, 1);
  1093. const bool data = ud->disarm();
  1094. lua_pushboolean(L, data);
  1095. return 1;
  1096. }
  1097. static int AP_AHRS_prearm_healthy(lua_State *L) {
  1098. AP_AHRS * ud = AP_AHRS::get_singleton();
  1099. if (ud == nullptr) {
  1100. return luaL_argerror(L, 1, "ahrs not supported on this firmware");
  1101. }
  1102. binding_argcheck(L, 1);
  1103. ud->get_semaphore().take_blocking();
  1104. const bool data = ud->prearm_healthy();
  1105. ud->get_semaphore().give();
  1106. lua_pushboolean(L, data);
  1107. return 1;
  1108. }
  1109. static int AP_AHRS_home_is_set(lua_State *L) {
  1110. AP_AHRS * ud = AP_AHRS::get_singleton();
  1111. if (ud == nullptr) {
  1112. return luaL_argerror(L, 1, "ahrs not supported on this firmware");
  1113. }
  1114. binding_argcheck(L, 1);
  1115. ud->get_semaphore().take_blocking();
  1116. const bool data = ud->home_is_set();
  1117. ud->get_semaphore().give();
  1118. lua_pushboolean(L, data);
  1119. return 1;
  1120. }
  1121. static int AP_AHRS_get_relative_position_NED_home(lua_State *L) {
  1122. AP_AHRS * ud = AP_AHRS::get_singleton();
  1123. if (ud == nullptr) {
  1124. return luaL_argerror(L, 1, "ahrs not supported on this firmware");
  1125. }
  1126. binding_argcheck(L, 1);
  1127. Vector3f data_5002 = {};
  1128. ud->get_semaphore().take_blocking();
  1129. const bool data = ud->get_relative_position_NED_home(
  1130. data_5002);
  1131. ud->get_semaphore().give();
  1132. if (data) {
  1133. new_Vector3f(L);
  1134. *check_Vector3f(L, -1) = data_5002;
  1135. } else {
  1136. lua_pushnil(L);
  1137. }
  1138. return 1;
  1139. }
  1140. static int AP_AHRS_get_velocity_NED(lua_State *L) {
  1141. AP_AHRS * ud = AP_AHRS::get_singleton();
  1142. if (ud == nullptr) {
  1143. return luaL_argerror(L, 1, "ahrs not supported on this firmware");
  1144. }
  1145. binding_argcheck(L, 1);
  1146. Vector3f data_5002 = {};
  1147. ud->get_semaphore().take_blocking();
  1148. const bool data = ud->get_velocity_NED(
  1149. data_5002);
  1150. ud->get_semaphore().give();
  1151. if (data) {
  1152. new_Vector3f(L);
  1153. *check_Vector3f(L, -1) = data_5002;
  1154. } else {
  1155. lua_pushnil(L);
  1156. }
  1157. return 1;
  1158. }
  1159. static int AP_AHRS_groundspeed_vector(lua_State *L) {
  1160. AP_AHRS * ud = AP_AHRS::get_singleton();
  1161. if (ud == nullptr) {
  1162. return luaL_argerror(L, 1, "ahrs not supported on this firmware");
  1163. }
  1164. binding_argcheck(L, 1);
  1165. ud->get_semaphore().take_blocking();
  1166. const Vector2f &data = ud->groundspeed_vector();
  1167. ud->get_semaphore().give();
  1168. new_Vector2f(L);
  1169. *check_Vector2f(L, -1) = data;
  1170. return 1;
  1171. }
  1172. static int AP_AHRS_wind_estimate(lua_State *L) {
  1173. AP_AHRS * ud = AP_AHRS::get_singleton();
  1174. if (ud == nullptr) {
  1175. return luaL_argerror(L, 1, "ahrs not supported on this firmware");
  1176. }
  1177. binding_argcheck(L, 1);
  1178. ud->get_semaphore().take_blocking();
  1179. const Vector3f &data = ud->wind_estimate();
  1180. ud->get_semaphore().give();
  1181. new_Vector3f(L);
  1182. *check_Vector3f(L, -1) = data;
  1183. return 1;
  1184. }
  1185. static int AP_AHRS_get_hagl(lua_State *L) {
  1186. AP_AHRS * ud = AP_AHRS::get_singleton();
  1187. if (ud == nullptr) {
  1188. return luaL_argerror(L, 1, "ahrs not supported on this firmware");
  1189. }
  1190. binding_argcheck(L, 1);
  1191. float data_5002 = {};
  1192. ud->get_semaphore().take_blocking();
  1193. const bool data = ud->get_hagl(
  1194. data_5002);
  1195. ud->get_semaphore().give();
  1196. if (data) {
  1197. lua_pushnumber(L, data_5002);
  1198. } else {
  1199. lua_pushnil(L);
  1200. }
  1201. return 1;
  1202. }
  1203. static int AP_AHRS_get_gyro(lua_State *L) {
  1204. AP_AHRS * ud = AP_AHRS::get_singleton();
  1205. if (ud == nullptr) {
  1206. return luaL_argerror(L, 1, "ahrs not supported on this firmware");
  1207. }
  1208. binding_argcheck(L, 1);
  1209. ud->get_semaphore().take_blocking();
  1210. const Vector3f &data = ud->get_gyro();
  1211. ud->get_semaphore().give();
  1212. new_Vector3f(L);
  1213. *check_Vector3f(L, -1) = data;
  1214. return 1;
  1215. }
  1216. static int AP_AHRS_get_home(lua_State *L) {
  1217. AP_AHRS * ud = AP_AHRS::get_singleton();
  1218. if (ud == nullptr) {
  1219. return luaL_argerror(L, 1, "ahrs not supported on this firmware");
  1220. }
  1221. binding_argcheck(L, 1);
  1222. ud->get_semaphore().take_blocking();
  1223. const Location &data = ud->get_home();
  1224. ud->get_semaphore().give();
  1225. new_Location(L);
  1226. *check_Location(L, -1) = data;
  1227. return 1;
  1228. }
  1229. static int AP_AHRS_get_position(lua_State *L) {
  1230. AP_AHRS * ud = AP_AHRS::get_singleton();
  1231. if (ud == nullptr) {
  1232. return luaL_argerror(L, 1, "ahrs not supported on this firmware");
  1233. }
  1234. binding_argcheck(L, 1);
  1235. Location data_5002 = {};
  1236. ud->get_semaphore().take_blocking();
  1237. const bool data = ud->get_position(
  1238. data_5002);
  1239. ud->get_semaphore().give();
  1240. if (data) {
  1241. new_Location(L);
  1242. *check_Location(L, -1) = data_5002;
  1243. } else {
  1244. lua_pushnil(L);
  1245. }
  1246. return 1;
  1247. }
  1248. static int AP_AHRS_get_yaw(lua_State *L) {
  1249. AP_AHRS * ud = AP_AHRS::get_singleton();
  1250. if (ud == nullptr) {
  1251. return luaL_argerror(L, 1, "ahrs not supported on this firmware");
  1252. }
  1253. binding_argcheck(L, 1);
  1254. ud->get_semaphore().take_blocking();
  1255. const float data = ud->get_yaw();
  1256. ud->get_semaphore().give();
  1257. lua_pushnumber(L, data);
  1258. return 1;
  1259. }
  1260. static int AP_AHRS_get_pitch(lua_State *L) {
  1261. AP_AHRS * ud = AP_AHRS::get_singleton();
  1262. if (ud == nullptr) {
  1263. return luaL_argerror(L, 1, "ahrs not supported on this firmware");
  1264. }
  1265. binding_argcheck(L, 1);
  1266. ud->get_semaphore().take_blocking();
  1267. const float data = ud->get_pitch();
  1268. ud->get_semaphore().give();
  1269. lua_pushnumber(L, data);
  1270. return 1;
  1271. }
  1272. static int AP_AHRS_get_roll(lua_State *L) {
  1273. AP_AHRS * ud = AP_AHRS::get_singleton();
  1274. if (ud == nullptr) {
  1275. return luaL_argerror(L, 1, "ahrs not supported on this firmware");
  1276. }
  1277. binding_argcheck(L, 1);
  1278. ud->get_semaphore().take_blocking();
  1279. const float data = ud->get_roll();
  1280. ud->get_semaphore().give();
  1281. lua_pushnumber(L, data);
  1282. return 1;
  1283. }
  1284. const luaL_Reg GCS_meta[] = {
  1285. {"send_text", GCS_send_text},
  1286. {NULL, NULL}
  1287. };
  1288. const luaL_Reg AP_Relay_meta[] = {
  1289. {"toggle", AP_Relay_toggle},
  1290. {"enabled", AP_Relay_enabled},
  1291. {"off", AP_Relay_off},
  1292. {"on", AP_Relay_on},
  1293. {NULL, NULL}
  1294. };
  1295. const luaL_Reg AP_Terrain_meta[] = {
  1296. {"height_above_terrain", AP_Terrain_height_above_terrain},
  1297. {"height_terrain_difference_home", AP_Terrain_height_terrain_difference_home},
  1298. {"height_amsl", AP_Terrain_height_amsl},
  1299. {"status", AP_Terrain_status},
  1300. {"enabled", AP_Terrain_enabled},
  1301. {NULL, NULL}
  1302. };
  1303. const luaL_Reg RangeFinder_meta[] = {
  1304. {"num_sensors", RangeFinder_num_sensors},
  1305. {NULL, NULL}
  1306. };
  1307. const luaL_Reg AP_Notify_meta[] = {
  1308. {"play_tune", AP_Notify_play_tune},
  1309. {NULL, NULL}
  1310. };
  1311. const luaL_Reg notify_meta[] = {
  1312. {NULL, NULL}
  1313. };
  1314. const luaL_Reg AP_GPS_meta[] = {
  1315. {"first_unconfigured_gps", AP_GPS_first_unconfigured_gps},
  1316. {"get_antenna_offset", AP_GPS_get_antenna_offset},
  1317. {"have_vertical_velocity", AP_GPS_have_vertical_velocity},
  1318. {"last_message_time_ms", AP_GPS_last_message_time_ms},
  1319. {"last_fix_time_ms", AP_GPS_last_fix_time_ms},
  1320. {"get_vdop", AP_GPS_get_vdop},
  1321. {"get_hdop", AP_GPS_get_hdop},
  1322. {"time_week_ms", AP_GPS_time_week_ms},
  1323. {"time_week", AP_GPS_time_week},
  1324. {"num_sats", AP_GPS_num_sats},
  1325. {"ground_course", AP_GPS_ground_course},
  1326. {"ground_speed", AP_GPS_ground_speed},
  1327. {"velocity", AP_GPS_velocity},
  1328. {"vertical_accuracy", AP_GPS_vertical_accuracy},
  1329. {"horizontal_accuracy", AP_GPS_horizontal_accuracy},
  1330. {"speed_accuracy", AP_GPS_speed_accuracy},
  1331. {"location", AP_GPS_location},
  1332. {"status", AP_GPS_status},
  1333. {"primary_sensor", AP_GPS_primary_sensor},
  1334. {"num_sensors", AP_GPS_num_sensors},
  1335. {NULL, NULL}
  1336. };
  1337. const luaL_Reg AP_BattMonitor_meta[] = {
  1338. {"get_temperature", AP_BattMonitor_get_temperature},
  1339. {"overpower_detected", AP_BattMonitor_overpower_detected},
  1340. {"has_failsafed", AP_BattMonitor_has_failsafed},
  1341. {"pack_capacity_mah", AP_BattMonitor_pack_capacity_mah},
  1342. {"capacity_remaining_pct", AP_BattMonitor_capacity_remaining_pct},
  1343. {"consumed_wh", AP_BattMonitor_consumed_wh},
  1344. {"consumed_mah", AP_BattMonitor_consumed_mah},
  1345. {"current_amps", AP_BattMonitor_current_amps},
  1346. {"voltage_resting_estimate", AP_BattMonitor_voltage_resting_estimate},
  1347. {"voltage", AP_BattMonitor_voltage},
  1348. {"healthy", AP_BattMonitor_healthy},
  1349. {"num_instances", AP_BattMonitor_num_instances},
  1350. {NULL, NULL}
  1351. };
  1352. const luaL_Reg AP_Arming_meta[] = {
  1353. {"arm", AP_Arming_arm},
  1354. {"is_armed", AP_Arming_is_armed},
  1355. {"disarm", AP_Arming_disarm},
  1356. {NULL, NULL}
  1357. };
  1358. const luaL_Reg AP_AHRS_meta[] = {
  1359. {"prearm_healthy", AP_AHRS_prearm_healthy},
  1360. {"home_is_set", AP_AHRS_home_is_set},
  1361. {"get_relative_position_NED_home", AP_AHRS_get_relative_position_NED_home},
  1362. {"get_velocity_NED", AP_AHRS_get_velocity_NED},
  1363. {"groundspeed_vector", AP_AHRS_groundspeed_vector},
  1364. {"wind_estimate", AP_AHRS_wind_estimate},
  1365. {"get_hagl", AP_AHRS_get_hagl},
  1366. {"get_gyro", AP_AHRS_get_gyro},
  1367. {"get_home", AP_AHRS_get_home},
  1368. {"get_position", AP_AHRS_get_position},
  1369. {"get_yaw", AP_AHRS_get_yaw},
  1370. {"get_pitch", AP_AHRS_get_pitch},
  1371. {"get_roll", AP_AHRS_get_roll},
  1372. {NULL, NULL}
  1373. };
  1374. struct userdata_enum {
  1375. const char *name;
  1376. int value;
  1377. };
  1378. struct userdata_enum AP_Terrain_enums[] = {
  1379. {"TerrainStatusOK", AP_Terrain::TerrainStatusOK},
  1380. {"TerrainStatusUnhealthy", AP_Terrain::TerrainStatusUnhealthy},
  1381. {"TerrainStatusDisabled", AP_Terrain::TerrainStatusDisabled},
  1382. {NULL, 0}};
  1383. struct userdata_enum AP_GPS_enums[] = {
  1384. {"GPS_OK_FIX_3D_RTK_FIXED", AP_GPS::GPS_OK_FIX_3D_RTK_FIXED},
  1385. {"GPS_OK_FIX_3D_RTK_FLOAT", AP_GPS::GPS_OK_FIX_3D_RTK_FLOAT},
  1386. {"GPS_OK_FIX_3D_DGPS", AP_GPS::GPS_OK_FIX_3D_DGPS},
  1387. {"GPS_OK_FIX_3D", AP_GPS::GPS_OK_FIX_3D},
  1388. {"GPS_OK_FIX_2D", AP_GPS::GPS_OK_FIX_2D},
  1389. {"NO_FIX", AP_GPS::NO_FIX},
  1390. {"NO_GPS", AP_GPS::NO_GPS},
  1391. {NULL, 0}};
  1392. struct userdata_meta {
  1393. const char *name;
  1394. const luaL_Reg *reg;
  1395. const struct userdata_enum *enums;
  1396. };
  1397. const struct userdata_meta userdata_fun[] = {
  1398. {"Vector2f", Vector2f_meta, NULL},
  1399. {"Vector3f", Vector3f_meta, NULL},
  1400. {"Location", Location_meta, NULL},
  1401. };
  1402. const struct userdata_meta singleton_fun[] = {
  1403. {"gcs", GCS_meta, NULL},
  1404. {"relay", AP_Relay_meta, NULL},
  1405. {"terrain", AP_Terrain_meta, AP_Terrain_enums},
  1406. {"rangefinder", RangeFinder_meta, NULL},
  1407. {"AP_Notify", AP_Notify_meta, NULL},
  1408. {"notify", notify_meta, NULL},
  1409. {"gps", AP_GPS_meta, AP_GPS_enums},
  1410. {"battery", AP_BattMonitor_meta, NULL},
  1411. {"arming", AP_Arming_meta, NULL},
  1412. {"ahrs", AP_AHRS_meta, NULL},
  1413. };
  1414. void load_generated_bindings(lua_State *L) {
  1415. luaL_checkstack(L, 5, "Out of stack");
  1416. // userdata metatables
  1417. for (uint32_t i = 0; i < ARRAY_SIZE(userdata_fun); i++) {
  1418. luaL_newmetatable(L, userdata_fun[i].name);
  1419. luaL_setfuncs(L, userdata_fun[i].reg, 0);
  1420. lua_pushstring(L, "__index");
  1421. lua_pushvalue(L, -2);
  1422. lua_settable(L, -3);
  1423. lua_pop(L, 1);
  1424. }
  1425. // singleton metatables
  1426. for (uint32_t i = 0; i < ARRAY_SIZE(singleton_fun); i++) {
  1427. luaL_newmetatable(L, singleton_fun[i].name);
  1428. luaL_setfuncs(L, singleton_fun[i].reg, 0);
  1429. lua_pushstring(L, "__index");
  1430. lua_pushvalue(L, -2);
  1431. lua_settable(L, -3);
  1432. if (singleton_fun[i].enums != nullptr) {
  1433. int j = 0;
  1434. while (singleton_fun[i].enums[j].name != NULL) {
  1435. lua_pushstring(L, singleton_fun[i].enums[j].name);
  1436. lua_pushinteger(L, singleton_fun[i].enums[j].value);
  1437. lua_settable(L, -3);
  1438. j++;
  1439. }
  1440. }
  1441. lua_pop(L, 1);
  1442. lua_newuserdata(L, 0);
  1443. luaL_getmetatable(L, singleton_fun[i].name);
  1444. lua_setmetatable(L, -2);
  1445. lua_setglobal(L, singleton_fun[i].name);
  1446. }
  1447. load_boxed_numerics(L);
  1448. }
  1449. const char *singletons[] = {
  1450. "gcs",
  1451. "relay",
  1452. "terrain",
  1453. "rangefinder",
  1454. "AP_Notify",
  1455. "notify",
  1456. "gps",
  1457. "battery",
  1458. "arming",
  1459. "ahrs",
  1460. };
  1461. const struct userdata {
  1462. const char *name;
  1463. const lua_CFunction fun;
  1464. } new_userdata[] = {
  1465. {"Vector2f", new_Vector2f},
  1466. {"Vector3f", new_Vector3f},
  1467. {"Location", new_Location},
  1468. };
  1469. void load_generated_sandbox(lua_State *L) {
  1470. for (uint32_t i = 0; i < ARRAY_SIZE(singletons); i++) {
  1471. lua_pushstring(L, singletons[i]);
  1472. lua_getglobal(L, singletons[i]);
  1473. lua_settable(L, -3);
  1474. }
  1475. for (uint32_t i = 0; i < ARRAY_SIZE(new_userdata); i++) {
  1476. lua_pushstring(L, new_userdata[i].name);
  1477. lua_pushcfunction(L, new_userdata[i].fun);
  1478. lua_settable(L, -3);
  1479. }
  1480. load_boxed_numerics_sandbox(L);
  1481. }