{"id":13580225,"url":"https://github.com/luvit/luv","last_synced_at":"2025-05-14T01:07:33.306Z","repository":{"id":4970244,"uuid":"6127999","full_name":"luvit/luv","owner":"luvit","description":"Bare libuv bindings for lua","archived":false,"fork":false,"pushed_at":"2025-02-05T15:19:57.000Z","size":1773,"stargazers_count":863,"open_issues_count":52,"forks_count":190,"subscribers_count":48,"default_branch":"master","last_synced_at":"2025-04-03T08:51:34.190Z","etag":null,"topics":["hacktoberfest","libuv","lua","lua-bindings","luajit","luvit"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"d5884/yabin","license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/luvit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-10-08T17:08:45.000Z","updated_at":"2025-04-02T03:08:17.000Z","dependencies_parsed_at":"2023-02-15T08:16:24.070Z","dependency_job_id":"fff8a6bf-fb82-4cc3-a990-e12b025a996c","html_url":"https://github.com/luvit/luv","commit_stats":{"total_commits":1092,"total_committers":76,"mean_commits":"14.368421052631579","dds":0.5989010989010989,"last_synced_commit":"1ca0af2b9177d66ef14d78bfdaae1ab417302d83"},"previous_names":[],"tags_count":60,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luvit%2Fluv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luvit%2Fluv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luvit%2Fluv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luvit%2Fluv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luvit","download_url":"https://codeload.github.com/luvit/luv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248224095,"owners_count":21068072,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest","libuv","lua","lua-bindings","luajit","luvit"],"created_at":"2024-08-01T15:01:48.923Z","updated_at":"2025-04-10T13:07:30.626Z","avatar_url":"https://github.com/luvit.png","language":"C","readme":"luv\n===\n\n[![Linux Build Status](https://github.com/luvit/luv/actions/workflows/ci.yml/badge.svg)](https://github.com/luvit/luv/actions/workflows/ci.yml)\n[![Windows Build status](https://ci.appveyor.com/api/projects/status/uo1qhdcc0vcqsiok/branch/master?svg=true)](https://ci.appveyor.com/project/racker-buildbot/luv/branch/master)\n\n[libuv](https://github.com/libuv/libuv) bindings for\n[luajit](http://luajit.org/) and [lua](http://www.lua.org/)\n[5.1](http://www.lua.org/manual/5.1/manual.html)/\n[5.2](http://www.lua.org/manual/5.2/manual.html)/\n[5.3](http://www.lua.org/manual/5.3/manual.html)/\n[5.4](http://www.lua.org/manual/5.4/manual.html).\n\nThis library makes libuv available to lua scripts.  It was made for the [luvit](http://luvit.io/) project but should usable from nearly any lua project.\n\nThe library can be used by multiple threads at once.  Each thread is assumed to load the library from a different `lua_State`.  Luv will create a unique `uv_loop_t` for each state.  You can't share uv handles between states/loops.\n\n- [Luv docs](docs.md)\n- [Libuv docs](http://docs.libuv.org/)\n\n```lua\nlocal uv = require('luv')\n\n-- Create a handle to a uv_timer_t\nlocal timer = uv.new_timer()\n\n-- This will wait 1000ms and then continue inside the callback\ntimer:start(1000, 0, function ()\n  -- timer here is the value we passed in before from new_timer.\n\n  print(\"Awake!\")\n\n  -- You must always close your uv handles or you'll leak memory\n  -- We can't depend on the GC since it doesn't know enough about libuv.\n  timer:close()\nend)\n\nprint(\"Sleeping\")\n\n-- uv.run will block and wait for all events to run.\n-- When there are no longer any active handles, it will return\nuv.run()\n```\n\n\nHere is an example of an TCP echo server\n```lua\nlocal uv = require('luv')\n\nlocal function create_server(host, port, on_connection)\n\n  local server = uv.new_tcp()\n  server:bind(host, port)\n\n  server:listen(128, function(err)\n    -- Make sure there was no problem setting up listen\n    assert(not err, err)\n\n    -- Accept the client\n    local client = uv.new_tcp()\n    server:accept(client)\n\n    on_connection(client)\n  end)\n\n  return server\nend\n\nlocal server = create_server(\"0.0.0.0\", 0, function (client)\n\n  client:read_start(function (err, chunk)\n\n    -- Crash on errors\n    assert(not err, err)\n\n    if chunk then\n      -- Echo anything heard\n      client:write(chunk)\n    else\n      -- When the stream ends, close the socket\n      client:close()\n    end\n  end)\nend)\n\nprint(\"TCP Echo server listening on port \" .. server:getsockname().port)\n\nuv.run()\n```\n\nMore examples can be found in the [examples](examples) and [tests](tests) folders.\n\n## Luarocks\n\nLuv is available on Luarocks [here](https://luarocks.org/modules/creationix/luv). It can be installed via:\n\n```\nluarocks install luv\n```\n\nNote: To require `luv` using `require 'uv'` (to maintain compatibility with how luv is required in [luvi](https://github.com/luvit/luvi)) create a `uv.lua` with the contents:\n```\nreturn require 'luv'\n```\n\n## Building From Source\n\nTo build, first install your compiler tools.\n\n### Get a Compiler\n\nOn linux this probably means `gcc` and `make`.  On Ubuntu, the `build-essential`\npackage is good for this.\n\nOn OSX, you probably want XCode which comes with `clang` and `make` and friends.\n\nFor windows the free Visual Studio Express works.  If you get the 2013 edition,\nmake sure to get the `Windows Desktop` edition.  The `Windows` version doesn't\ninclude a working C compiler.  Make sure to run all of setup including getting a\nfree license.\n\n### Install CMake\n\nNow install Cmake.  The version in `brew` on OSX or most Linux package managers\nis good.  The version on Travis CI is too old and so I use a PPA there.  On\nwindows use the installer and make sure to add cmake to your command prompt\npath.\n\n### Install Git\n\nIf you haven't already, install git and make sure it's in your path.  This comes\nwith XCode on OSX.  On Linux it's in your package manager.  For windows, use the\ninstaller at \u003chttp://git-scm.com\u003e.  Make sure it's available to your windows\ncommand prompt.\n\n### Clone the Code\n\nNow open a terminal and clone the code.  For windows I recommend the special\ndeveloper command prompt that came with Visual Studio.\n\n```\ngit clone https://github.com/luvit/luv.git --recursive\ncd luv\n```\n\n### Build the Code and Test\n\nOn windows I wrote a small batch file that runs the correct cmake commands and\ncopies the output files for easy access.\n\n```\nC:\\Code\\luv\u003e msvcbuild.bat\nC:\\Code\\luv\u003e luajit tests\\run.lua\n```\n\nOn unix systems, use the Makefile.\n\n```\n~/Code/luv\u003e make test\n```\n\nThis will build luv as a module library. Module libraries are plugins that are\nnot linked into other targets.\n\n#### Build with PUC Lua 5.4\nBy default luv is linked with LuaJIT 2.1.0-beta3. If you rather like to link luv\nwith PUC Lua 5.4 you can run make with:\n\n```\n~/Code/luv\u003e WITH_LUA_ENGINE=Lua make\n```\n\n#### Build as static library\n\nIf you want to build luv as a static library run make with:\n\n```\n~/Code/luv\u003e BUILD_MODULE=OFF BUILD_STATIC_LIBS=ON make\n```\n\nThis will create a static library `libluv_a.a`.\n\n#### Build as shared library\n\nIf you want to build luv as a shared library run make with:\n\n```\n~/Code/luv\u003e BUILD_MODULE=OFF BUILD_SHARED_LIBS=ON make\n```\n\nThis will create a shared library `libluv.so`.\n\n#### Build with shared libraries\n\nBy default the build system will build luv with the supplied dependencies.\nThese are:\n  * libuv\n  * LuaJIT or Lua\n\nHowever, if your target system has already one or more of these dependencies\ninstalled you can link `luv` against them.\n\n##### Linking with shared libuv\n\nThe default shared library name for libuv is `libuv`. To link against it use:\n\n```\n~/Code/luv\u003e WITH_SHARED_LIBUV=ON make\n```\n\n##### Linking with shared LuaJIT\n\nThe default shared library name for LuaJIT is `libluajit-5.1`. To link against\nit use:\n\n```\n~/Code/luv\u003e LUA_BUILD_TYPE=System make\n```\n\n##### Linking with shared Lua 5.x\n\nThe default shared library name for Lua 5.x is `liblua5.x`. To link against\nit use:\n\n```\n~/Code/luv\u003e LUA_BUILD_TYPE=System WITH_LUA_ENGINE=Lua make\n```\n","funding_links":[],"categories":["C"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluvit%2Fluv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluvit%2Fluv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluvit%2Fluv/lists"}