其他分享
首页 > 其他分享> > skynet:给debug console添加搜索功能

skynet:给debug console添加搜索功能

作者:互联网

skynet:给debug console添加搜索功能

为什么要给skynet的debug console添加搜索功能?

实现搜索命令ag

local function get_all_list(key_string)
    local table_list={}
    local all_services = skynet.call(".launcher", "lua", "LIST")
    local count = 0
    for k,v in pairs(all_services) do
        if string.match(k, key_string) or string.match(v, key_string) then
            table_list[k] = v
            count = count + 1
        end
    end
    table_list["total_count"] = count
    return table_list
end

function COMMAND.ag(key_string)
    if key_string == nil then
        skynet.error("ag nil string:")
        return nil
    end
    skynet.error("ag:",key_string)
    return get_all_list(key_string)
end
ag vip
:0000003b       snlua vip_service
:0000003c       snlua vip_agent 1
total_count     2
<CMD OK>
ag 3b
:0000003b       snlua vip_service
total_count     1
<CMD OK>

标签:count,console,string,ag,list,key,debug,skynet
来源: https://blog.csdn.net/cfanzp/article/details/122683875