Luna is a modern framework for creating high-performance servers in Lua (5.1/LuaJIT) with a simple and elegant API. The Lunac client provides convenient server interaction. Open source - Luna is released under the MIT license.
Luna provides all the necessary tools for creating modern server applications in Lua
Optimized code for Lua 5.1 and LuaJIT delivers maximum request processing speed up to 40,000 requests per second.
The Lunac client allows easy server connection and request sending with minimal code.
Automatic request parameter validation and DDoS protection.
Powerful routing system with support for prefixes and nested routers.
Support for asynchronous requests via noawait_fetch and synchronous via fetch.
Easily integrates with popular frameworks including LÖVE, Solar2d.
A simple server and client written using Luna and Lunac
-- Initializing Luna server and Lunac client
local luna, lunac
function love.load()
-- Loading server library
luna = require("luna")
-- Creating a new server application
local app = luna.new_app({
host = "127.0.0.1",
port = 8081,
name = "test server",
max_ip_connected = 20,
no_errors = true,
})
-- Creating main router with 'api' prefix
local main_router = app:new_router({
prefix = "api",
})
-- Creating /api/echo endpoint
main_router:new({
validate = {text = {"string","nil"}},
responce_validate = {"string"},
prefix = "echo",
fun = function(args, client)
return args.text or "no text provided"
end
})
-- Loading client library
lunac = require("lunac")
_G.client = lunac.connect_to_app({
host = "127.0.0.1",
port = 8081,
name = "test server",
no_errors = true,
server = luna,
listener = function (message)
print("New message client:send ", message)
end
})
-- Asynchronous request
client:noawait_fetch("api/echo", function(data, err) end, {text = "hello world"})
-- Synchronous request
local response = client:fetch("api/echo", {text = "hello world"})
print("Echo data: "..response)
end
function love.update(dt)
-- Updating server and client
luna.update(dt)
lunac.update(dt)
end