luat_base_sysp.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include "luat_base.h"
  2. #include "luat_msgbus.h"
  3. #include "luat_fs.h"
  4. #include "luat_timer.h"
  5. #include <stdlib.h>
  6. #ifdef __EMSCRIPTEN__
  7. #include <emscripten.h>
  8. #include <emscripten/html5.h>
  9. #endif
  10. static const luaL_Reg loadedlibs[] = {
  11. {"_G", luaopen_base}, // _G
  12. {LUA_LOADLIBNAME, luaopen_package}, // require
  13. {LUA_COLIBNAME, luaopen_coroutine}, // coroutine协程库
  14. {LUA_TABLIBNAME, luaopen_table}, // table库,操作table类型的数据结构
  15. {LUA_IOLIBNAME, luaopen_io}, // io库,操作文件
  16. {LUA_OSLIBNAME, luaopen_os}, // os库,已精简
  17. {LUA_STRLIBNAME, luaopen_string}, // string库,字符串操作
  18. {LUA_MATHLIBNAME, luaopen_math}, // math 数值计算
  19. // {LUA_UTF8LIBNAME, luaopen_utf8},
  20. {LUA_DBLIBNAME, luaopen_debug}, // debug库,已精简
  21. #if defined(LUA_COMPAT_BITLIB)
  22. {LUA_BITLIBNAME, luaopen_bit32}, // 不太可能启用
  23. #endif
  24. {"rtos", luaopen_rtos}, // rtos底层库, 核心功能是队列和定时器
  25. {"log", luaopen_log}, // 日志库
  26. {"timer", luaopen_timer}, // 延时库
  27. {"pack", luaopen_pack}, // pack.pack/pack.unpack
  28. {"json", luaopen_cjson}, // json
  29. {"zbuff", luaopen_zbuff}, //
  30. {"mqttcore", luaopen_mqttcore}, //
  31. {"libcoap", luaopen_libcoap}, //
  32. {"crypto", luaopen_crypto},
  33. {"lvgl", luaopen_lvgl},
  34. //------------------------------------------------
  35. // 这部分是外设, 只能模拟
  36. {"gpio", luaopen_gpio},
  37. {"spi", luaopen_spi},
  38. {"lcd", luaopen_lcd},
  39. //-------------------------------------------------
  40. {NULL, NULL}
  41. };
  42. // 按不同的rtconfig加载不同的库函数
  43. void luat_openlibs(lua_State *L) {
  44. // 初始化队列服务
  45. luat_msgbus_init();
  46. //print_list_mem("done>luat_msgbus_init");
  47. // 加载系统库
  48. const luaL_Reg *lib;
  49. /* "require" functions from 'loadedlibs' and set results to global table */
  50. for (lib = loadedlibs; lib->func; lib++) {
  51. luaL_requiref(L, lib->name, lib->func, 1);
  52. lua_pop(L, 1); /* remove lib */
  53. //extern void print_list_mem(const char* name);
  54. //print_list_mem(lib->name);
  55. }
  56. }
  57. void luat_os_reboot(int code) {
  58. exit(code);
  59. }
  60. const char* luat_os_bsp(void) {
  61. return "sysp";
  62. }
  63. /** 设备进入待机模式 */
  64. void luat_os_standy(int timeout) {
  65. return; // nop
  66. }
  67. void luat_ota_reboot(int timeout_ms) {
  68. if (timeout_ms > 0)
  69. luat_timer_mdelay(timeout_ms);
  70. luat_os_reboot(1);
  71. }