conlang-heonian/search_list.lua
2022-03-24 21:47:24 +01:00

62 lines
1.3 KiB
Lua

function searchList(query)
results_table = {}
local skip_regular = false
for _, v in pairs(arg) do
if v == "-i" or v == "--id" then
skip_regular = true
local id = tonumber(query)
if words[id] then
local word = {id,words[id]}
table.insert(results_table,word)
end
break
end
end
for i=1, #words do
if skip_regular then break end
local exit = true
local all = true
for _, v in pairs(arg) do
if v == "-r" or v == "--raw" then
all = false
word = string.gsub(words[i][1],"%p","")
if string.find(word, query) then
exit = false
break
end
end
if v == "-e" or v == "--english" then
all = false
word = string.gsub(words[i][2],"%p","")
if string.find(word, query) then
exit = false
break
end
end
end
if all == true then
for j=1, #words[i] do
word = string.gsub(words[i][j],"%p","")
if string.find(word, query) then
exit = false
break
end
end
end
if not exit then
local word = {i,words[i]}
table.insert(results_table,word)
end
end
if #results_table ~= 0 then
results_table = adjustTableSizes(results_table)
printOutputTable(results_table)
else
if skip_regular then
print("no word found for id #" .. query)
else
print("no words found for query <" .. query .. ">")
end
end
end