public List<ModSearchUnitResult> SearchUnits(string text, bool useLua)
{
var res = new List<ModSearchUnitResult>();
if (!useLua) {
var words = text.ToLower().Split(new[] {' ', '\r', '\n'}, StringSplitOptions.RemoveEmptyEntries);
foreach (DictionaryEntry de in Units) {
bool hasWords = true;
foreach (var w in words) if (!HasWord((LuaTable) de.Value, w)) hasWords = false;
if (hasWords) res.Add(new ModSearchUnitResult((LuaTable) de.Value));
}
} else {
var ret = lua.DoString(string.Format(@"local function Funct(Unit) {0}
end
local res = {{}}
for k,v in pairs(Units) do if (Funct(v)) then table.insert(res, v) end end
return res", text));
var rettab = (LuaTable) ret[0];
foreach (DictionaryEntry de in rettab) res.Add(new ModSearchUnitResult((LuaTable) de.Value));
}
res.Sort(delegate(ModSearchUnitResult a, ModSearchUnitResult b) { return a.id.CompareTo(b.id); });
return res;
}