I'm Hanchin Hsieh, a developer passionate about FOSS, and a big Fan of LiSA(織部 里沙). You can ask me about Go, CloudNative, Nvim, and Asahi Linux.
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.
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:
local boot = require("ltask.bootstrap")boot.searchpath() to find embedded Lua modulesboot.dofile() to load the main bootstrap modulebootstrap.start() with configurationbootstrap.wait() to keep the system runningServices are configured through the bootstrap process. The loading behavior is completely customizable via initfunc:
Different examples show different initfunc implementations:
ltask.searchpath and ltask.loadfile for embedded servicespackage.searchpath and loadfile for external servicesExplore 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.