lua lanes多线程使用

local TimeInstance = require("timer_instance") local cjson = require("cjson")

local demo ={}

function demo.new() local obj = {} obj.state = "running" obj.value = {"elliot", "starier"} setmetatable(obj, {__index = demo}) return obj end

function demo:fire_thread_func() print("xxxxxxxxxx") print(self.state) self:print_log() end

function demo:print_log() local json = cjson.encode(self.value) print("start elliot test") end

function error_handeling() print("Error thread") end

local obj = demo.new() local threadobj = TimeInstance.new(2, obj.fire_thread_func, "fire_thread_func_timer_xxxxx", error_handeling, true, "fire_thread_func") threadobj:start(obj)

////////////////////// timer_instance.lua 中,我在start的时候用 self.thread = lanes.gen("*",{ globals = global_varibles._G, required = {"socket","cjson"} }, self.run)(self,thread_id, obj) 并且我的self.run 函数里面通过 local status, ex = pcall(self.fire_func,pcall_obj) self.fire_func这个函数就是我传进去的obj.fire_thread_func 函数 但是会报错lanes.lua:330: function '_G/package/loaded/cjson/encode_number_precision' not found in main origin transfer database. 我不知道是不是required用的不对导致的,因为看文档说能给子线程加载需要的库。

希望能得到答案

点赞