Lua中判断值是否在table里面

在Python中可以判断某个值是否列表里面,在Lua中也可以实现

ip_table = {'192.168.10.133','192.168.10.135'}

function isintable(value,tb)
    for k,v in pairs(tb) do
        if v == value then
            return true
        end
    end
    return false    --重点:全部跑完以后,如果非true,则返回false
end


print(isintable('192.168.10.133',ip_table))

结果为:
True     

  

  

原文地址:https://www.cnblogs.com/lucktomato/p/15234626.html