Ejemplo n.º 1
0
        static LuaObject EvalUnaryExpression(UnaryExpression Expression, LuaContext Context)
        {
            LuaObject obj = EvalExpression(Expression.Expression, Context)[0];

            switch (Expression.Operation)
            {
            case UnaryOp.Invert:
                return(-(obj.AsNumber()));

            case UnaryOp.Length:
            {
                if (obj.Is(LuaType.table))
                {
                    return(obj.AsTable().Count);
                }
                else
                {
                    return(obj.AsString().Length);
                }
            }

            case UnaryOp.Negate:
                return(!(obj.AsBool()));

            default:
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 2
0
        static LuaArguments EvalWhile(WhileStat stat, LuaContext Context, out LuaReturnStatus returned)
        {
            returned.returned = false;
            returned.broke    = false;
            LuaObject  cond = EvalExpression(stat.Condition, Context)[0];
            LuaContext ctx  = new LuaContext(Context);

            while (cond.AsBool())
            {
                LuaArguments obj = EvalBlock(stat.Block, ctx, out returned);
                if (returned.broke)
                {
                    break;
                }
                if (returned.returned)
                {
                    return(obj);
                }
                else
                {
                    cond = EvalExpression(stat.Condition, Context)[0];
                }
            }
            return(Lua.Return());
        }