lualist.indexof
lualist.indexof
lualist.indexof(lista, searchitem, [func] )
- lista
- (tipo lista) lista in input
- searchitem
- (tipo qualsiasi) elemento da cercare
- func
- (tipo funzione) Funzione di test
Cerca un elemento in una lista (sequenza). Restituisce l'indice dell'elemento (se trovato) oppure nil.
lst = {"gennaio", "febbraio", "marzo", "aprile"}
function isPluto(el) return el == "pluto" end function
iniziacon(str, pref) return 0 == stricmp(str, pref, strlen(pref))
end print(lualist.indexof(lst, "Dic"), "\n") -- restituisce NIL
print(lualist.indexof(lst, "MArzo"), "\n") -- 3
print(lualist.indexof(lst, "FEB", iniziacon), "\n") -- restituisce 2
Esempio 1. Esempio lualist.indexof
-- NON implementato in v28 — usare questa alternativa:
local function indexof(lst, val)
for i, v in lst do if v == val then return i end end
return nil
end
print("\n" .. tostring(indexof({"A","B","C"}, "B"))) -- 2