AP_Scripting: Nullable primitive arguments do not recieve a range check
This commit is contained in:
parent
893779fbcd
commit
6bcc6d85e7
@ -18,12 +18,72 @@ include AP_AHRS/AP_AHRS.h
|
||||
singleton AP_AHRS alias ahrs
|
||||
singleton AP_AHRS method get_position boolean Location'Null
|
||||
singleton AP_AHRS method get_home Location
|
||||
singleton AP_AHRS method get_gyro Vector3f
|
||||
singleton AP_AHRS method get_hagl boolean float'Null
|
||||
singleton AP_AHRS method wind_estimate Vector3f
|
||||
singleton AP_AHRS method groundspeed_vector Vector2f
|
||||
singleton AP_AHRS method get_velocity_NED boolean Vector3f'Null
|
||||
singleton AP_AHRS method get_relative_position_NED_home boolean Vector3f'Null
|
||||
singleton AP_AHRS method home_is_set boolean
|
||||
singleton AP_AHRS method prearm_healthy boolean
|
||||
|
||||
include AP_BattMonitor/AP_BattMonitor.h
|
||||
|
||||
singleton AP_BattMonitor alias battery
|
||||
singleton AP_BattMonitor method num_instances uint8_t
|
||||
singleton AP_BattMonitor method healthy boolean uint8_t 0 AP_BATT_MONITOR_MAX_INSTANCES
|
||||
singleton AP_BattMonitor method has_consumed_energy boolean uint8_t 0 AP_BATT_MONITOR_MAX_INSTANCES
|
||||
singleton AP_BattMonitor method has_current boolean uint8_t 0 AP_BATT_MONITOR_MAX_INSTANCES
|
||||
singleton AP_BattMonitor method voltage float uint8_t 0 AP_BATT_MONITOR_MAX_INSTANCES
|
||||
singleton AP_BattMonitor method voltage_resting_estimate float uint8_t 0 AP_BATT_MONITOR_MAX_INSTANCES
|
||||
singleton AP_BattMonitor method current_amps float uint8_t 0 AP_BATT_MONITOR_MAX_INSTANCES
|
||||
singleton AP_BattMonitor method consumed_mah float uint8_t 0 AP_BATT_MONITOR_MAX_INSTANCES
|
||||
singleton AP_BattMonitor method consumed_wh float uint8_t 0 AP_BATT_MONITOR_MAX_INSTANCES
|
||||
singleton AP_BattMonitor method capacity_remaining_pct uint8_t uint8_t 0 AP_BATT_MONITOR_MAX_INSTANCES
|
||||
singleton AP_BattMonitor method pack_capacity_mah int32_t uint8_t 0 AP_BATT_MONITOR_MAX_INSTANCES
|
||||
singleton AP_BattMonitor method has_failsafed boolean
|
||||
singleton AP_BattMonitor method overpower_detected boolean uint8_t 0 AP_BATT_MONITOR_MAX_INSTANCES
|
||||
singleton AP_BattMonitor method get_temperature boolean float'Null uint8_t 0 AP_BATT_MONITOR_MAX_INSTANCES
|
||||
|
||||
include AP_GPS/AP_GPS.h
|
||||
|
||||
singleton AP_GPS alias gps
|
||||
singleton AP_GPS method num_sensors uint8_t
|
||||
singleton AP_GPS method primary_sensor uint8_t
|
||||
singleton AP_GPS method status uint8_t uint8_t 0 GPS_MAX_INSTANCES
|
||||
singleton AP_GPS method location Location uint8_t 0 GPS_MAX_INSTANCES
|
||||
singleton AP_GPS method speed_accuracy boolean uint8_t 0 GPS_MAX_INSTANCES float'Null
|
||||
singleton AP_GPS method horizontal_accuracy boolean uint8_t 0 GPS_MAX_INSTANCES float'Null
|
||||
singleton AP_GPS method vertical_accuracy boolean uint8_t 0 GPS_MAX_INSTANCES float'Null
|
||||
singleton AP_GPS method velocity Vector3f uint8_t 0 GPS_MAX_INSTANCES
|
||||
singleton AP_GPS method ground_speed float uint8_t 0 GPS_MAX_INSTANCES
|
||||
singleton AP_GPS method ground_course float uint8_t 0 GPS_MAX_INSTANCES
|
||||
singleton AP_GPS method num_sats uint8_t uint8_t 0 GPS_MAX_INSTANCES
|
||||
singleton AP_GPS method get_hdop uint16_t uint8_t 0 GPS_MAX_INSTANCES
|
||||
singleton AP_GPS method get_vdop uint16_t uint8_t 0 GPS_MAX_INSTANCES
|
||||
singleton AP_GPS method have_vertical_velocity boolean uint8_t 0 GPS_MAX_INSTANCES
|
||||
singleton AP_GPS method get_antenna_offset Vector3f uint8_t 0 GPS_MAX_INSTANCES
|
||||
singleton AP_GPS method all_configured boolean
|
||||
singleton AP_GPS method first_unconfigured_gps uint8_t
|
||||
|
||||
include AP_Math/AP_Math.h
|
||||
|
||||
userdata Vector3f field x float read write -FLT_MAX FLT_MAX
|
||||
userdata Vector3f field y float read write -FLT_MAX FLT_MAX
|
||||
userdata Vector3f field z float read write -FLT_MAX FLT_MAX
|
||||
userdata Vector3f method length float
|
||||
userdata Vector3f method normalize void
|
||||
userdata Vector3f method is_nan void
|
||||
userdata Vector3f method is_inf void
|
||||
userdata Vector3f method is_zero void
|
||||
|
||||
userdata Vector2f field x float read write -FLT_MAX FLT_MAX
|
||||
userdata Vector2f field y float read write -FLT_MAX FLT_MAX
|
||||
userdata Vector2f method length float
|
||||
userdata Vector2f method normalize void
|
||||
userdata Vector2f method is_nan void
|
||||
userdata Vector2f method is_inf void
|
||||
userdata Vector2f method is_zero void
|
||||
|
||||
include AP_Notify/AP_Notify.h
|
||||
singleton notify alias notify
|
||||
|
@ -74,7 +74,7 @@ enum access_flags {
|
||||
};
|
||||
|
||||
enum field_type {
|
||||
TYPE_BOOLEAN,
|
||||
TYPE_BOOLEAN = 0,
|
||||
TYPE_FLOAT,
|
||||
TYPE_INT8_T,
|
||||
TYPE_INT16_T,
|
||||
@ -86,6 +86,18 @@ enum field_type {
|
||||
TYPE_USERDATA,
|
||||
};
|
||||
|
||||
const char * type_labels[TYPE_USERDATA + 1] = { "bool",
|
||||
"float",
|
||||
"int8_t",
|
||||
"int16_t",
|
||||
"int32_t",
|
||||
"uint8_t",
|
||||
"uint16_t",
|
||||
"void",
|
||||
"string",
|
||||
"userdata",
|
||||
};
|
||||
|
||||
enum access_type {
|
||||
ACCESS_VALUE = 0,
|
||||
ACCESS_REFERENCE,
|
||||
@ -234,6 +246,8 @@ enum userdata_type {
|
||||
struct argument {
|
||||
struct argument * next;
|
||||
struct type type;
|
||||
int line_num; // line read from
|
||||
int token_num; // token number on the line
|
||||
};
|
||||
|
||||
struct method {
|
||||
@ -427,7 +441,8 @@ int parse_type(struct type *type, const uint32_t restrictions, enum range_check_
|
||||
}
|
||||
}
|
||||
|
||||
if (range_type != RANGE_CHECK_NONE) {
|
||||
// add range checks, unless disabled or a nullable type
|
||||
if (range_type != RANGE_CHECK_NONE && !(type->flags & TYPE_FLAGS_NULLABLE)) {
|
||||
switch (type->type) {
|
||||
case TYPE_FLOAT:
|
||||
case TYPE_INT8_T:
|
||||
@ -516,8 +531,20 @@ void handle_method(enum trace_level traceType, char *parent_name, struct method
|
||||
}
|
||||
struct argument * arg = allocate(sizeof(struct argument));
|
||||
memcpy(&(arg->type), &arg_type, sizeof(struct type));
|
||||
arg->next = method->arguments;
|
||||
method->arguments = arg;
|
||||
arg->line_num = state.line_num;
|
||||
arg->token_num = state.token_num;
|
||||
if (method->arguments == NULL) {
|
||||
method->arguments = arg;
|
||||
} else {
|
||||
struct argument *tail = method->arguments;
|
||||
while (tail->next != NULL) {
|
||||
tail = tail->next;
|
||||
}
|
||||
tail->next = arg;
|
||||
}
|
||||
|
||||
// reset the stack arg_type
|
||||
memset(&arg_type, 0, sizeof(struct type));
|
||||
}
|
||||
}
|
||||
|
||||
@ -738,11 +765,11 @@ void emit_checker(const struct type t, int arg_number, const char *indentation,
|
||||
forced_max = "INT32_MAX";
|
||||
break;
|
||||
case TYPE_UINT8_T:
|
||||
forced_min = "UINT8_MIN";
|
||||
forced_min = "0";
|
||||
forced_max = "UINT8_MAX";
|
||||
break;
|
||||
case TYPE_UINT16_T:
|
||||
forced_min = "UINT16_MIN";
|
||||
forced_min = "0";
|
||||
forced_max = "UINT16_MAX";
|
||||
break;
|
||||
case TYPE_NONE:
|
||||
@ -823,7 +850,7 @@ void emit_checker(const struct type t, int arg_number, const char *indentation,
|
||||
}
|
||||
|
||||
void emit_userdata_field(const struct userdata *data, const struct userdata_field *field) {
|
||||
fprintf(source, "int %s_%s(lua_State *L) {\n", data->name, field->name);
|
||||
fprintf(source, "static int %s_%s(lua_State *L) {\n", data->name, field->name);
|
||||
fprintf(source, " %s *ud = check_%s(L, 1);\n", data->name, data->name);
|
||||
fprintf(source, " switch(lua_gettop(L)) {\n");
|
||||
|
||||
@ -884,18 +911,26 @@ void emit_userdata_fields() {
|
||||
|
||||
void emit_userdata_method(const struct userdata *data, const struct method *method) {
|
||||
int arg_count = 1;
|
||||
|
||||
const char *access_name = data->alias ? data->alias : data->name;
|
||||
|
||||
fprintf(source, "static int %s_%s(lua_State *L) {\n", data->name, method->name);
|
||||
// emit comments on expected arg/type
|
||||
struct argument *arg = method->arguments;
|
||||
while (arg != NULL) {
|
||||
fprintf(source, " // %d %s %d : %d\n", arg_count++, arg->type.type == TYPE_USERDATA ? arg->type.data.userdata_name : type_labels[arg->type.type],
|
||||
arg->line_num, arg->token_num);
|
||||
arg = arg->next;
|
||||
}
|
||||
// sanity check number of args called with
|
||||
fprintf(source, " const int args = lua_gettop(L);\n");
|
||||
arg = method->arguments;
|
||||
while (arg != NULL) {
|
||||
if (!(arg->type.flags & TYPE_FLAGS_NULLABLE)) {
|
||||
arg_count++;
|
||||
}
|
||||
arg = arg->next;
|
||||
}
|
||||
|
||||
const char *access_name = data->alias ? data->alias : data->name;
|
||||
|
||||
fprintf(source, "int %s_%s(lua_State *L) {\n", data->name, method->name);
|
||||
fprintf(source, " const int args = lua_gettop(L);\n");
|
||||
fprintf(source, " if (args > %d) {\n", arg_count);
|
||||
fprintf(source, " return luaL_argerror(L, args, \"too many arguments\");\n");
|
||||
fprintf(source, " } else if (args < %d) {\n", arg_count);
|
||||
@ -950,7 +985,7 @@ void emit_userdata_method(const struct userdata *data, const struct method *meth
|
||||
fprintf(source, " const uint8_t data = ud->%s(\n", method->name);
|
||||
break;
|
||||
case TYPE_UINT16_T:
|
||||
fprintf(source, " const uint6_t data = ud->%s(\n", method->name);
|
||||
fprintf(source, " const uint16_t data = ud->%s(\n", method->name);
|
||||
break;
|
||||
case TYPE_USERDATA:
|
||||
fprintf(source, " const %s &data = ud->%s(\n", method->return_type.data.userdata_name, method->name);
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -3,11 +3,14 @@
|
||||
#include <AP_RangeFinder/AP_RangeFinder.h>
|
||||
#include <AP_Notify/AP_Notify.h>
|
||||
#include <AP_Math/AP_Math.h>
|
||||
#include <AP_GPS/AP_GPS.h>
|
||||
#include <AP_AHRS/AP_AHRS.h>
|
||||
#include <AP_Common/Location.h>
|
||||
#include "lua/src/lua.hpp"
|
||||
#include <new>
|
||||
|
||||
int new_Vector2f(lua_State *L);
|
||||
Vector2f * check_Vector2f(lua_State *L, int arg);
|
||||
int new_Vector3f(lua_State *L);
|
||||
Vector3f * check_Vector3f(lua_State *L, int arg);
|
||||
int new_Location(lua_State *L);
|
||||
|
Loading…
Reference in New Issue
Block a user