From 00efc1c926e177e0eea06c4173fb0680b780b56f Mon Sep 17 00:00:00 2001 From: Iampete1 Date: Thu, 14 Nov 2024 15:39:45 +0000 Subject: [PATCH] AP_Scripting: generator: allow fields on ap_objects --- libraries/AP_Scripting/generator/src/main.c | 29 +++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/libraries/AP_Scripting/generator/src/main.c b/libraries/AP_Scripting/generator/src/main.c index e22f03d05d..92278a34a1 100644 --- a/libraries/AP_Scripting/generator/src/main.c +++ b/libraries/AP_Scripting/generator/src/main.c @@ -1222,8 +1222,11 @@ void handle_ap_object(void) { } else if (strcmp(type, keyword_manual) == 0) { handle_manual(node, ALIAS_TYPE_MANUAL); + } else if (strcmp(type, keyword_field) == 0) { + handle_userdata_field(node); + } else { - error(ERROR_SINGLETON, "AP_Objects only support renames, methods, semaphore or manual keywords (got %s)", type); + error(ERROR_SINGLETON, "AP_Objects only support renames, methods, field, semaphore or manual keywords (got %s)", type); } // check that we didn't just add 2 singleton flags @@ -1830,6 +1833,28 @@ void emit_singleton_fields() { } } +void emit_ap_object_field(const struct userdata *data, const struct userdata_field *field) { + fprintf(source, "static int %s_%s(lua_State *L) {\n", data->sanatized_name, field->name); + fprintf(source, " %s *ud = *check_%s(L, 1);\n", data->name, data->sanatized_name); + emit_field(field, "ud", "->"); +} + +void emit_ap_object_fields() { + struct userdata * node = parsed_ap_objects; + while(node) { + struct userdata_field *field = node->fields; + if (field) { + start_dependency(source, node->dependency); + while(field) { + emit_ap_object_field(node, field); + field = field->next; + } + end_dependency(source, node->dependency); + } + node = node->next; + } +} + // emit refences functions for a call, return the number of arduments added int emit_references(const struct argument *arg, const char * tab) { int arg_index = NULLABLE_ARG_COUNT_BASE + 2; @@ -3162,7 +3187,7 @@ int main(int argc, char **argv) { emit_methods(parsed_userdata); emit_index(parsed_userdata); - + emit_ap_object_fields(); emit_methods(parsed_ap_objects); emit_index(parsed_ap_objects);