32 lines
481 B
Lua
32 lines
481 B
Lua
-- 调用 C 函数
|
|
local ffi = require("ffi")
|
|
ffi.cdef([[
|
|
int printf(const char *fmt, ...);
|
|
]])
|
|
|
|
ffi.C.printf("Invocate printf in %s\n", "lua")
|
|
|
|
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 _ = 1, 160 do
|
|
io.write(".")
|
|
io.flush()
|
|
sleep(0.01)
|
|
end
|
|
io.write("\n")
|
|
|