diff --git a/lualib-src/lua-sharetable.c b/lualib-src/lua-sharetable.c index 0dbb5256..f45086d9 100644 --- a/lualib-src/lua-sharetable.c +++ b/lualib-src/lua-sharetable.c @@ -54,6 +54,17 @@ mark_shared(lua_State *L) { } } +static int +lis_sharedtable(lua_State* L) { + int b = 0; + if(lua_type(L, 1) == LUA_TTABLE) { + Table * t = (Table *)lua_topointer(L, 1); + b = isshared(t); + } + lua_pushboolean(L, b); + return 1; +} + static int make_matrix(lua_State *L) { // turn off gc , because marking shared will prevent gc mark. @@ -212,6 +223,7 @@ luaopen_skynet_sharetable_core(lua_State *L) { luaL_Reg l[] = { { "clone", clone_table }, { "matrix", matrix_from_file }, + { "is_sharedtable", lis_sharedtable }, { NULL, NULL }, }; luaL_newlib(L, l); diff --git a/lualib/skynet/sharetable.lua b/lualib/skynet/sharetable.lua index d5db143d..208e035d 100644 --- a/lualib/skynet/sharetable.lua +++ b/lualib/skynet/sharetable.lua @@ -1,6 +1,7 @@ local skynet = require "skynet" local service = require "skynet.service" local core = require "skynet.sharetable.core" +local is_sharedtable = core.is_sharedtable local function sharetable_service() local skynet = require "skynet" @@ -218,6 +219,7 @@ local getupvalue = debug.getupvalue local setupvalue = debug.setupvalue local getlocal = debug.getlocal local setlocal = debug.setlocal +local getinfo = debug.getinfo local NILOBJ = {} local function insert_replace(old_t, new_t, replace_map) @@ -257,7 +259,7 @@ local function resolve_replace(replace_map) assert(v ~= nil) local tv = type(v) local f = match[tv] - if record_map[v] then + if record_map[v] or is_sharedtable(v) then return end @@ -339,14 +341,14 @@ local function resolve_replace(replace_map) end local function match_function(f) - local info = debug.getinfo(f) + local info = getinfo(f, "uf") match_funcinfo(info) end local function match_thread(co) local level = 1 while true do - local info = debug.getinfo(co, level) + local info = getinfo(co, level, "uf") if not info then break end