Skip to content

colourlabs/lunar

Repository files navigation

lunar

A lightweight HTTP workers runtime for Lua built on asynchronous I/O.

Write request handlers in Lua and serve them using a high-performance event loop powered by libuv.

function handle(req)
    return {
        status = 200,
        headers = {
            ["Content-Type"] = "text/plain"
        },
        body = "Hello, " .. (req.query.name or "world")
    }
end

features

  • async runtime powered by libuv.
  • a secure sandbox with isolate architecture, each LuaState has it's own memory allocator and restricted API calls
  • fast secure HTTP parsing with llhttp.
  • lunar/json API that uses yyjson under the hood for extreme performance.
  • simple request/response API.
  • minimal dependencies

quick start

create hello.lua:

function handle(req)
    return {
        status = 200,
        headers = {
            ["Content-Type"] = "text/plain"
        },
        body = "Hello from Lunar!"
    }
end

run it:

./lunar hello.lua

then visit:

http://localhost:8080

request object

function handle(req)
    print(req.method)
    print(req.path)
    print(req.query.name)
end

response object

handlers return a Lua table describing the HTTP response:

return {
    status = 200,
    headers = {
        ["Content-Type"] = "application/json"
    },
    body = '{"ok":true}'
}

technology

lunar is built on:

  • libuv for asynchronous networking and the event loop
  • llhttp for HTTP/1.1 request parsing
  • lua 5.5 for application logic (forked to add sandbox limits and possibly performance improvements over stock 5.5)

building from source

git clone https://github.com/colourlabs/lunar
cd lunar

meson setup build
meson compile -C build

run a Lua worker:

./build/lunar hello.lua

status

lunar is currently under active development. APIs may change between releases.

About

A lightweight async workers runtime for Lua 5.5

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages