public override Task <LuaArguments> CallAsync(Engine engine, LuaArguments args, CancellationToken token = default) { var first = args[0]; if (first.IsNil()) { throw new LuaException("bad argument #1"); } var instance = (ICallableProxy)first.ToObject(); return(instance.CallAsync(Lua.Args(args.Skip(1)), token)); }
public override async Task <LuaArguments> CallAsync(Engine engine, LuaArguments args, CancellationToken token = default) { var context = new LuaTableFunction(Context, _useParent); // Set the arguments. var i = 0; for (; i < _definition.Arguments.Count; i++) { context.NewIndexRaw(_definition.Arguments[i].Name, args[i]); } if (_definition.Varargs) { context.Varargs = args.Skip(i).ToArray(); } // Execute the statements. var state = new LuaState(engine, context); await engine.ExecuteStatement(_definition.Body, state, token); return(state.FunctionState.ReturnArguments); }
public static Task Throws(Engine engine, LuaObject obj, LuaArguments args) { return(Assert.ThrowsAsync <LuaException>(() => obj.CallAsync(engine, Lua.Args(args.Skip(1))))); }
public static LuaArguments Min(LuaArguments args) { var min = args.Skip(1).Aggregate(args[0], (current, o) => Math.Min(current, o)); return(Lua.Args(min)); }
public static LuaArguments Max(LuaArguments args) { var max = args.Skip(1).Aggregate(args[0], (current, o) => Math.Max(current, o)); return(Lua.Args(max)); }
public static string Format(LuaArguments args) { return(InternalStringUtils.Sprintf(args[0].AsString(), args.Skip(1).Select(i => i.ToObject()).ToArray())); }