luat_lib_lvgl_msgbox_ex.c 1.1 KB

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. #include "luat_zbuff.h"
  12. int luat_lv_msgbox_add_btns(lua_State *L) {
  13. LV_DEBUG("CALL lv_msgbox_add_btns");
  14. lv_obj_t* mbox = (lv_obj_t*)lua_touserdata(L, 1);
  15. char **btn_mapaction = NULL;
  16. if (lua_istable(L,2)){
  17. int n = luaL_len(L, 2);
  18. btn_mapaction = (char**)luat_heap_calloc(n,sizeof(char*));
  19. for (int i = 0; i < n; i++) {
  20. lua_pushnumber(L, i+1);
  21. if (LUA_TSTRING == lua_gettable(L, 2)) {
  22. char* btn_mapaction_str = luaL_checkstring(L, -1);
  23. LV_LOG_INFO("%d: %s",i,btn_mapaction_str);
  24. btn_mapaction[i] =luat_heap_calloc(1,strlen(btn_mapaction_str)+1);
  25. memcpy(btn_mapaction[i],btn_mapaction_str,strlen(btn_mapaction_str)+1);
  26. };
  27. lua_pop(L, 1);
  28. }
  29. }
  30. if (btn_mapaction == NULL)
  31. return 0;
  32. lv_msgbox_add_btns(mbox, btn_mapaction);
  33. return 0;
  34. }