From f2b40601c98331635a13aaf73c564e845f0f956c Mon Sep 17 00:00:00 2001 From: Iampete1 Date: Sat, 21 Dec 2024 03:49:26 +0000 Subject: [PATCH] AP_Scripting: docs: remove incorrect camera creation function --- libraries/AP_Scripting/docs/docs.lua | 3 - libraries/AP_Scripting/generator/src/main.c | 67 +++++++++++---------- 2 files changed, 36 insertions(+), 34 deletions(-) diff --git a/libraries/AP_Scripting/docs/docs.lua b/libraries/AP_Scripting/docs/docs.lua index e5c9155867..78548252c4 100644 --- a/libraries/AP_Scripting/docs/docs.lua +++ b/libraries/AP_Scripting/docs/docs.lua @@ -1395,9 +1395,6 @@ function camera:take_picture(instance) end ---@class (exact) AP_Camera__camera_state_t_ud local AP_Camera__camera_state_t_ud = {} ----@return AP_Camera__camera_state_t_ud -function AP_Camera__camera_state_t() end - -- get field ---@return Vector2f_ud function AP_Camera__camera_state_t_ud:tracking_p1() end diff --git a/libraries/AP_Scripting/generator/src/main.c b/libraries/AP_Scripting/generator/src/main.c index 92278a34a1..7f2257465b 100644 --- a/libraries/AP_Scripting/generator/src/main.c +++ b/libraries/AP_Scripting/generator/src/main.c @@ -2578,20 +2578,14 @@ void emit_loaders(void) { fprintf(source, "}\n\n"); } -void emit_userdata_new_funcs(void) { - struct userdata *data = parsed_userdata; - fprintf(source, "const struct userdata {\n"); - fprintf(source, " const char *name;\n"); - fprintf(source, " const lua_CFunction fun;\n"); - fprintf(source, "} new_userdata[] = {\n"); - while (data) { +int should_emit_creation(struct userdata * data) { // Dont expose creation function for all read only items int expose_creation = FALSE; if (data->creation || data->methods) { // Custom creation or methods, if not specifically disabled expose_creation = !(data->creation && data->creation_args == -1); } else { - // Feilds only + // Fields only struct userdata_field * field = data->fields; while(field) { if (field->access_flags & ACCESS_FLAG_WRITE) { @@ -2601,8 +2595,18 @@ void emit_userdata_new_funcs(void) { field = field->next; } } + return expose_creation; +} - if (expose_creation) { +void emit_userdata_new_funcs(void) { + struct userdata *data = parsed_userdata; + fprintf(source, "const struct userdata {\n"); + fprintf(source, " const char *name;\n"); + fprintf(source, " const lua_CFunction fun;\n"); + fprintf(source, "} new_userdata[] = {\n"); + while (data) { + // Dont expose creation function for all read only items + if (should_emit_creation(data)) { start_dependency(source, data->dependency); if (data->creation) { // expose custom creation function to user (not used internally) @@ -2885,32 +2889,33 @@ void emit_docs(struct userdata *node, int is_userdata, int emit_creation) { } if (is_userdata) { - // local userdata - fprintf(docs, "local %s = {}\n\n", name); + if (should_emit_creation(node)) { + // local userdata + fprintf(docs, "local %s = {}\n\n", name); - int creation_disabled = (node->creation && node->creation_args == -1); - if (emit_creation && (!node->creation || !creation_disabled)) { - // creation function - if (node->creation != NULL) { - for (int i = 0; i < node->creation_args; ++i) { - fprintf(docs, "---@param param%i UNKNOWN\n", i+1); - } - } - - fprintf(docs, "---@return %s\n", 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, ", "); + int creation_disabled = (node->creation && node->creation_args == -1); + if (emit_creation && (!node->creation || !creation_disabled)) { + // creation function + if (node->creation != NULL) { + for (int i = 0; i < node->creation_args; ++i) { + fprintf(docs, "---@param param%i UNKNOWN\n", i+1); } } - fprintf(docs, ") end\n\n"); - } + fprintf(docs, "---@return %s\n", 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 { // global