Ejemplo n.º 1
0
        public LuaValue Execute(out bool isBreak)
        {
            foreach (Statement statement in Statements)
            {
                ReturnStmt returnStmt = statement as ReturnStmt;
                if (returnStmt != null)
                {
                    isBreak = false;
                    return(LuaMultiValue.WrapLuaValues(returnStmt.ExprList.ConvertAll(expr => expr.Evaluate(Enviroment)).ToArray()));
                }
                else if (statement is BreakStmt)
                {
                    isBreak = true;
                    return(null);
                }
                else
                {
                    var returnValue = statement.Execute(Enviroment, out isBreak);
                    if (returnValue != null || isBreak == true)
                    {
                        return(returnValue);
                    }
                }
            }

            isBreak = false;
            return(null);
        }
Ejemplo n.º 2
0
        private ReturnStmt ParseReturnStmt(out bool success)
        {
            var reskey = new Tuple2<int, string>(position, "ReturnStmt");
            if (ParsingResults.ContainsKey(reskey))
            {
                var parsingResult = ParsingResults[reskey];
                success = parsingResult.Item2;
                position = parsingResult.Item3;
                return parsingResult.Item1 as ReturnStmt;
            }

            int errorCount = Errors.Count;
            ReturnStmt returnStmt = new ReturnStmt();
            int start_position = position;

            MatchTerminalString("return", out success);
            if (!success)
            {
                position = start_position;
                ParsingResults[reskey] = new Tuple3<object, bool, int>(returnStmt, success, position);return returnStmt;
            }

            ParseSpReq(out success);
            if (!success)
            {
                Error("Failed to parse SpReq of ReturnStmt.");
                position = start_position;
                ParsingResults[reskey] = new Tuple3<object, bool, int>(returnStmt, success, position);return returnStmt;
            }

            returnStmt.ExprList = ParseExprList(out success);
            success = true;

            ParsingResults[reskey] = new Tuple3<object, bool, int>(returnStmt, success, position);
            return returnStmt;
        }