Adding, building and linking Lua in a project #45485
-
Bug description My environment:
To reproduce the problem
2.2.
2.3.
Expected behavior
Impact Logs and console output
It seems that zephyr is not able to find the functions
However, once the binary is flashed, a run time error appears:
Additional context |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 2 replies
-
This is not a Zephyr bug, but a problem/bug with something you are working on. |
Beta Was this translation helpful? Give feedback.
-
Funny that this is the top result when googling for Lua support in Zephyr. It should be done, and I think it can be done relatively easily. |
Beta Was this translation helpful? Give feedback.
-
I could make this example run with the following project layout: CMakeLists.txt The content of the CMakeLists.txt file is cmake_minimum_required(VERSION 3.20.0) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) add_library(liblua STATIC target_include_directories(liblua target_link_libraries(liblua zephyr_interface) install(TARGETS liblua DESTINATION lib) add_subdirectory(src) The content of the prj.conf is: CONFIG_APPLICATION_DEFINED_SYSCALL=y In the src file I have: where CMakeLists.txt contains: target_sources(app target_link_libraries(app main.c contains: #include <zephyr.h> #include <stdio.h> void main(void)
} and missing_stubs.c contains: #include <zephyr.h> /* FIXME: this stubs should be properly implemented, in zephyr itself or here.
clock_t _times(struct tms* tms) int _unlink(const char *pathname) int _link(const char *oldpath, const char *newpath) The code runs on an nxp discovery l475 iot1 board, it shows the lua string: *** Booting Zephyr OS build 70cca36 *** The content of the lua directory is the sources of lua downloaded from their git repository. I could not solve however the problem of the missing newlib stubs. I think these should be added to the newlib library from zephyr. Hope this helps. Christian Tenllado |
Beta Was this translation helpful? Give feedback.
-
For your convenience I created a github repo with the code for the lua hello world example in a west workspace. The repo is https://github.com/tenllado/zephyr_hello_world_lua.git The README.md file includes the instructions to compile and run it. I will appreciate any help with the missing newlib stubs problem. |
Beta Was this translation helpful? Give feedback.
-
@oscarbaselga - awesome! It would probably be worth it to consider adding a E.g. application CMakeLists.txt # concatenate feature.lua to build/generated/all_lua_sources.lua
lua_sources_ifdef(CONFIG_SOME_LUA_FEATURE feature.lua)
# Export one or more function definitions so that they can be added to a C header prior to compiling C code
# Maybe even automatically generate C wrappers for Lua functions?
# e.g. z = f(x, y) => double zlua_f(int x, double y)
# https://www.lua.org/pil/25.2.html
lua_export_ifdef(CONFIG_SOME_LUA_FEATURE "double", "feature_function", "int", "x", "double", "y") C / C++ file #include <generated/all_lua_functions.h>
void arbitrary_function() {
int x = 42;
double y = 73.0;
double z = zlua_f(x, y);
} I guess CMake could be used to collect all of the "entry points" into lua code (so that it isn't just a I would put the lua library definition inside of What you've done with the kind of "west submodule" for the Lua source code is smart - it makes your Lua module really a thin wrapper around upstream. If |
Beta Was this translation helpful? Give feedback.
-
@oscarbaselga @tenllado, I was wondering why you did not follow up with the Lua module on Zephyr. I am investing some time in that and would like to understand why such a cool feature is still not there, given that you had a good base code 3 years ago. Are you still interested in collaborating with this effort? |
Beta Was this translation helpful? Give feedback.
I could make this example run with the following project layout:
CMakeLists.txt
prj.conf
src
lua
The content of the CMakeLists.txt file is
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(sol)
add_library(liblua STATIC
lua/lapi.c
lua/lauxlib.c
lua/lbaselib.c
lua/lcode.c
lua/lcorolib.c
lua/lctype.c
lua/ldblib.c
lua/ldebug.c
lua/ldo.c
lua/ldump.c
lua/lfunc.c
lua/lgc.c
lua/linit.c
lua/liolib.c
lua/llex.c
lua/lmathlib.c
lua/lmem.c
lua/loadlib.c
lua/lobject.c
lua/lopcodes.c
lua/loslib.c
lua/lparser.c
lua/lstate.c
lua/lstring.c
lua/lstrlib.c
lua/ltable.c
lua/ltablib.c
lua/ltm.c
lua/lundump.c
lua/lutf8lib.c
lua/lvm.c
lua/lzio.c
)
target_include…