3fe4471e
zhouhaihai
热更新 demo
|
1
2
3
4
5
6
7
|
local skynet = require "skynet"
local sharedata = require "skynet.sharedata"
local codecache = require "skynet.codecache" -- 清空缓存用
local _M = {}
|
5e5d7680
zhouhaihai
热更新 优化
|
8
|
-- 清空缓存
|
3fe4471e
zhouhaihai
热更新 demo
|
9
10
11
12
13
14
|
function _M.clearcache(query, body)
skynet.error(string.format("clearcache time: %s", skynet.timex()))
codecache.clear()
return 'success'
end
|
5e5d7680
zhouhaihai
热更新 优化
|
15
16
17
18
19
20
21
|
--重新加载 需要修改的csvdb
--[=[ eg:
body = """
csvdb["itemCsv"][1]["name"] = "测试一下"
"""
]=]
|
3fe4471e
zhouhaihai
热更新 demo
|
22
|
function _M.reload_csvdata(query, body)
|
5e5d7680
zhouhaihai
热更新 优化
|
23
24
|
if not body or body == "" then
return
|
3fe4471e
zhouhaihai
热更新 demo
|
25
|
end
|
3fe4471e
zhouhaihai
热更新 demo
|
26
|
|
5e5d7680
zhouhaihai
热更新 优化
|
27
28
|
local ok = pcall(load, body)
if not ok then return end
|
3fe4471e
zhouhaihai
热更新 demo
|
29
|
|
5e5d7680
zhouhaihai
热更新 优化
|
30
31
32
33
34
35
|
skynet.error(string.format("reload_csvdata time: %s, code: %s", skynet.timex(), body))
local status = skynet.call('CSVDATA', "lua", "reload", body)
if status == "ok" then
return 'success'
end
|
3fe4471e
zhouhaihai
热更新 demo
|
36
37
38
39
40
41
|
end
-- 热更新代码 -- 针对 agent 执行发送过来的代码 -- 代码要规范~
--[=[ eg:
|
5e5d7680
zhouhaihai
热更新 优化
|
42
43
44
45
46
47
48
49
|
1. *Action
body = """
_hotfixActions = _hotfixActions or {}
_hotfixActions["Gm.clientRequest"] = function(agent, data)
bin = MsgPack.pack({ cmd = "testtest" })
SendPacket(actionCodes.Gm_receiveResponse, bin)
end
"""
|
3fe4471e
zhouhaihai
热更新 demo
|
50
51
52
53
54
55
|
2. 修改 global 方法 和 变量 直接覆盖
body = """
function a()
print(123)
end
|
5e5d7680
zhouhaihai
热更新 优化
|
56
57
58
59
|
globalCsv["asdasd"] = 12
HEHE = 123
|
3fe4471e
zhouhaihai
热更新 demo
|
60
61
|
"""
|
5e5d7680
zhouhaihai
热更新 优化
|
62
|
3. 修改 role 方法(待定)
|
3fe4471e
zhouhaihai
热更新 demo
|
63
64
|
body = """
|
5e5d7680
zhouhaihai
热更新 优化
|
65
|
|
3fe4471e
zhouhaihai
热更新 demo
|
66
67
68
69
70
71
72
|
"""
]=]
function _M.hotfix(query, body)
if not body or body == "" then
return
end
|
3fe4471e
zhouhaihai
热更新 demo
|
73
74
|
local ok = pcall(load, body)
if not ok then return end
|
5e5d7680
zhouhaihai
热更新 优化
|
75
76
77
|
skynet.error(string.format("hotfix time: %s, code: %s", skynet.timex(), body))
|
3fe4471e
zhouhaihai
热更新 demo
|
78
79
80
81
82
83
84
85
|
pcall(skynet.call, 'WATCHDOG', "lua", "hotfix", body)
return 'success'
end
return _M
|