luat_lib_timer.c 927 B

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