Skip to content

Commit

Permalink
widget: add option to expose widget API to global
Browse files Browse the repository at this point in the history
Signed-off-by: Neo Xu <[email protected]>
  • Loading branch information
XuNeo committed Aug 18, 2024
1 parent f74f48e commit dc6d844
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ option(LV_USE_LIBPNG "Use libpng to decode PNG" OFF)
option(LV_USE_LIBJPEG_TURBO "Use libjpeg turbo to decode JPEG" OFF)
option(LV_USE_FFMPEG "Use libffmpeg to display video using lv_ffmpeg" OFF)
option(LV_USE_FREETYPE "Use freetype lib" OFF)
option(EXPOSE_WIDGET_API "Expose widget create method to global" ON)

add_compile_definitions($<$<BOOL:${LV_USE_DRAW_SDL}>:LV_USE_DRAW_SDL=1>)
add_compile_definitions($<$<BOOL:${LV_USE_LIBPNG}>:LV_USE_LIBPNG=1>)
add_compile_definitions($<$<BOOL:${LV_USE_LIBJPEG_TURBO}>:LV_USE_LIBJPEG_TURBO=1>)
add_compile_definitions($<$<BOOL:${LV_USE_FFMPEG}>:LV_USE_FFMPEG=1>)
add_compile_definitions($<$<BOOL:${EXPOSE_WIDGET_API}>:LUAVGL_EXPOSE_WIDGET_API=1>)

find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
Expand Down
12 changes: 12 additions & 0 deletions src/luavgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ LUALIB_API int luaopen_lvgl(lua_State *L)
luaL_getmetatable(L, "widgets");
lua_setmetatable(L, -2);

#ifdef LUAVGL_EXPOSE_WIDGET_API
const luaL_Reg *reg;
for (int i = 0; ;i++) {
reg = &widget_create_methods[i];
if (reg->name == NULL)
break;

lua_pushcfunction(L, reg->func);
lua_setglobal(L, reg->name);
}
#endif

(void)dumpstack;
(void)dumptable;
(void)dumpvalue;
Expand Down

0 comments on commit dc6d844

Please sign in to comment.