Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
 public static Task Throws(Engine engine, LuaObject obj, LuaArguments args)
 {
     return(Assert.ThrowsAsync <LuaException>(() => obj.CallAsync(engine, Lua.Args(args.Skip(1)))));
 }
Exemplo n.º 4
0
        public static LuaArguments Min(LuaArguments args)
        {
            var min = args.Skip(1).Aggregate(args[0], (current, o) => Math.Min(current, o));

            return(Lua.Args(min));
        }
Exemplo n.º 5
0
        public static LuaArguments Max(LuaArguments args)
        {
            var max = args.Skip(1).Aggregate(args[0], (current, o) => Math.Max(current, o));

            return(Lua.Args(max));
        }
Exemplo n.º 6
0
 public static string Format(LuaArguments args)
 {
     return(InternalStringUtils.Sprintf(args[0].AsString(), args.Skip(1).Select(i => i.ToObject()).ToArray()));
 }