mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-22 02:53:09 +00:00
add skynet.pcall for hotfix use (call a function with require)
This commit is contained in:
@@ -5,6 +5,9 @@ skynet.start(function()
|
||||
local sdb = skynet.newservice("simpledb")
|
||||
skynet.name(".simpledb", sdb)
|
||||
print(skynet.call(".simpledb", "lua", "SET", "a", "foobar"))
|
||||
print(skynet.call(".simpledb", "lua", "SET", "b", "foobar2"))
|
||||
print(skynet.call(".simpledb", "lua", "GET", "a"))
|
||||
print(skynet.call(".simpledb", "lua", "GET", "b"))
|
||||
cluster.open "db"
|
||||
cluster.open "db2"
|
||||
end)
|
||||
|
||||
@@ -5,4 +5,5 @@ skynet.start(function()
|
||||
local proxy = cluster.proxy("db", ".simpledb")
|
||||
print(skynet.call(proxy, "lua", "GET", "a"))
|
||||
print(cluster.call("db", ".simpledb", "GET", "a"))
|
||||
print(cluster.call("db2", ".simpledb", "GET", "b"))
|
||||
end)
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
db = "127.0.0.1:2528"
|
||||
db2 = "127.0.0.1:2529"
|
||||
|
||||
@@ -620,8 +620,10 @@ end
|
||||
local function init_all()
|
||||
local funcs = init_func
|
||||
init_func = nil
|
||||
for k,v in pairs(funcs) do
|
||||
v()
|
||||
if funcs then
|
||||
for k,v in pairs(funcs) do
|
||||
v()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -632,8 +634,12 @@ local function init_template(start)
|
||||
init_all()
|
||||
end
|
||||
|
||||
function skynet.pcall(start)
|
||||
return xpcall(init_template, debug.traceback, start)
|
||||
end
|
||||
|
||||
local function init_service(start)
|
||||
local ok, err = xpcall(init_template, debug.traceback, start)
|
||||
local ok, err = skynet.pcall(start)
|
||||
if not ok then
|
||||
skynet.error("init service failed: " .. tostring(err))
|
||||
skynet.send(".launcher","lua", "ERROR")
|
||||
|
||||
@@ -49,7 +49,7 @@ end
|
||||
|
||||
function dbgcmd.RUN(source, filename)
|
||||
local inject = require "skynet.inject"
|
||||
local output = inject(source, filename , export.dispatch, skynet.register_protocol)
|
||||
local output = inject(skynet, source, filename , export.dispatch, skynet.register_protocol)
|
||||
collectgarbage "collect"
|
||||
skynet.ret(skynet.pack(table.concat(output, "\n")))
|
||||
end
|
||||
|
||||
@@ -18,7 +18,7 @@ local function getupvaluetable(u, func, unique)
|
||||
end
|
||||
end
|
||||
|
||||
return function(source, filename , ...)
|
||||
return function(skynet, source, filename , ...)
|
||||
if filename then
|
||||
filename = "@" .. filename
|
||||
else
|
||||
@@ -56,7 +56,7 @@ return function(source, filename , ...)
|
||||
if not func then
|
||||
return { err }
|
||||
end
|
||||
local ok, err = xpcall(func, debug.traceback)
|
||||
local ok, err = skynet.pcall(func)
|
||||
if not ok then
|
||||
table.insert(output, err)
|
||||
end
|
||||
|
||||
@@ -44,7 +44,7 @@ function CMD.new(name, t)
|
||||
elseif dt == "string" then
|
||||
value = setmetatable({}, env_mt)
|
||||
local f = load(t, "=" .. name, "t", value)
|
||||
f()
|
||||
assert(skynet.pcall(f))
|
||||
setmetatable(value, nil)
|
||||
elseif dt == "nil" then
|
||||
value = {}
|
||||
|
||||
Reference in New Issue
Block a user