Easiest way to make lua script wait/pause/sleep/block for a few seconds?

前端 未结 19 1399
礼貌的吻别
礼貌的吻别 2020-12-03 00:41

I cant figure out how to get lua to do any common timing tricks, such as

  • sleep - stop all action on thread

  • pause/wait - don\'t go on to the

19条回答
  •  隐瞒了意图╮
    2020-12-03 01:20

    If you happen to use LuaSocket in your project, or just have it installed and don't mind to use it, you can use the socket.sleep(time) function which sleeps for a given amount of time (in seconds).

    This works both on Windows and Unix, and you do not have to compile additional modules.

    I should add that the function supports fractional seconds as a parameter, i.e. socket.sleep(0.5) will sleep half a second. It uses Sleep() on Windows and nanosleep() elsewhere, so you may have issues with Windows accuracy when time gets too low.

提交回复
热议问题