A Go implementation of cloudwu/ltask - a Lua task library with n:m scheduler that enables running M Lua VMs on N OS threads.
This library is currently working in progress 🚧. APIs are not stable and may undergo breaking changes. It is not recommended for production use at this time.
- N:M Scheduler: Run multiple Lua VMs efficiently across OS threads
- Bootstrap Architecture: Proper service initialization through bootstrap process
- Embedded Lua Runtime: Built-in Lua support with embedded glue code
- Service Management: Lightweight service model for concurrent tasks
- Cross-Platform: Works on Windows, Linux, and macOS
go get go.yuchanns.xyz/ltaskltask-go follows the bootstrap pattern used in the test files. Create a main Lua file that requires the bootstrap module and starts the system:
-- main.lua
local start = require("test.start")
start({
core = {
worker = 3, -- Number of worker threads
-- debuglog = "=", -- Uncomment for debug output
},
service_path = "service/?.lua", -- Service search path
bootstrap = {
{
name = "timer",
unique = true,
builtin = true,
},
{
name = "logger",
unique = true,
builtin = true,
},
{
name = "my_service", -- Your custom service
unique = false,
}
}
})Create a service file. The service path is configurable in the bootstrap setup:
-- service/my_service.lua
local ltask = require "ltask"
local my_service = {}
function my_service.echo(message)
print("Service received:", message)
return "Echo: " .. message
end
function my_service.ping()
return "pong"
end
return my_serviceThe service will be automatically loaded when referenced in the bootstrap configuration.
ltask-go requires a proper bootstrap sequence:
- Require bootstrap:
local boot = require("ltask.bootstrap") - Search embedded files: Use
boot.searchpath()to find embedded Lua modules - Load bootstrap:
boot.dofile()to load the main bootstrap module - Start system:
bootstrap.start()with configuration - Wait for completion:
bootstrap.wait()to keep the system running
Services are configured through the bootstrap process. The loading behavior is completely customizable via initfunc:
- unique: Whether only one instance is allowed
- service_path: Where to search for service files
- initfunc: Custom function to control how services are loaded (completely flexible)
Different examples show different initfunc implementations:
- Root test: Uses
ltask.searchpathandltask.loadfilefor embedded services - Sokol example: Uses standard
package.searchpathandloadfilefor external services
Explore the provided examples for proper usage patterns:
test.lua- Main test entry pointtest/start.lua- Bootstrap implementationtest/user.lua- Example service implementationexamples/- Application examples, such as sokol-integration
# Clone the repository and submodules
git clone --recurse-submodules https://github.com/yuchanns/ltask-go
git clone --recurse-submodules https://github.com/yuchanns/lua
go work init
go work use ./ltask-go
go work use ./lua
# Build Lua library
cd lua && luamake && cd -
# Run tests
cd ltask-go && go test -v ./...This project is a Go rewrite of cloudwu/ltask, originally created by 云风.
Apache License 2.0 - see LICENSE for details.