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','peach'} 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