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

前端 未结 19 1392
礼貌的吻别
礼貌的吻别 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条回答
  •  Happy的楠姐
    2020-12-03 01:17

    require 'alien'
    
    if alien.platform == "windows" then
      kernel32 = alien.load("kernel32.dll")
      sleep = kernel32.Sleep
      sleep:types{ret="void",abi="stdcall","uint"}
    else
      -- untested !!!
      libc = alien.default
      local usleep = libc.usleep
      usleep:types('int', 'uint')
      sleep = function(ms)
        while ms > 1000 do
          usleep(1000)
          ms = ms - 1000
        end
        usleep(1000 * ms)
      end
    end 
    
    print('hello')
    sleep(500)  -- sleep 500 ms
    print('world')
    

提交回复
热议问题