Add luajit snippet
This commit is contained in:
parent
e01bc6604f
commit
29cea70ef3
|
@ -0,0 +1,31 @@
|
||||||
|
-- 调用 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")
|
||||||
|
|
Loading…
Reference in New Issue