Skip to content

Commit

Permalink
AP_Scripting: use helper for not supported error saving 1K of flash
Browse files Browse the repository at this point in the history
  • Loading branch information
IamPete1 authored and WickedShell committed Feb 18, 2021
1 parent b7044d3 commit bf7920f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion libraries/AP_Scripting/generator/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1397,7 +1397,7 @@ void emit_userdata_method(const struct userdata *data, const struct method *meth
// fetch and check the singleton pointer
fprintf(source, " %s * ud = %s::get_singleton();\n", data->name, data->name);
fprintf(source, " if (ud == nullptr) {\n");
fprintf(source, " return luaL_argerror(L, %d, \"%s not supported on this firmware\");\n", arg_count, access_name);
fprintf(source, " return not_supported_error(L, %d, \"%s\");\n", arg_count, access_name);
fprintf(source, " }\n\n");
}

Expand Down Expand Up @@ -1956,6 +1956,13 @@ void emit_argcheck_helper(void) {
fprintf(source, "}\n\n");
}

void emit_not_supported_helper(void) {
fprintf(source, "static int not_supported_error(lua_State *L, int arg, const char* name) {\n");
fprintf(source, " char error_msg[50];\n");
fprintf(source, " snprintf(error_msg, sizeof(error_msg), \"%%s not supported on this firmware\", name);\n");
fprintf(source, " return luaL_argerror(L, arg, error_msg);\n");
fprintf(source, "}\n\n");
}

char * output_path = NULL;

Expand Down Expand Up @@ -2043,6 +2050,8 @@ int main(int argc, char **argv) {

emit_argcheck_helper();

emit_not_supported_helper();

emit_userdata_allocators();

emit_userdata_checkers();
Expand Down

0 comments on commit bf7920f

Please sign in to comment.