inList Is a value in a list

Description

Takes a value and a "flat" table and returns true if the value is in the list

Requires: None

Code

function inList(tblList,value)
    bRet = false
    for _,v in pairs(tblList) do
        if v == value then
            bRet = true
            break
        end
    end
    return bRet
end

Usage

tblList = {'orange','apple','banana'}
if inList(tblList,'orange') then
  print('we have an orange')
end
if not inList(tblList,'pear') then
  print('there is not a pear in the list')
end

Section plugins:code_snippets