lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


This is from Mike Pall's ext_ffi_tutorial.html (latest in git)

It's using LuaJIT's FFI, but one can do it the lua binding way if needed.

local ffi = require("ffi")
ffi.cdef[[
void Sleep(int ms);
int poll(struct pollfd *fds, unsigned long nfds, int timeout);
]]

local sleep
if ffi.os == "Windows" then
  function sleep(s)
    ffi.C.Sleep(s*1000)
  end
else
  function sleep(s)
    ffi.C.poll(nil, 0, s*1000)
  end
end

for i=1,160 do
  io.write("."); io.flush()
  sleep(0.01)
end
io.write("\n")


On 2/18/11 4:55 AM, Gilles Ganault wrote:
Hello,

	Now that I could create the text file, I need to have the script
pause for a few seconds before resuming.

I checked the archives for this list:
===========
"NEWBIE Question: LUA wait() function?"
http://thread.gmane.org/gmane.comp.lang.lua.general/46268/focus=46287

"SLEEP"
http://thread.gmane.org/gmane.comp.lang.lua.general/69686/focus=69693
===========

Since I cross-compile Lua on Ubuntu and run it on a uClinux appliance,
I need a portable, compact solution to pause a script.

Which solution would you recommend? Compiling Lua with a POSIX
library, such as luaposix? Using "socket.sleep(0.2)"? Other?

I was thinking of using those options in CFLAGS:
-DLUA_USE_POSIX -DLUA_USE_LINUX

Thank you.