-
-
Save rphillips/bf14ef35e54c5789a173 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Luvit is a port of the NodeJS API to Luajit leveraging the same cross-platform library from NodeJS called libuv. The main goals in Luvit are to provide these bindings with high performance and low memory usage. A typical Node process may be around 30 or more megabytes, while a Luvit process will start at around 1.2 megabytes (smaller if the tiny Luvi binary is used). Because of this small footprint, Luvit is perfect for embedded projects (Raspberry Pi, BeagleBone, custom hardware, etc) or other projects where memory usage is sensitive. | |
## What does Luvit look like? | |
HTTP Server: | |
```lua | |
local http = require("http") | |
http.createServer(function (req, res) | |
local body = "Hello world\n" | |
res:on("error", function(err) | |
msg = tostring(err) | |
print("Error while sending a response: " .. msg) | |
end) | |
res:writeHead(200, { | |
["Content-Type"] = "text/plain", | |
["Content-Length"] = #body | |
}) | |
res:finish(body) | |
end):listen(8080) | |
print("Server listening at http://localhost:8080/") | |
``` | |
HTTP Client: | |
```lua | |
local http = require('http') | |
local req = http.request({ | |
host = "luvit.io", | |
port = 80, | |
path = "/" | |
}, function (res) | |
res:on("error", function(err) | |
msg = tostring(err) | |
print("Error while receiving a response: " .. msg) | |
end) | |
res:on("data", function (chunk) | |
p("ondata", {chunk=chunk}) | |
end) | |
res:on("end", function () | |
res:destroy() | |
end) | |
end) | |
req:on("error", function(err) | |
msg = tostring(err) | |
print("Error while sending a request: " .. msg) | |
end) | |
req:done() | |
``` | |
## What is changing in Luvit2? | |
Luvit2 is making use of Luv and Luvi. Luv and Luvi can be used standalone if you want lowlevel access to libuv. Luvit2 will include the NodeJS-like APIs. | |
Luv is a barebones library binding libuv to Luajit (and eventually stock Lua to provide more portability). Luajit is able to load the resulting shared library directly, so applications can use the lowlevel libuv bindings if they wish. Luv can also be used in other applications, which is when Luvi comes into play. | |
Luvi is a cross-platform application (Linux, OSX, and Windows) that includes support for optional feature such as: SSL, glfw, and Windows service support. We are making this layer extremely customizable knowing that all projects have their own requirements. A great feature of Luvi is that it supports reading a bundled application from the filesystem or from a zip file appended onto the end of the executable. As you can expect, the development cycle becomes extremely streamlined and distribution of a final executable is a breeze. | |
Luvit2 is built on top of Luvi. We include prebuilt Luvi binaries within the Luvit tree so developers can target Windows and other platforms with ease. A compiler is not needed when developing on Luvit now. | |
## Contributing to Luvit2 | |
All code for Luvit is on Github. Let's begin by checking out the code and running the unit tests. | |
### OSX and Linux | |
```shell | |
git clone --recursive https://github.com/luvit/luvit --branch luvi-up | |
cd luvit | |
make | |
make test | |
``` | |
### Windows | |
```shell | |
git clone --recursive https://github.com/luvit/luvit --branch luvi-up | |
cd luvit | |
make.bat | |
luvit tests/run.lua | |
``` | |
## Contributing to Luvi | |
As I previously stated, Luvi is the core executable. There are optional components that can be included within the binary to taylor the executable to your needs. | |
```shell | |
git clone --recursive https://github.com/luvit/luvi.git | |
cd luvi | |
make static | |
make test | |
``` | |
## Contributing to Luv | |
The libuv bindings are found in Luv. If there is a bug fix or other feature you need from libuv this is the project to add it to. | |
### OSX and Linux | |
```shell | |
git clone --recursive https://github.com/luvit/luv.git | |
cd luv | |
make | |
make test | |
``` | |
### Windows | |
```shell | |
git clone --recursive https://github.com/luvit/luv.git | |
cd luv | |
msvcbuild.bat | |
luajit.exe tests\run.lua | |
``` | |
## Migration to CMake | |
We have migrated from the Gyp build system to CMake for Luv and Luvi. We feel CMake is more accessible to developers, removes the Python build dependency on the project, and the 'out-of-the-box' experience is easier to contend with. Even though we added a dependency with an executable, most platforms have CMake within their package distribution systems. So far we have been extremely impressed with the ease of use and quick turn around time with CMake. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment