Skip to content

Commit

Permalink
最终还原perl环境 pb 打包sharedata数据应注意先copy
Browse files Browse the repository at this point in the history
  • Loading branch information
huahua132 committed Jan 8, 2025
1 parent 791a0cf commit 0b7ff71
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
11 changes: 11 additions & 0 deletions install_centos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,24 @@ compile() {
)
}

# 还原perl环境
revert_perl() {
(
sudo mv /usr/bin/perl.old /usr/bin/perl && echo "revert perl successfully" || {
echo -e "\033[31m Failed to revert perl \033[0m"
exit 1
}
)
}

# 主程序
main() {
install_dependencies
install_perl
install_openssl
install_zlib
compile
revert_perl
}

main
19 changes: 19 additions & 0 deletions lualib/skynet-fly/sharedata.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@ local module_info = require "skynet-fly.etc.module_info"
local log = require "skynet-fly.log"
local file_util = require "skynet-fly.utils.file_util"
local string_util = require "skynet-fly.utils.string_util"
local table_util = require "skynet-fly.utils.table_util"

local sinterface = service_watch_interface:new(".sharedata_service")

----------------------------------------------
-- 使用注意点
-- 对于使用sharedata配置,被其他外部引用的表会被更新到,sharetable不会,所以如果想拿到最新的配置就必须用这个文件的`get_map,get_map_list,get_data_table`拿取
-- 对于不想更新到的表sharedata需要做个深拷贝
-- 直接用sharedata 的表数据传入pb,该部分数据打包不进去,需要深拷贝后导入
----------------------------------------------

local next = next
local assert = assert
local setmetatable = setmetatable
Expand Down Expand Up @@ -341,6 +349,17 @@ function M:builder()
return self
end

--[[
local cfg = {
items = {{id = 1, count = 2000}}
}
比如pb需要items,就只需要 M:copy_table(cfg.items)即可
]]
--copy 配置表 直接用sharedata 的表数据传入pb,该部分数据打包不进去,需要深拷贝后导入
function M:copy_table(tab)
return table_util.copy(tab)
end

--获取数据表
function M:get_data_table()
assert(self.is_builder, "not build can`t get_data_table")
Expand Down
13 changes: 13 additions & 0 deletions lualib/skynet-fly/utils/table_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,19 @@ function M.deep_copy(orig)
return copy_recursive(orig)
end

-- copy简单copy
function M.copy(tab)
local t = {}
for k, v in pairs(tab) do
if "table" ~= type(v) then
t[k] = v
else
t[k] = M.copy(v)
end
end
return t
end

-- 按深度元素转成list
function M.depth_to_list(tab, depth)
assert(depth > 0)
Expand Down

0 comments on commit 0b7ff71

Please sign in to comment.