Esempio n. 1
0
        public virtual CVar call(CVar[] call, VariabelDatabase db, EnegyData data, Posision pos)
        {
            if(func.extraVariabelDatabase != null)
            {
                db = func.extraVariabelDatabase.createShadow();
                if (SetVariabel)
                {
                    for (int i = 0; i < func.agument.size(); i++)
                        db.push(func.agument.get(i).Name, call[i], data);
                }
            }

            CVar r = func.callFunction(call, db, data, pos);
            db.garbageCollector();
            if(func.ReturnType != null)
            {
                //this function is lock to a type :)
                if (r == null)
                    r = new NullVariabel();

                if(!TypeHandler.controlType(r, func.ReturnType))
                {
                    data.setError(new ScriptError("a function '"+func.Name+"' returns can not be convertet to '" + func.ReturnType + "'", pos), db);
                    return new NullVariabel();
                }
            }

            if (r == null)
                return new NullVariabel();

            return r;
        }
Esempio n. 2
0
        public override CVar call(CVar[] call, VariabelDatabase db, EnegyData data, Posision pos)
        {
            if(extraVariabelDatabase != null)
            {
                db = getShadowVariabelDatabase(extraVariabelDatabase);
                if (SetVariabel)
                {
                    for (int i = 0; i < method.Agument.size(); i++)
                        db.push(method.Agument.get(i).Name, call[i], data);
                }
            }

            CVar cache = method.Body(obj, db, call, data, pos);
            db.garbageCollector();
            if(method.ReturnType != null)
            {
                if(!TypeHandler.controlType(cache, method.ReturnType))
                {
                    data.setError(new ScriptError("a method '" + obj.Name + "->"+method.Name+"' returns can not be convertet to '" + method.ReturnType + "'", pos), db);
                    return new NullVariabel();
                }
            }

            return cache;
        }
Esempio n. 3
0
        public CVar parse(EnegyData ed, VariabelDatabase db, Token token)
        {
            if (token.next().type() != TokenType.LeftBue)
            {
                ed.setError(new ScriptError("Missing ( after foreach", token.getCache().posision()), db);
                return new NullVariabel();
            }

            token.next();

            CVar agument = new VariabelParser().parseNoEnd(ed, db, token);

            if (!(agument is ArrayVariabel))
            {
                ed.setError(new ScriptError("Foreach first agument must be a array!", token.getCache().posision()), db);
                return new NullVariabel();
            }

            if (token.getCache().type() != TokenType.As)
            {
                ed.setError(new ScriptError("After array in foreach there must be a 'as'", token.getCache().posision()), db);
                return new NullVariabel();
            }

            if (token.next().type() != TokenType.Variabel)
            {
                ed.setError(new ScriptError("After 'as' there must be variabel", token.getCache().posision()), db);
                return new NullVariabel();
            }

            string firstVariabel = token.getCache().ToString();
            string secondVariabel = null;

            //wee see if the next token is :
            if(token.next().type() == TokenType.DublePunk)
            {
                if (token.next().type() != TokenType.Variabel)
                {
                    ed.setError(new ScriptError("After : in foreach there must be a variabel.", token.getCache().posision()), db);
                    return new NullVariabel();
                }

                secondVariabel = token.getCache().ToString();
                token.next();
            }

            if (token.getCache().type() != TokenType.RightBue)
            {
                ed.setError(new ScriptError("Missing ) in end of Foreach scope. got " + token.getCache().ToString(), token.getCache().posision()), db);
                return new NullVariabel();
            }

            ArrayList body = BodyParser.parse(token, ed, db);

            ArrayVariabel array = (ArrayVariabel)agument;

            foreach(string key in array.Keys())
            {
                if (ed.State != RunningState.Normal)
                    break;

                db.push(firstVariabel, (secondVariabel != null ? Types.toString(key, ed, db, token.getCache().posision()) : array.get(key, token.getCache().posision(), ed, db)), ed);
                if (secondVariabel != null)
                    db.push(secondVariabel, array.get(key, token.getCache().posision(), ed, db), ed);
                Interprenter.parse(new TokenCache(body, ed, db), ed, db);

                if (ed.State == RunningState.Break)
                {
                    //a token in this foreach is 'break' so wee stop this and continue outside the body of this foreach
                    ed.setNormal();
                    break;
                }
                else if (ed.State == RunningState.Continue)
                    ed.setNormal();
            }

            token.next();
            return null;
        }