XuNeo / luavgl

lua + lvgl = luavgl An optimized lvgl Lua binding
MIT License
57 stars 13 forks source link

feat(obj): allow to omit the nil parent #48

Closed XuNeo closed 3 weeks ago

XuNeo commented 3 weeks ago

Check if the first parameter is table, if so, the parent must be nil and default root is used. This allows us to create object on screen easier.

The change is pretty simple.

@@ -842,7 +842,7 @@ LUALIB_API int luavgl_obj_create_helper(lua_State *L,
   luavgl_ctx_t *ctx = luavgl_context(L);
   lv_obj_t *parent;

-  if (lua_isnoneornil(L, 1)) {
+  if (lua_type(L, 1) == LUA_TTABLE || lua_isnoneornil(L, 1)) {
     parent = ctx->root;
   } else {
     parent = luavgl_to_obj(L, 1);