mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-02-08 17:03:57 -04:00
AP_Scripting: binding gen: add number of argument to manual functions and generate docs for manual
This commit is contained in:
parent
a1607b954c
commit
48ce8c4e16
@ -347,7 +347,7 @@ singleton AP_Param method add_table boolean uint8_t 0 200 string uint8_t 1 63
|
|||||||
singleton AP_Param method add_param boolean uint8_t 0 200 uint8_t 1 63 string float'skip_check
|
singleton AP_Param method add_param boolean uint8_t 0 200 uint8_t 1 63 string float'skip_check
|
||||||
|
|
||||||
include AP_Scripting/AP_Scripting_helpers.h
|
include AP_Scripting/AP_Scripting_helpers.h
|
||||||
userdata Parameter creation lua_new_Parameter
|
userdata Parameter creation lua_new_Parameter 1
|
||||||
userdata Parameter method init boolean string
|
userdata Parameter method init boolean string
|
||||||
userdata Parameter method init_by_info boolean uint16_t 0 UINT16_MAX uint32_t'skip_check ap_var_type'enum AP_PARAM_INT8 AP_PARAM_FLOAT
|
userdata Parameter method init_by_info boolean uint16_t 0 UINT16_MAX uint32_t'skip_check ap_var_type'enum AP_PARAM_INT8 AP_PARAM_FLOAT
|
||||||
userdata Parameter method get boolean float'Null
|
userdata Parameter method get boolean float'Null
|
||||||
@ -438,7 +438,7 @@ include AP_HAL/I2CDevice.h
|
|||||||
ap_object AP_HAL::I2CDevice semaphore-pointer
|
ap_object AP_HAL::I2CDevice semaphore-pointer
|
||||||
ap_object AP_HAL::I2CDevice method set_retries void uint8_t 0 20
|
ap_object AP_HAL::I2CDevice method set_retries void uint8_t 0 20
|
||||||
ap_object AP_HAL::I2CDevice method write_register boolean uint8_t 0 UINT8_MAX uint8_t 0 UINT8_MAX
|
ap_object AP_HAL::I2CDevice method write_register boolean uint8_t 0 UINT8_MAX uint8_t 0 UINT8_MAX
|
||||||
ap_object AP_HAL::I2CDevice manual read_registers AP_HAL__I2CDevice_read_registers
|
ap_object AP_HAL::I2CDevice manual read_registers AP_HAL__I2CDevice_read_registers 2
|
||||||
ap_object AP_HAL::I2CDevice method set_address void uint8_t 0 UINT8_MAX
|
ap_object AP_HAL::I2CDevice method set_address void uint8_t 0 UINT8_MAX
|
||||||
|
|
||||||
|
|
||||||
@ -481,8 +481,8 @@ include AP_InertialSensor/AP_InertialSensor.h
|
|||||||
singleton AP_InertialSensor rename ins
|
singleton AP_InertialSensor rename ins
|
||||||
singleton AP_InertialSensor method get_temperature float uint8_t 0 INS_MAX_INSTANCES
|
singleton AP_InertialSensor method get_temperature float uint8_t 0 INS_MAX_INSTANCES
|
||||||
|
|
||||||
singleton CAN manual get_device lua_get_CAN_device
|
singleton CAN manual get_device lua_get_CAN_device 1
|
||||||
singleton CAN manual get_device2 lua_get_CAN_device2
|
singleton CAN manual get_device2 lua_get_CAN_device2 1
|
||||||
singleton CAN depends HAL_MAX_CAN_PROTOCOL_DRIVERS
|
singleton CAN depends HAL_MAX_CAN_PROTOCOL_DRIVERS
|
||||||
|
|
||||||
include AP_Scripting/AP_Scripting_CANSensor.h depends HAL_MAX_CAN_PROTOCOL_DRIVERS
|
include AP_Scripting/AP_Scripting_CANSensor.h depends HAL_MAX_CAN_PROTOCOL_DRIVERS
|
||||||
@ -606,15 +606,15 @@ singleton AP_EFI method get_backend AP_EFI_Backend uint8_t 0 UINT8_MAX
|
|||||||
-- ----END EFI Library----
|
-- ----END EFI Library----
|
||||||
|
|
||||||
singleton AP_Logger rename logger
|
singleton AP_Logger rename logger
|
||||||
singleton AP_Logger manual write AP_Logger_Write
|
singleton AP_Logger manual write AP_Logger_Write 7
|
||||||
|
|
||||||
singleton i2c manual get_device lua_get_i2c_device
|
singleton i2c manual get_device lua_get_i2c_device 4
|
||||||
|
|
||||||
global manual millis lua_millis
|
global manual millis lua_millis 0
|
||||||
global manual micros lua_micros
|
global manual micros lua_micros 0
|
||||||
global manual mission_receive lua_mission_receive
|
global manual mission_receive lua_mission_receive 0
|
||||||
|
|
||||||
userdata uint32_t creation lua_new_uint32_t
|
userdata uint32_t creation lua_new_uint32_t 1
|
||||||
userdata uint32_t manual_operator __add uint32_t___add
|
userdata uint32_t manual_operator __add uint32_t___add
|
||||||
userdata uint32_t manual_operator __sub uint32_t___sub
|
userdata uint32_t manual_operator __sub uint32_t___sub
|
||||||
userdata uint32_t manual_operator __mul uint32_t___mul
|
userdata uint32_t manual_operator __mul uint32_t___mul
|
||||||
@ -631,6 +631,6 @@ userdata uint32_t manual_operator __lt uint32_t___lt
|
|||||||
userdata uint32_t manual_operator __le uint32_t___le
|
userdata uint32_t manual_operator __le uint32_t___le
|
||||||
userdata uint32_t manual_operator __bnot uint32_t___bnot
|
userdata uint32_t manual_operator __bnot uint32_t___bnot
|
||||||
userdata uint32_t manual_operator __tostring uint32_t___tostring
|
userdata uint32_t manual_operator __tostring uint32_t___tostring
|
||||||
userdata uint32_t manual toint uint32_t_toint
|
userdata uint32_t manual toint uint32_t_toint 0
|
||||||
userdata uint32_t manual tofloat uint32_t_tofloat
|
userdata uint32_t manual tofloat uint32_t_tofloat 0
|
||||||
|
|
||||||
|
@ -365,6 +365,7 @@ struct method_alias {
|
|||||||
char *name;
|
char *name;
|
||||||
char *alias;
|
char *alias;
|
||||||
int line;
|
int line;
|
||||||
|
int num_args;
|
||||||
enum alias_type type;
|
enum alias_type type;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -405,6 +406,7 @@ struct userdata {
|
|||||||
int flags; // flags from the userdata_flags enum
|
int flags; // flags from the userdata_flags enum
|
||||||
char *dependency;
|
char *dependency;
|
||||||
char *creation; // name of a manual creation function if set, note that this will not be used internally
|
char *creation; // name of a manual creation function if set, note that this will not be used internally
|
||||||
|
int creation_args; // number of args for custom creation function
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct userdata *parsed_userdata;
|
static struct userdata *parsed_userdata;
|
||||||
@ -856,13 +858,21 @@ void handle_manual(struct userdata *node, enum alias_type type) {
|
|||||||
}
|
}
|
||||||
char *cpp_function_name = next_token();
|
char *cpp_function_name = next_token();
|
||||||
if (cpp_function_name == NULL) {
|
if (cpp_function_name == NULL) {
|
||||||
error(ERROR_SINGLETON, "Expected a cpp name for manual %s method",node->name);
|
error(ERROR_SINGLETON, "Expected a cpp name for manual method %s %s", node->name, name);
|
||||||
}
|
}
|
||||||
struct method_alias *alias = allocate(sizeof(struct method_alias));
|
struct method_alias *alias = allocate(sizeof(struct method_alias));
|
||||||
string_copy(&(alias->name), cpp_function_name);
|
string_copy(&(alias->name), cpp_function_name);
|
||||||
string_copy(&(alias->alias), name);
|
string_copy(&(alias->alias), name);
|
||||||
alias->line = state.line_num;
|
alias->line = state.line_num;
|
||||||
alias->type = type;
|
alias->type = type;
|
||||||
|
|
||||||
|
if (type != ALIAS_TYPE_MANUAL_OPERATOR) {
|
||||||
|
char *num_args = next_token();
|
||||||
|
if (num_args == NULL) {
|
||||||
|
error(ERROR_SINGLETON, "Expected number of args for manual method %s %s", node->name, name);
|
||||||
|
}
|
||||||
|
alias->num_args = atoi(num_args);
|
||||||
|
}
|
||||||
alias->next = node->method_aliases;
|
alias->next = node->method_aliases;
|
||||||
node->method_aliases = alias;
|
node->method_aliases = alias;
|
||||||
}
|
}
|
||||||
@ -970,10 +980,16 @@ void handle_userdata(void) {
|
|||||||
if (node->creation != NULL) {
|
if (node->creation != NULL) {
|
||||||
error(ERROR_SINGLETON, "Userdata only support a single creation function");
|
error(ERROR_SINGLETON, "Userdata only support a single creation function");
|
||||||
}
|
}
|
||||||
char *creation = strtok(NULL, "");
|
char *creation = next_token();
|
||||||
if (creation == NULL) {
|
if (creation == NULL) {
|
||||||
error(ERROR_USERDATA, "Expected a creation string for %s",node->name);
|
error(ERROR_USERDATA, "Expected a creation string for %s",node->name);
|
||||||
}
|
}
|
||||||
|
char *num_args = next_token();
|
||||||
|
if (num_args == NULL) {
|
||||||
|
error(ERROR_SINGLETON, "Expected number of args for creation method %s", node->name);
|
||||||
|
}
|
||||||
|
node->creation_args = atoi(num_args);
|
||||||
|
|
||||||
string_copy(&(node->creation), creation);
|
string_copy(&(node->creation), creation);
|
||||||
|
|
||||||
} else if (strcmp(type, keyword_manual_operator) == 0) {
|
} else if (strcmp(type, keyword_manual_operator) == 0) {
|
||||||
@ -2503,7 +2519,19 @@ void emit_docs(struct userdata *node, int is_userdata, int emit_creation) {
|
|||||||
if (emit_creation) {
|
if (emit_creation) {
|
||||||
// creation function
|
// creation function
|
||||||
fprintf(docs, "---@return %s\n", name);
|
fprintf(docs, "---@return %s\n", name);
|
||||||
fprintf(docs, "function %s() end\n\n", node->rename ? node->rename : node->sanatized_name);
|
fprintf(docs, "function %s(", node->rename ? node->rename : node->sanatized_name);
|
||||||
|
if (node->creation == NULL) {
|
||||||
|
fprintf(docs, ") end\n\n");
|
||||||
|
} else {
|
||||||
|
for (int i = 0; i < node->creation_args; ++i) {
|
||||||
|
fprintf(docs, "param%i", i+1);
|
||||||
|
if (i < node->creation_args-1) {
|
||||||
|
fprintf(docs, ", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fprintf(docs, ") end\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// global
|
// global
|
||||||
@ -2557,7 +2585,6 @@ void emit_docs(struct userdata *node, int is_userdata, int emit_creation) {
|
|||||||
// aliases
|
// aliases
|
||||||
struct method_alias *alias = node->method_aliases;
|
struct method_alias *alias = node->method_aliases;
|
||||||
while(alias) {
|
while(alias) {
|
||||||
// dont do manual bindings
|
|
||||||
if (alias->type == ALIAS_TYPE_NONE) {
|
if (alias->type == ALIAS_TYPE_NONE) {
|
||||||
// find the method this is a alias of
|
// find the method this is a alias of
|
||||||
struct method * method = node->methods;
|
struct method * method = node->methods;
|
||||||
@ -2569,6 +2596,17 @@ void emit_docs(struct userdata *node, int is_userdata, int emit_creation) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
emit_docs_method(name, alias->alias, method);
|
emit_docs_method(name, alias->alias, method);
|
||||||
|
|
||||||
|
} else if (alias->type == ALIAS_TYPE_MANUAL) {
|
||||||
|
// Cant do a great job, don't know types or return
|
||||||
|
fprintf(docs, "-- desc\nfunction %s:%s(", name, alias->alias);
|
||||||
|
for (int i = 0; i < alias->num_args; ++i) {
|
||||||
|
fprintf(docs, "param%i", i+1);
|
||||||
|
if (i < alias->num_args-1) {
|
||||||
|
fprintf(docs, ", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fprintf(docs, ") end\n\n");
|
||||||
}
|
}
|
||||||
alias = alias->next;
|
alias = alias->next;
|
||||||
}
|
}
|
||||||
@ -2797,6 +2835,25 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
emit_docs(parsed_singletons, FALSE, FALSE);
|
emit_docs(parsed_singletons, FALSE, FALSE);
|
||||||
|
|
||||||
|
// global aliases
|
||||||
|
if (parsed_globals != NULL) {
|
||||||
|
struct method_alias *alias = parsed_globals->method_aliases;
|
||||||
|
while(alias) {
|
||||||
|
if (alias->type == ALIAS_TYPE_MANUAL) {
|
||||||
|
// Cant do a great job, don't know types or return
|
||||||
|
fprintf(docs, "-- desc\nfunction %s(", alias->alias);
|
||||||
|
for (int i = 0; i < alias->num_args; ++i) {
|
||||||
|
fprintf(docs, "param%i", i+1);
|
||||||
|
if (i < alias->num_args-1) {
|
||||||
|
fprintf(docs, ", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fprintf(docs, ") end\n\n");
|
||||||
|
}
|
||||||
|
alias = alias->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fclose(docs);
|
fclose(docs);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user