AP_Scripting: load manual bindings via generator

This commit is contained in:
Iampete1 authored and Andrew Tridgell committed 2022-05-04 17:49:14 +10:00
1 parent 03476711f2
commit 9da80b45e9
5 files changed
+28 -53

No files matched your search

+6 -49
View File
@@ -1,5 +1,4 @@
#include <AP_Common/AP_Common.h>
#include <SRV_Channel/SRV_Channel.h>
#include <AP_HAL/HAL.h>
#include <AP_Logger/AP_Logger.h>
@@ -29,7 +28,7 @@ int check_arguments(lua_State *L, int expected_arguments, const char *fn_name) {
}
// millis
static int lua_millis(lua_State *L) {
int lua_millis(lua_State *L) {
check_arguments(L, 0, "millis");
new_uint32_t(L);
@@ -39,7 +38,7 @@ static int lua_millis(lua_State *L) {
}
// micros
static int lua_micros(lua_State *L) {
int lua_micros(lua_State *L) {
check_arguments(L, 0, "micros");
new_uint32_t(L);
@@ -48,7 +47,7 @@ static int lua_micros(lua_State *L) {
return 1;
}
static int lua_mission_receive(lua_State *L) {
int lua_mission_receive(lua_State *L) {
check_arguments(L, 0, "mission_receive");
ObjectBuffer<struct AP_Scripting::scripting_mission_cmd> *input = AP::scripting()->mission_data;
@@ -76,15 +75,7 @@ static int lua_mission_receive(lua_State *L) {
return 5;
}
static const luaL_Reg global_functions[] =
{
{"millis", lua_millis},
{"micros", lua_micros},
{"mission_receive", lua_mission_receive},
{NULL, NULL}
};
static int AP_Logger_Write(lua_State *L) {
int AP_Logger_Write(lua_State *L) {
AP_Logger * AP_logger = AP_Logger::get_singleton();
if (AP_logger == nullptr) {
return luaL_argerror(L, 1, "logger not supported on this firmware");
@@ -283,12 +274,7 @@ static int AP_Logger_Write(lua_State *L) {
return 0;
}
const luaL_Reg AP_Logger_functions[] = {
{"write", AP_Logger_Write},
{NULL, NULL}
};
static int lua_get_i2c_device(lua_State *L) {
int lua_get_i2c_device(lua_State *L) {
const int args = lua_gettop(L);
if (args < 2) {
@@ -342,13 +328,8 @@ static int lua_get_i2c_device(lua_State *L) {
return 1;
}
const luaL_Reg i2c_functions[] = {
{"get_device", lua_get_i2c_device},
{NULL, NULL}
};
#if HAL_MAX_CAN_PROTOCOL_DRIVERS
static int lua_get_CAN_device(lua_State *L) {
int lua_get_CAN_device(lua_State *L) {
check_arguments(L, 1, "CAN:get_device");
@@ -368,28 +349,4 @@ static int lua_get_CAN_device(lua_State *L) {
return 1;
}
const luaL_Reg CAN_functions[] = {
{"get_device", lua_get_CAN_device},
{NULL, NULL}
};
#endif // HAL_MAX_CAN_PROTOCOL_DRIVERS
void load_lua_bindings(lua_State *L) {
lua_pushstring(L, "logger");
luaL_newlib(L, AP_Logger_functions);
lua_settable(L, -3);
lua_pushstring(L, "i2c");
luaL_newlib(L, i2c_functions);
lua_settable(L, -3);
#if HAL_MAX_CAN_PROTOCOL_DRIVERS
lua_pushstring(L, "CAN");
luaL_newlib(L, CAN_functions);
lua_settable(L, -3);
#endif
luaL_setfuncs(L, global_functions, 0);
}