mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-22 02:53: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 sproto_mt = { __index = sproto }
|
||||
local sproto_nogc = { __index = sproto }
|
||||
local host_mt = { __index = host }
|
||||
|
||||
function sproto_mt:__gc()
|
||||
core.deleteproto(self.__cobj)
|
||||
end
|
||||
|
||||
function sproto.new(...)
|
||||
local cobj = assert(core.newproto(...))
|
||||
function sproto.new(bin,sz,nogc)
|
||||
local cobj = assert(core.newproto(bin,sz))
|
||||
local self = {
|
||||
__cobj = cobj,
|
||||
__tcache = setmetatable( {} , weak_mt ),
|
||||
__pcache = setmetatable( {} , weak_mt ),
|
||||
}
|
||||
return setmetatable(self, sproto_mt)
|
||||
return setmetatable(self, nogc and sproto_nogc or sproto_mt)
|
||||
end
|
||||
|
||||
function sproto.parse(ptext)
|
||||
|
||||
@@ -16,7 +16,8 @@ loader.save = core.saveproto
|
||||
|
||||
function loader.load(index)
|
||||
local bin, sz = core.loadproto(index)
|
||||
return sproto.new(bin,sz)
|
||||
-- no __gc in metatable
|
||||
return sproto.new(bin,sz, true)
|
||||
end
|
||||
|
||||
return loader
|
||||
|
||||
Reference in New Issue
Block a user