luat_lib_lvgl_btnmatrix_ex.c 1008 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. @module lvgl
  3. @summary LVGL图像库
  4. @version 1.0
  5. @date 2021.06.01
  6. */
  7. #include "luat_base.h"
  8. #include "lvgl.h"
  9. #include "luat_lvgl.h"
  10. #include "luat_mem.h"
  11. int luat_lv_btnmatrix_set_map(lua_State *L) {
  12. LV_DEBUG("CALL lv_btnmatrix_set_map");
  13. lv_obj_t* btnm = (lv_obj_t*)lua_touserdata(L, 1);
  14. char **map;
  15. if (lua_istable(L,2)){
  16. int n = luaL_len(L, 2);
  17. map = (char**)luat_heap_calloc(n,sizeof(char*));
  18. for (int i = 0; i < n; i++) {
  19. lua_pushnumber(L, i+1);
  20. if (LUA_TSTRING == lua_gettable(L, 2)) {
  21. char* map_str = luaL_checkstring(L, -1);
  22. LV_LOG_INFO("%d: [%s]", i, map_str);
  23. map[i] =luat_heap_calloc(1,strlen(map_str)+1);
  24. memcpy(map[i],map_str,strlen(map_str)+1);
  25. };
  26. lua_pop(L, 1);
  27. }
  28. } else {
  29. return 0;
  30. }
  31. lv_btnmatrix_set_map(btnm,map);
  32. // luat_heap_free(map);
  33. return 0;
  34. }