使用断言
assert()宏是用于保证满足某个特定条件,用法是:
assert(表达式);
如果表达式的值为假,整个程序将退出,并输出一条错误信息。如果表达式的值为真则继续执行后面的语句。、
function skynet.watch(service)
assert(type(service) == "number") -- 如果service不是number类型,则终止运行
if(watch_monitor == nil then
watch_monitor = string_to_handle(c.command("MONITOR"))
assert(watch_monitor,"Need a monitor")
end
if watching_service[service] == nil then
watching_service[service] = true
--read lualib/simplemonitor.lua
assert(skynet.call(watch_monitor,"lua","WATCH",service),"watch a dead service")
end
end