public Player[] GetPlayers(LuaFunction filter) { return Context.World.Players .Where(p => { using (var f = filter.Call(p.ToLuaValue(Context))) return f.First().ToBoolean(); }).ToArray(); }
public bool Any(LuaValue[] collection, LuaFunction func) { foreach (var c in collection) using (var ret = func.Call(c)) using (var result = ret.FirstOrDefault()) if (result != null && result.ToBoolean()) return true; return false; }
public LuaTable ActorsInCircle(WPos location, WRange radius, LuaFunction filter) { var actors = context.World.FindActorsInCircle(location, radius) .Select(a => a.ToLuaValue(context)) .Where(a => { using (var f = filter.Call(a)) return f.First().ToBoolean(); }); return actors.ToLuaTable(context); }
public LuaTable GetPlayers(LuaFunction filter) { var players = context.World.Players .Select(p => p.ToLuaValue(context)) .Where(a => { using (var f = filter.Call(a)) return f.First().ToBoolean(); }); return players.ToLuaTable(context); }
public bool All(LuaValue[] collection, LuaFunction func) { foreach (var c in collection) { using (var ret = func.Call(c)) { var result = ret.FirstOrDefault(); if (result == null || !result.ToBoolean()) return false; } } return true; }
public bool Any(LuaTable table, LuaFunction func) { foreach (var kv in table) { using (var ret = func.Call(kv.Value)) { var result = ret.FirstOrDefault(); if (result != null && result.ToBoolean()) return true; } } return false; }
public Actor[] ActorsInBox(WPos topLeft, WPos bottomRight, LuaFunction filter = null) { var actors = Context.World.ActorMap.ActorsInBox(topLeft, bottomRight); if (filter != null) { actors = actors.Where(a => { using (var f = filter.Call(a.ToLuaValue(Context))) return f.First().ToBoolean(); }); } return actors.ToArray(); }
public Actor[] ActorsInCircle(WPos location, WDist radius, LuaFunction filter = null) { var actors = Context.World.FindActorsInCircle(location, radius); if (filter != null) { actors = actors.Where(a => { using (var f = filter.Call(a.ToLuaValue(Context))) return f.First().ToBoolean(); }); } return actors.ToArray(); }
public void Do(LuaValue[] collection, LuaFunction func) { foreach (var c in collection) func.Call(c).Dispose(); }
void Execute(string cmd, string args, LuaFunction filter) { var handleOutput = new Action<string, CommandOutput>( (text, command) => { // Clean up new lines in the end of the string. if (text.EndsWith(Environment.NewLine)) text = text.Replace(Environment.NewLine, string.Empty); command.Raw.Add(text); if (filter == null) goto SkipFilter; var result = filter.Call(text); if (result.Count == 0) return; text = result[0].ToString(); SkipFilter: command.Lines.Add(text); Build.Output.WriteLine(text); }); ExecuteProcess(cmd, args, handleOutput); }
void BuildStep(string name, LuaFunction step) { Output.PushGroup("Build step '{0}'", name); step.Call(); Output.PopGroup(); }
private static void RunCode(LuaFunction function) { try { function.Call(); } catch (Exception ex) { throw new BuildException("Error in Lua script: " + ex.ToString()); } }
public void Do(LuaTable table, LuaFunction func) { foreach (var kv in table) func.Call(kv.Value).Dispose(); }
public LuaTable Where(LuaValue[] collection, LuaFunction func) { var t = Context.CreateTable(); foreach (var c in collection) using (var ret = func.Call(c)) using (var result = ret.FirstOrDefault()) if (result != null && result.ToBoolean()) t.Add(t.Count + 1, c); return t; }