From 31b52d25f41a4bf171ab205d0c039adc4f726b18 Mon Sep 17 00:00:00 2001 From: Neo Xu Date: Tue, 22 Oct 2024 01:22:24 +0800 Subject: [PATCH 1/4] simulator: remove auto-import headers Signed-off-by: Neo Xu --- simulator/lua_in_C.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/simulator/lua_in_C.c b/simulator/lua_in_C.c index b12d139..852d2a5 100644 --- a/simulator/lua_in_C.c +++ b/simulator/lua_in_C.c @@ -1,10 +1,6 @@ #include "lua.h" #include #include -#include -#include -#include -#include #define _STRINGIZE(...) #__VA_ARGS__ #define STRINGIZE(...) _STRINGIZE(__VA_ARGS__) From d097625cebc8bd4255360fcbe56ccd17c97f13b6 Mon Sep 17 00:00:00 2001 From: Neo Xu Date: Tue, 22 Oct 2024 01:23:46 +0800 Subject: [PATCH 2/4] luavgl: avoid wild pointer in lua context Monitor if the root obj is deleted, and change the ctx->root pointer correspondingly to avoid accessing wild pointer Signed-off-by: Neo Xu --- src/luavgl.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/luavgl.c b/src/luavgl.c index d5508de..4a16a5b 100644 --- a/src/luavgl.c +++ b/src/luavgl.c @@ -87,10 +87,17 @@ static int root_clean(lua_State *L) { LV_LOG_INFO("enter"); luavgl_ctx_t *ctx = luavgl_context(L); - lv_obj_clean(ctx->root); + if (ctx->root) + lv_obj_clean(ctx->root); return 0; } +static void root_delete_cb(lv_event_t *e) +{ + luavgl_ctx_t *ctx = e->user_data; + ctx->root = NULL; +} + LUALIB_API int luaopen_lvgl(lua_State *L) { luavgl_ctx_t *ctx = luavgl_context(L); @@ -148,7 +155,7 @@ LUALIB_API int luaopen_lvgl(lua_State *L) #ifdef LUAVGL_EXPOSE_WIDGET_API const luaL_Reg *reg; - for (int i = 0; ;i++) { + for (int i = 0;; i++) { reg = &widget_create_methods[i]; if (reg->name == NULL) break; @@ -158,6 +165,8 @@ LUALIB_API int luaopen_lvgl(lua_State *L) } #endif + lv_obj_add_event_cb(root, root_delete_cb, LV_EVENT_DELETE, ctx); + (void)dumpstack; (void)dumptable; (void)dumpvalue; From bca28b3a66f66365a5062c1bb8340719b9787bc5 Mon Sep 17 00:00:00 2001 From: Neo Xu Date: Tue, 22 Oct 2024 01:27:23 +0800 Subject: [PATCH 3/4] obj: allow chain set of obj style API Return the obj so we can do obj:add_style():remove_style() etc. Signed-off-by: Neo Xu --- src/style.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/style.c b/src/style.c index 0b7eca8..4676a70 100644 --- a/src/style.c +++ b/src/style.c @@ -679,7 +679,8 @@ static int luavgl_obj_set_style(lua_State *L) lua_pop(L, 1); /* remove value, keep the key to continue. */ } - return 0; + lua_settop(L, 1); + return 1; } /** @@ -697,7 +698,8 @@ static int luavgl_obj_add_style(lua_State *L) lv_obj_add_style(obj, &s->style, selector); - return 0; + lua_settop(L, 1); + return 1; } /** @@ -714,7 +716,9 @@ static int luavgl_obj_remove_style(lua_State *L) } lv_obj_remove_style(obj, &s->style, selector); - return 0; + + lua_settop(L, 1); + return 1; } /** @@ -725,7 +729,8 @@ static int luavgl_obj_remove_style_all(lua_State *L) lv_obj_t *obj = luavgl_to_obj(L, 1); lv_obj_remove_style_all(obj); - return 0; + lua_settop(L, 1); + return 1; } static const rotable_Reg luavgl_style_methods[] = { From 44b5e9b4ac7ebde5cd37319b5aa5a46037c4184a Mon Sep 17 00:00:00 2001 From: Neo Xu Date: Tue, 22 Oct 2024 01:27:53 +0800 Subject: [PATCH 4/4] doc: minor update to include global functions Signed-off-by: Neo Xu --- src/lvgl.lua | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/lvgl.lua b/src/lvgl.lua index b86944b..ce3e078 100644 --- a/src/lvgl.lua +++ b/src/lvgl.lua @@ -332,9 +332,11 @@ end --- @param parent? Object | nil --- @param property? StyleProp --- @return Object -function lvgl.Object(parent, property) +function Object(parent, property) end +lvgl.Object = Object + --- Create Calendar widget on parent --- @param parent? Object | nil --- @param property? StyleProp @@ -364,17 +366,21 @@ end --- @param parent? Object | nil --- @param property? ImageStyle --- @return Image -function lvgl.Image(parent, property) +function Image(parent, property) end +lvgl.Image = Image + --- --- Create Label on parent --- @param parent? Object | nil --- @param property? LabelStyle --- @return Label -function lvgl.Label(parent, property) +function Label(parent, property) end +lvgl.Label = Label + --- --- Create Textarea Widget on parent --- @param parent? Object | nil