一个基于C++17的Lua多任务调度库!。
- msvc: 准备好lua依赖库并放到指定位置,将proj文件加到sln后编译。
- linux: 准备好lua依赖库并放到指定位置,执行make -f lworker.mak
- mimalloc: 参考quanta使用,不用则在工程文件中注释
--主线程
--worker_test.lua
import("lua/scheduler.lua")
local log_err = logger.err
local log_debug = logger.debug
local scheduler = quanta.get("scheduler")
local timer_mgr = quanta.get("timer_mgr")
scheduler:setup("quanta")
scheduler:startup("wtest", "wtest")
timer_mgr:loop(2000, function()
local ok, res1, res2 = scheduler:call("wtest", "test_rpc", 1, 2, 3, 4)
if not ok then
log_err("[scheduler][call] call failed: %s", res1)
return
end
log_debug("[scheduler][call] call success: %s, %s", res1, res2)
end)
--任务线程
--wtest.lua
import("lua/worker.lua")
local log_debug = logger.debug
local event_mgr = quanta.get("event_mgr")
local WorkerTest = class()
function WorkerTest:__init()
event_mgr:add_listener(self, "test_rpc")
end
function WorkerTest:test_rpc(a, b, c, d)
log_debug("[WorkerTest][test_rpc] %s, %s, %s, %s", a, b, c, d)
return a + b, c + d
end
quanta.startup(function()
quanta.qtest1 = WorkerTest()
end)