I'm trying to add some lua scripts to a firmware project writen in C. For now, the script is a config table, from which I'm trying to get the value of the num variable, all of this using the C API in the main.c file.
I'm testing this code including the standard source files of Lua for Desktop in my project (I have read about eLua, but the I don't need to implement the full code in Lua, I need to have Lua and C files coexisting in my project).
It works fine when I test this in the computer with the gcc compiler, but when I try to pass the same idea to my microcontroller with the cross compiler it compiles and there are no erros, but it seems to have problems getting the value from the lua file, because the variable valueFromLua always equals to 1.
My project folder tree has the following structure:
- Source
- main.c
- Tools
- lua
- scripts
- config_table.lua
- scripts
- lua
config_table.lua
config_table = {
num = 10
}
main.c
lua_State *L = luaL_newstate();
uint8_t valueFromLua;
if(luaL_dofile(L, "./Tools/lua/scripts/config_table.lua") == LUA_OK)
{
lua_getglobal(L, "config_table");
if(lua_istable(L, -1))
{
lua_getfield(L, -1, "num");
valueFromLua = lua_tointeger(L, -1);
}
}
else
{
valueFromLua = 1;
}
I would appreciate your comments, thanks in advance.