diff --git a/libraries/AP_Scripting/.gitignore b/libraries/AP_Scripting/.gitignore new file mode 100644 index 0000000000..319ec56ad5 --- /dev/null +++ b/libraries/AP_Scripting/.gitignore @@ -0,0 +1,3 @@ +lua_generated_bindings.cpp +lua_generated_bindings.h + diff --git a/libraries/AP_Scripting/generator/src/main.c b/libraries/AP_Scripting/generator/src/main.c index f5759f6b48..971d6ffcd1 100644 --- a/libraries/AP_Scripting/generator/src/main.c +++ b/libraries/AP_Scripting/generator/src/main.c @@ -68,8 +68,8 @@ FILE *description; FILE *header; FILE *source; -static struct generator_state state = {}; -static struct header * headers = NULL; +static struct generator_state state; +static struct header * headers; enum trace_level { TRACE_TOKENS = (1 << 0), @@ -321,8 +321,8 @@ struct userdata { int flags; // flags from the userdata_flags enum }; -static struct userdata *parsed_userdata = NULL; -static struct userdata *parsed_ap_objects = NULL; +static struct userdata *parsed_userdata; +static struct userdata *parsed_ap_objects; struct dependency { @@ -332,7 +332,7 @@ struct dependency { char *error_msg; // message if the check fails }; -static struct dependency *parsed_dependencies = NULL; +static struct dependency *parsed_dependencies; // lazy helper that allocates a storage buffer and does strcpy for us void string_copy(char **dest, const char * src) { @@ -1928,7 +1928,7 @@ int main(int argc, char **argv) { sanity_check_userdata(); fprintf(source, "#include \"lua_generated_bindings.h\"\n"); - fprintf(source, "#include \"lua_boxed_numerics.h\"\n"); + fprintf(source, "#include \n"); trace(TRACE_GENERAL, "Starting emission"); @@ -1980,7 +1980,7 @@ int main(int argc, char **argv) { fprintf(header, "#pragma once\n"); fprintf(header, "// auto generated bindings, don't manually edit. See README.md for details.\n"); emit_headers(header); - fprintf(header, "#include \"lua/src/lua.hpp\"\n"); + fprintf(header, "#include \n"); fprintf(header, "#include \n\n"); emit_dependencies(header); fprintf(header, "\n\n"); diff --git a/libraries/AP_Scripting/lua_bindings.cpp b/libraries/AP_Scripting/lua_bindings.cpp index d3e38fcf58..83a7c340da 100644 --- a/libraries/AP_Scripting/lua_bindings.cpp +++ b/libraries/AP_Scripting/lua_bindings.cpp @@ -5,7 +5,7 @@ #include "lua_bindings.h" #include "lua_boxed_numerics.h" -#include "lua_generated_bindings.h" +#include extern const AP_HAL::HAL& hal; diff --git a/libraries/AP_Scripting/lua_repl.cpp b/libraries/AP_Scripting/lua_repl.cpp index fc2b5b8cf0..d90f078dcd 100644 --- a/libraries/AP_Scripting/lua_repl.cpp +++ b/libraries/AP_Scripting/lua_repl.cpp @@ -4,7 +4,7 @@ #include "lua_scripts.h" -#include "lua_generated_bindings.h" +#include #include "lua/src/lua.h" #include "lua/src/lauxlib.h" diff --git a/libraries/AP_Scripting/lua_scripts.cpp b/libraries/AP_Scripting/lua_scripts.cpp index 3d7a326895..244c09f644 100644 --- a/libraries/AP_Scripting/lua_scripts.cpp +++ b/libraries/AP_Scripting/lua_scripts.cpp @@ -18,7 +18,7 @@ #include #include "AP_Scripting.h" -#include "lua_generated_bindings.h" +#include #ifndef SCRIPTING_DIRECTORY #if HAL_OS_FATFS_IO diff --git a/libraries/AP_Scripting/wscript b/libraries/AP_Scripting/wscript new file mode 100644 index 0000000000..adffe3cdc5 --- /dev/null +++ b/libraries/AP_Scripting/wscript @@ -0,0 +1,39 @@ +#!/usr/bin/env python +# encoding: utf-8 +''' +build generated bindings from bindings.desc for AP_Scripting +''' + +from waflib.TaskGen import after_method, before_method, feature + +CFLAGS="-std=c99 -Wno-error=missing-field-initializers -Wall -Werror -Wextra" +CC="gcc" + +def configure(cfg): + cfg.env.AP_LIB_EXTRA_SOURCES['AP_Scripting'] = ['lua_generated_bindings.cpp'] + +def build(bld): + main_c = bld.srcnode.make_node('libraries/AP_Scripting/generator/src/main.c') + gen_bindings = bld.bldnode.find_or_declare('gen-bindings') + + bld( + # build gen-bindings compiler + source=main_c, + target=[gen_bindings], + # we should have configure tests for finding the native compiler + rule="%s %s -o %s %s" % (CC, CFLAGS, gen_bindings.abspath(), main_c.abspath()), + group='dynamic_sources', + ) + + bindings = bld.srcnode.make_node('libraries/AP_Scripting/generator/description/bindings.desc') + gen_bindings = bld.bldnode.find_or_declare('gen-bindings') + generated_cpp = bld.bldnode.find_or_declare('libraries/AP_Scripting/lua_generated_bindings.cpp') + generated_h = bld.bldnode.find_or_declare('libraries/AP_Scripting/lua_generated_bindings.h') + + bld( + # build the bindings + source=[bindings, gen_bindings], + rule="./gen-bindings -o libraries/AP_Scripting/lua_generated_bindings -i %s" % (bindings.abspath()), + target=[generated_cpp, generated_h], + group='dynamic_sources', + )