在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):luvit/luv开源软件地址(OpenSource Url):https://github.com/luvit/luv开源编程语言(OpenSource Language):C 59.9%开源软件介绍(OpenSource Introduction):luvlibuv bindings for luajit and lua 5.1/ 5.2/ 5.3/ 5.4. This library makes libuv available to lua scripts. It was made for the luvit project but should usable from nearly any lua project. The library can be used by multiple threads at once. Each thread is assumed to load the library from a different local uv = require('luv')
-- Create a handle to a uv_timer_t
local timer = uv.new_timer()
-- This will wait 1000ms and then continue inside the callback
timer:start(1000, 0, function ()
-- timer here is the value we passed in before from new_timer.
print ("Awake!")
-- You must always close your uv handles or you'll leak memory
-- We can't depend on the GC since it doesn't know enough about libuv.
timer:close()
end)
print("Sleeping");
-- uv.run will block and wait for all events to run.
-- When there are no longer any active handles, it will return
uv.run() Here is an example of an TCP echo server local uv = require('luv')
local function create_server(host, port, on_connection)
local server = uv.new_tcp()
server:bind(host, port)
server:listen(128, function(err)
-- Make sure there was no problem setting up listen
assert(not err, err)
-- Accept the client
local client = uv.new_tcp()
server:accept(client)
on_connection(client)
end)
return server
end
local server = create_server("0.0.0.0", 0, function (client)
client:read_start(function (err, chunk)
-- Crash on errors
assert(not err, err)
if chunk then
-- Echo anything heard
client:write(chunk)
else
-- When the stream ends, close the socket
client:close()
end
end)
end)
print("TCP Echo server listening on port " .. server:getsockname().port)
uv.run() More examples can be found in the examples and tests folders. LuarocksLuv is available on Luarocks here. It can be installed via:
Note: To require
Building From SourceTo build, first install your compiler tools. Get a CompilerOn linux this probably means On OSX, you probably want XCode which comes with For windows the free Visual Studio Express works. If you get the 2013 edition,
make sure to get the Install CMakeNow install Cmake. The version in Install GitIf you haven't already, install git and make sure it's in your path. This comes with XCode on OSX. On Linux it's in your package manager. For windows, use the installer at http://git-scm.com. Make sure it's available to your windows command prompt. Clone the CodeNow open a terminal and clone the code. For windows I recommend the special developer command prompt that came with Visual Studio.
Build the Code and TestOn windows I wrote a small batch file that runs the correct cmake commands and copies the output files for easy access.
On unix systems, use the Makefile.
This will build luv as a module library. Module libraries are plugins that are not linked into other targets. Build with PUC Lua 5.4By default luv is linked with LuaJIT 2.1.0-beta3. If you rather like to link luv with PUC Lua 5.4 you can run make with:
Build as static libraryIf you want to build luv as a static library run make with:
This will create a static library Build as shared libraryIf you want to build luv as a shared library run make with:
This will create a shared library Build with shared librariesBy default the build system will build luv with the supplied dependencies. These are:
However, if your target system has already one or more of these dependencies
installed you can link Linking with shared libuvThe default shared library name for libuv is
Linking with shared LuaJITThe default shared library name for LuaJIT is
Linking with shared Lua 5.xThe default shared library name for Lua 5.x is
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论