mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 12:43:09 +00:00
don't delete sproto object when share it
This commit is contained in:
@@ -6,20 +6,21 @@ local host = {}
|
|||||||
|
|
||||||
local weak_mt = { __mode = "kv" }
|
local weak_mt = { __mode = "kv" }
|
||||||
local sproto_mt = { __index = sproto }
|
local sproto_mt = { __index = sproto }
|
||||||
|
local sproto_nogc = { __index = sproto }
|
||||||
local host_mt = { __index = host }
|
local host_mt = { __index = host }
|
||||||
|
|
||||||
function sproto_mt:__gc()
|
function sproto_mt:__gc()
|
||||||
core.deleteproto(self.__cobj)
|
core.deleteproto(self.__cobj)
|
||||||
end
|
end
|
||||||
|
|
||||||
function sproto.new(...)
|
function sproto.new(bin,sz,nogc)
|
||||||
local cobj = assert(core.newproto(...))
|
local cobj = assert(core.newproto(bin,sz))
|
||||||
local self = {
|
local self = {
|
||||||
__cobj = cobj,
|
__cobj = cobj,
|
||||||
__tcache = setmetatable( {} , weak_mt ),
|
__tcache = setmetatable( {} , weak_mt ),
|
||||||
__pcache = setmetatable( {} , weak_mt ),
|
__pcache = setmetatable( {} , weak_mt ),
|
||||||
}
|
}
|
||||||
return setmetatable(self, sproto_mt)
|
return setmetatable(self, nogc and sproto_nogc or sproto_mt)
|
||||||
end
|
end
|
||||||
|
|
||||||
function sproto.parse(ptext)
|
function sproto.parse(ptext)
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ loader.save = core.saveproto
|
|||||||
|
|
||||||
function loader.load(index)
|
function loader.load(index)
|
||||||
local bin, sz = core.loadproto(index)
|
local bin, sz = core.loadproto(index)
|
||||||
return sproto.new(bin,sz)
|
-- no __gc in metatable
|
||||||
|
return sproto.new(bin,sz, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
return loader
|
return loader
|
||||||
|
|||||||
Reference in New Issue
Block a user