Skip to content

Commit

Permalink
fix: lv.style_t()改成内存分配方式后, 需要添加__gc进行额外的内存回收
Browse files Browse the repository at this point in the history
  • Loading branch information
wendal committed Jul 14, 2023
1 parent 4a0d9c8 commit df1163c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions components/lvgl/binding/luat_lib_lvgl_struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,13 @@ int _lvgl_struct_img_dsc_t_newindex(lua_State *L) {

//--------------------------------------------

int _lvgl_struct_style_t_gc(lua_State *L) {
lv_style_t *style = (lv_style_t *) lua_touserdata(L, 1);
if (style != NULL) {
lv_style_reset(style);
}
return 0;
}

void luat_lvgl_struct_init(lua_State *L) {

Expand Down Expand Up @@ -527,4 +534,10 @@ void luat_lvgl_struct_init(lua_State *L) {
lua_pushcfunction(L, _lvgl_struct_draw_line_dsc_t_newindex);
lua_setfield( L, -2, "__newindex" );
lua_pop(L, 1);


luaL_newmetatable(L, "LV_STYLE_T*");
lua_pushcfunction(L, _lvgl_struct_style_t_gc);
lua_setfield( L, -2, "__gc" );
lua_pop(L, 1);
}
1 change: 1 addition & 0 deletions components/lvgl/binding/luat_lib_lvgl_style.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ int luat_lv_style_t(lua_State *L) {
LLOGE("out of memory when create lv_style_t");
return 0;
}
luaL_setmetatable(L, "LV_STYLE_T*");
return 1;
}

Expand Down

0 comments on commit df1163c

Please sign in to comment.