luat_lib_timer.c 884 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. @module timer
  3. @summary 操作底层定时器
  4. @version 1.0
  5. @date 2020.03.30
  6. */
  7. #include "luat_base.h"
  8. #include "luat_log.h"
  9. #include "luat_timer.h"
  10. #include "luat_malloc.h"
  11. /*
  12. 硬阻塞指定时长,期间没有任何luat代码会执行,包括底层消息处理机制
  13. @api timer.mdelay(timeout)
  14. @int 阻塞时长
  15. @return nil 无返回值
  16. -- 本方法通常不会使用,除非你很清楚会发生什么
  17. timer.mdelay(10)
  18. */
  19. static int l_timer_mdelay(lua_State *L) {
  20. lua_gettop(L);
  21. if (lua_isinteger(L, 1)) {
  22. lua_Integer ms = luaL_checkinteger(L, 1);
  23. if (ms)
  24. luat_timer_mdelay(ms);
  25. }
  26. return 0;
  27. }
  28. //TODO 支持hwtimer
  29. #include "rotable.h"
  30. static const rotable_Reg reg_timer[] =
  31. {
  32. { "mdelay", l_timer_mdelay, 0},
  33. { NULL, NULL, 0}
  34. };
  35. LUAMOD_API int luaopen_timer( lua_State *L ) {
  36. luat_newlib(L, reg_timer);
  37. return 1;
  38. }