Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
0
        public ArrayVariabel(EnegyData data, VariabelDatabase db, Posision pos)
            : base(new ClassVariabel(new Class()), new Dictionary<string, PointerContainer>(), new Dictionary<string, MethodContainer>(), null, new System.Collections.ArrayList())
        {
            Class c = new Class("array");

            Method length = new Method("length");
            length.SetBody(Length_caller);
            c.SetMethod(length, data, db, pos);

            Method hasValue = new Method("hasValue");
            hasValue.GetAgumentStack().push("context");
            hasValue.SetBody(HasValue_caller);
            c.SetMethod(hasValue, data, db, pos);

            Method hasKey = new Method("hasKey");
            hasKey.GetAgumentStack().push("string", "context");
            hasKey.SetBody(HasKey_caller);
            c.SetMethod(hasKey, data, db, pos);

            Method removeKey = new Method("removeKey");
            removeKey.GetAgumentStack().push("string", "key");
            removeKey.SetBody(RemoveKey_caller);
            c.SetMethod(removeKey, data, db, pos);

            Method removeValue = new Method("removeValue");
            removeValue.GetAgumentStack().push("value");
            removeValue.SetBody(RemoveValue_caller);
            c.SetMethod(removeValue, data, db, pos);

            ClassVariabel i = new ClassVariabel(c);
            ObjectVariabel o = i.createNew(db, data, new CVar[0], pos);
            Items = o.Items;
        }
Ejemplo n.º 3
0
        public CVar call(CVar obj, VariabelDatabase db, CVar[] stack, EnegyData data, Posision pos)
        {
            if (obj is ObjectVariabel)
                return call((ObjectVariabel)obj, db, stack, data, pos);

            return call((ClassVariabel)obj, db, stack, data, pos);
        }
Ejemplo n.º 4
0
        private CVar Type_call(CVar[] stack, VariabelDatabase db, EnegyData data, Posision pos)
        {
            if (stack[0] is ObjectVariabel && stack[1].toString(pos, data, db) == ((ObjectVariabel)stack[0]).Name)
                return new BooleanVariabel(true);

            return new BooleanVariabel(stack[0].type() == stack[1].toString(pos, data, db));
        }
Ejemplo n.º 5
0
        private static void createIntClass(EnegyData data, VariabelDatabase db, Posision pos)
        {
            Class i = new Class("int");

            Method constructor = new Method(null);
            constructor.GetAgumentStack().push("int", "double", new NullVariabel());
            constructor.SetBody(Constructor_caller1);
            i.SetConstructor(constructor, data, db, pos);

            Method toInt = new Method("toInt");
            toInt.SetBody(ToInt_caller);
            i.SetMethod(toInt, data, db, pos);

            Method toString = new Method("toString");
            toString.SetBody(ToString_caller1);
            i.SetMethod(toString, data, db, pos);

            Method convert = new Method("convert");
            convert.SetStatic();
            convert.GetAgumentStack().push("string", "int");
            convert.SetBody(Convert_caller);
            i.SetMethod(convert, data, db, pos);

            db.pushClass(i, data);
        }
Ejemplo n.º 6
0
        public void open(VariabelDatabase database, EnegyData data, Posision pos)
        {
            Class config = new Class("Config");

            Method get = new Method("get");
            get.GetAgumentStack().push("string", "name");
            get.SetBody(Get_caller);
            get.SetStatic();
            config.SetMethod(get, data, database, pos);

            Method isScriptLock = new Method("isScriptLock");
            isScriptLock.SetBody(IsScriptLock_caller);
            isScriptLock.SetStatic();
            config.SetMethod(isScriptLock, data, database, pos);

            Method set = new Method("set");
            set.GetAgumentStack().push("string", "name");
            set.GetAgumentStack().push("string", "value");
            set.SetBody(Set_caller);
            set.SetStatic();
            config.SetMethod(set, data, database, pos);

            Method isLocked = new Method("isLocked");
            isLocked.SetStatic();
            isLocked.GetAgumentStack().push("string", "name");
            isLocked.SetBody(IsLocked_caller);
            config.SetMethod(isLocked, data, database, pos);

            database.pushClass(config, data);
        }
Ejemplo n.º 7
0
 public void open(VariabelDatabase database, EnegyData data, Posision pos)
 {
     Function version = new Function();
     version.Name = "version";
     version.call += Version_call;
     database.pushFunction(version, data);
 }
Ejemplo n.º 8
0
        private CVar Create_caller(CVar c, VariabelDatabase db, CVar[] stack, EnegyData data, Posision pos)
        {
            if(((StaticMethodVariabel)TypeHandler.ToObjectVariabel(c).get("exists")).call(data, db, stack[0].toString(pos, data, db)).toBoolean(pos, data, db))
            {
                data.setError(new ScriptError("'" + stack[0].toString(pos, data, db) + "' exists and there for can not be createt", pos), db);
                return null;
            }

            FileStream fs;
            StreamWriter f = new StreamWriter((fs = System.IO.File.Create(stack[0].toString(pos, data, db))));

            if(!(stack[1] is NullVariabel))
            {
                try {
                    f.Write(stack[1].toString(pos, data, db));
                }catch(IOException e)
                {
                    fs.Close();
                    f.Close();
                    data.setError(new ScriptError("Write to the new file '" + stack[0].toString(pos, data, db) + "' failed: " + e.Message, pos), db);
                    return null;
                }
            }

            fs.Close();
            f.Close();

            return null;
        }
Ejemplo n.º 9
0
        public CVar call(ObjectVariabel obj, VariabelDatabase db, CVar[] stack, EnegyData data, Posision pos)
        {
            //interprenter.setObject(obj);
            Interprenter.parse(new TokenCache(Body, data, db), data, db);

            return data.getReturn();
        }
Ejemplo n.º 10
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;
        }
Ejemplo n.º 11
0
 public int CompareTo(object obj)
 {
     if (obj is Step)
     {
         return(Posision.CompareTo(obj as Step));
     }
     return(0);
 }
Ejemplo n.º 12
0
        public CVar callFunction(CVar[] stack, VariabelDatabase db, EnegyData data, Posision pos)
        {
            if (call == null)
            {
                return new NullVariabel();
            }

            return call(stack, db, data, pos);
        }
Ejemplo n.º 13
0
        private void parseFile(EnegyData ed, VariabelDatabase db, Posision pos, string plugin)
        {
            if (!File.Exists(plugin))
            {
                ed.setError(new ScriptError("Unknown file: " + plugin, pos), db);
                return;
            }

            FileEnergy.parse(ed, new FileVariabelDatabase(db), plugin);
        }
Ejemplo n.º 14
0
        public void SetConstructor(Method method, EnegyData data, VariabelDatabase db, Posision pos)
        {
            if(container.Constructor != null)
            {
                data.setError(new ScriptError("A class can only have one constructor", pos), db);
                return;
            }

            container.Constructor = method.GetMethodContainer();
        }
Ejemplo n.º 15
0
        public CVar get(CVar key, Posision pos, EnegyData data, VariabelDatabase db)
        {
            if (!keyExists(key, pos, data, db))
            {
                data.setError(new ScriptError("Unknown key in array: " + key.toString(pos, data, db), pos), db);
                return new NullVariabel();
            }

            return container[key.toString(pos, data, db)];
        }
Ejemplo n.º 16
0
        private CVar ToInt_call(CVar[] stack, VariabelDatabase db, EnegyData data, Posision pos)
        {
            double result;
            if (!double.TryParse(stack[0].toString(pos, data, db), out result))
            {
                data.setError(new ScriptError(stack[0].toString(pos, data, db) + " could not be convertet to int", new Posision(0, 0)), db);
                return new NullVariabel();
            }

            return Types.toInt(result, data, db, pos);
        }
Ejemplo n.º 17
0
        public void SetPointer(Pointer pointer, EnegyData data, VariabelDatabase db, Posision pos)
        {
            PointerContainer pc = pointer.GetPointerContainer();

            Control(pc.Name, data, db, pos);//control if the class contains the name already

            if (pc.IsStatic)
                container.StaticPointer.Add(pc.Name, pc);
            else
                container.Pointer.Add(pc.Name, pc);
        }
Ejemplo n.º 18
0
        private static CVar Convert_caller(CVar c, VariabelDatabase db, CVar[] stack, EnegyData data, Posision pos)
        {
            double number;

            if (double.TryParse(stack[0].toString(pos, data, db), out number))
            {
                return Types.toInt(number, data, db, pos);
            }

            return Types.toInt(0, data, db, pos);
        }
Ejemplo n.º 19
0
        private CVar Get_caller(CVar c, VariabelDatabase db, CVar[] stack, EnegyData data, Posision pos)
        {
            string name = stack[0].toString(pos, data, db);

            if (!data.Config.exists(name))
            {
                data.setError(new ScriptError("Unknown config name: " + name, pos), db);
                return new NullVariabel();
            }

            return Types.toString(data.Config.get(name, ""), data, db, pos);
        }
Ejemplo n.º 20
0
        private CVar IsLocked_caller(CVar c, VariabelDatabase db, CVar[] stack, EnegyData data, Posision pos)
        {
            string name = stack[0].toString(pos, data, db);

            if (!data.Config.exists(name))
            {
                data.setError(new ScriptError("Unknown config: " + name, pos), db);
                return new BooleanVariabel(false);
            }

            return new BooleanVariabel(data.Config.isAllowedOverride(name));
        }
Ejemplo n.º 21
0
        private CVar HasValue_call(CVar[] stack, VariabelDatabase db, EnegyData data, Posision pos)
        {
            ArrayVariabel array = (ArrayVariabel)stack[0];

            foreach (string key in array.Keys())
            {
                if (array.get(key, pos, data, db).compare(stack[1], pos, data, db))
                    return new BooleanVariabel(true);
            }

            return new BooleanVariabel(false);
        }
Ejemplo n.º 22
0
        public void SetMethod(Method method, EnegyData data, VariabelDatabase db, Posision pos)
        {
            MethodContainer mc = method.GetMethodContainer();

            if(!Control(mc.Name, data, db, pos))
            {
                return;
            }

            if (mc.IsStatic)
                container.StaticMethod.Add(mc.Name, mc);
            else
                container.Methods.Add(mc.Name, mc);
        }
Ejemplo n.º 23
0
        private CVar Type_call1(CVar[] stack, VariabelDatabase db, EnegyData data, Posision pos)
        {
            if(stack[0].type() == "object")
            {
                return Types.toString(((ObjectVariabel)stack[0]).Name, data, db, pos);
            }

            if(stack[0].type() == "class")
            {
                return Types.toString(((ClassVariabel)stack[0]).Name, data, db, pos);
            }

            return Types.toString(stack[0].type(), data, db, pos);
        }
Ejemplo n.º 24
0
        public void open(VariabelDatabase database, EnegyData data, Posision pos)
        {
            Function error = new Function();
            error.Name = "error";
            error.agument.push("string", "message");//here wee say wee want a agument there is string and name string :)
            error.call += Error_call;

            database.pushFunction(error, data);

            Function errorCallback = new Function();
            errorCallback.Name = "errorCallback";
            errorCallback.agument.push("function", "f");//here wee say wee want a agument there is function and
            errorCallback.call += ErrorCallback_call; ;
            database.pushFunction(errorCallback, data);
        }
Ejemplo n.º 25
0
        //no support from V0.3
        public void open(VariabelDatabase database, EnegyData data, Posision pos)
        {
            Function hasValue = new Function();
            hasValue.Name = "hasValue";
            hasValue.agument.push("array", "array");
            hasValue.agument.push("context");
            hasValue.call += HasValue_call;
            database.pushFunction(hasValue, data);

            Function hasKey = new Function();
            hasKey.Name = "hasKey";
            hasKey.agument.push("array", "array");
            hasKey.agument.push("context");
            hasKey.call += HasKey_call;
            database.pushFunction(hasKey, data);
        }
Ejemplo n.º 26
0
        public override CVar call(CVar[] call, VariabelDatabase db, EnegyData data, Posision pos)
        {
            CVar cache = method.Body(c, db, call, data, pos);
            db.garbageCollector();

            if (method.ReturnType != null)
            {

                if(!TypeHandler.controlType(cache, method.ReturnType))
                {
                    data.setError(new ScriptError("a static method '" + c.Name + "->" + method.Name + "' returns can not be convertet to '" + method.ReturnType + "'", pos), db);
                    return new NullVariabel();
                }
            }

            return cache;
        }
Ejemplo n.º 27
0
        public ObjectVariabel createNew(VariabelDatabase db, EnegyData data, CVar[] call, Posision pos)
        {
            //wee create a new object and return the object to the system :)
            ObjectVariabel obj = new ObjectVariabel(this, Container.Pointer, Container.Methods, Container.ExtraVariabelDatabase, Container.Extends);

            if (hasConstructor())
            {
                VariabelDatabase vd = db.createShadow(obj);
                if (Container.Constructor.SetVariabel)
                {
                    for (int i = 0; i < Container.Constructor.Agument.size(); i++)
                        vd.push(Container.Constructor.Agument.get(i).Name, call[i], data);
                }
                CallConstructor(vd, call, data, pos, obj);
            }

            return obj;
        }
Ejemplo n.º 28
0
        public void open(VariabelDatabase database, EnegyData data, Posision pos)
        {
            if(data.Config.get("file.system.enable", "false") != "true")
            {
                data.setError(new ScriptError("You can use the plugin 'file' becuse it not enabled in the config system!", new Posision(0, 0)), database);
                return;
            }

            Class f = new Class("File");

            Method exsist = new Method("exists");
            exsist.SetStatic();
            exsist.GetAgumentStack().push("string", "dir");
            exsist.SetBody(Exsist_caller);
            f.SetMethod(exsist, data, database, pos);

            Method create = new Method("create");
            create.SetStatic();
            create.GetAgumentStack().push("string", "dir");
            create.GetAgumentStack().push("string", "context", new NullVariabel());
            create.SetBody(Create_caller);
            f.SetMethod(create, data, database, pos);

            Method delete = new Method("delete");
            delete.SetStatic();
            delete.GetAgumentStack().push("string", "dir");
            delete.SetBody(Delete_caller);
            f.SetMethod(delete, data, database, pos);

            Method write = new Method("write");
            write.SetStatic();
            write.GetAgumentStack().push("string", "dir");
            write.GetAgumentStack().push("string", "context");
            write.SetBody(Write_caller);
            f.SetMethod(write, data, database, pos);

            Method read = new Method("read");
            read.SetStatic();
            read.GetAgumentStack().push("string", "dir");
            read.SetBody(Read_caller);
            f.SetMethod(read, data, database, pos);

            database.pushClass(f, data);
        }
Ejemplo n.º 29
0
        private CVar Set_caller(CVar c, VariabelDatabase db, CVar[] stack, EnegyData data, Posision pos)
        {
            if (data.Config.isScriptLock)
            {
                data.setError(new ScriptError("The config is locked", pos), db);
                return null;
            }

            string name = stack[0].toString(pos, data, db);

            if (data.Config.exists(name) && data.Config.isAllowedOverride(name))
            {
                data.setError(new ScriptError("The config '" + name + "' is not allowed to be changed by the script", pos), db);
                return new NullVariabel();
            }

            data.Config.append(name, stack[1].toString(pos, data, db), true);
            return null;
        }
Ejemplo n.º 30
0
        public void open(VariabelDatabase database, EnegyData data, Posision pos)
        {
            Class r = new Class("Random");

            Method constructor = new Method("");
            constructor.SetBody(Constructor_caller);
            r.SetConstructor(constructor, data, database, pos);

            Method seed = new Method("seed");
            seed.GetAgumentStack().push("int", "seed");
            seed.SetBody(Seed_caller);
            r.SetMethod(seed, data, database, pos);

            Method next = new Method("next");
            next.GetAgumentStack().push("int", "min");
            next.GetAgumentStack().push("int", "max");
            next.SetBody(Next_caller);
            r.SetMethod(next, data, database, pos);

            database.pushClass(r, data);
        }
Ejemplo n.º 31
0
        public void open(VariabelDatabase database, EnegyData data, Posision pos)
        {
            Function cosh = new Function();
            cosh.Name = "cosh";
            cosh.agument.push("int", "");
            cosh.call += Cosh_call;

            database.pushFunction(cosh, data);

            Function cos = new Function();
            cos.Name = "cos";
            cos.agument.push("int", "");
            cos.call += Cos_call;

            database.pushFunction(cos, data);

            Function tanh = new Function();
            tanh.Name = "tanh";
            tanh.agument.push("int", "");
            tanh.call += Tanh_call;
            database.pushFunction(tanh, data);

            Function tan = new Function();
            tan.Name = "tan";
            tan.agument.push("int", "");
            tan.call += Tan_call;
            database.pushFunction(tan, data);

            Function sinh = new Function();
            sinh.Name = "sinh";
            sinh.agument.push("int", "");
            sinh.call += Sinh_call;
            database.pushFunction(sinh, data);

            Function sin = new Function();
            sin.Name = "sin";
            sin.agument.push("int", "");
            sin.call += Sin_call;
            database.pushFunction(sin, data);
        }
Ejemplo n.º 32
0
 private static CVar Print_call(CVar[] stack, VariabelDatabase db, EnegyData data, Posision pos)
 {
     Console.WriteLine(stack[0].toString(pos, data, db));
     return(null);
 }
Ejemplo n.º 33
0
        private static CVar Useage_call(CVar[] stack, VariabelDatabase db, EnegyData data, Posision pos)
        {
            Console.WriteLine("----container----");
            foreach (string co in db.ContainerKeys())
            {
                Console.WriteLine("-" + co);
            }

            Console.WriteLine("------Global-----");
            foreach (string go in db.GlobalsKey())
            {
                Console.WriteLine("-" + go);
            }

            return(new NullVariabel());
        }