Skip to content

sniper00/moon_rs

Repository files navigation

moon_rs

moon_rs is a Rust reimplementation of Moon: a lightweight, high-performance game server framework built around a Lua actor runtime on Tokio.

It keeps the original Moon model simple and scriptable, while moving scheduling, async I/O, memory control, and native integrations into Rust.

Why It Stands Out

  • Lua-first actor model: services communicate by typed message passing, keeping gameplay and service logic easy to script.
  • Tokio-powered runtime: Rust handles networking, timers, HTTP, database I/O, and concurrency under the hood.
  • Per-actor isolation: each actor owns its own lua_State, with support for regular actors and dedicated unique actors.
  • Practical native modules: HTTP client/server, WebSocket, Redis, PostgreSQL, SQLx, MongoDB, cluster, filesystem, JSON, buffer, random, and more.
  • Feature-gated build: optional modules can be compiled in or out through Cargo features.

Architecture At A Glance

flowchart LR
	A[Lua services] --> B[Typed messages]
	B --> C[moon-runtime]
	C --> D[Tokio runtime]
	D --> E[moon-modules]
	E --> F[Network\nSocket HTTP WebSocket]
	E --> G[Data\nRedis PG SQLx MongoDB]
	E --> H[Cluster and utils]
	C --> I[Per-actor lua_State]
	A --> J[lualib APIs]
Loading

Core Capabilities

Area What you get
Runtime Lua actors, typed messages, timers, logger, custom per-actor memory accounting
Concurrency Tokio multi-thread runtime plus dedicated execution for unique actors
Network TCP sockets, framing helpers, HTTP client, HTTP server, WebSocket
Data Redis, PostgreSQL protocol support, SQLx integration, MongoDB
Distributed Cluster module for node-to-node communication
Utility JSON, buffer, serialization, filesystem, random, sharetable, Excel/CSV helpers

Workspace Layout

Path Responsibility
crates/moon-app binary entry point, bootstrap, signal handling
crates/moon-runtime actor runtime, message types, timer, logger, shared context
crates/moon-modules Rust to Lua native bindings
crates/moon-lua embedded Lua 5.5 sources and Rust FFI
lualib/ user-facing Lua APIs and wrappers
assets/ examples, benchmarks, integration-style test scripts
docs/ module-focused documentation

Quick Start

moon_rs currently targets Rust nightly.

cargo build --release
cargo run --release -- assets/example/example.lua

Useful entry points:

# Example
cargo run --release -- assets/example/example_httpd.lua

# Benchmark
cargo run --release -- assets/benchmark/benchmark_send.lua

# Rust tests
cargo test

# Lua integration-style script
cargo run --release -- assets/test/test_socket.lua

Feature Flags

Default builds include:

excel, httpc, httpd, sqlx, mongodb, websocket, pg, redis, cluster

You can trim the binary or enable modules selectively with standard Cargo features.

Examples And Docs

  • Examples: assets/example/
  • Benchmarks: assets/benchmark/
  • Test scripts: assets/test/
  • Module docs: docs/socket.md, docs/httpc.md, docs/httpd.md, docs/redis.md, docs/pg.md, docs/sqlx.md, docs/mongodb.md, docs/cluster.md

Status

The project already includes a substantial runtime, networking stack, database integrations, and Lua-facing module surface. It is still evolving, but it is far beyond a placeholder port: the main value of the repository is a production-oriented architecture with an approachable scripting model.

License

MIT. See LICENSE.

About

A lightweight game server implemented in Rust and Lua

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors