Просмотр исходного кода

fix: lv.style_t()改成内存分配方式后, 需要添加__gc进行额外的内存回收

Wendal Chen 2 лет назад
Родитель
Сommit
df1163c592

+ 13 - 0
components/lvgl/binding/luat_lib_lvgl_struct.c

@@ -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) {
 
@@ -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 - 0
components/lvgl/binding/luat_lib_lvgl_style.c

@@ -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;
 }