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)); }
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); }
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; }
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; }
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; }
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(); }
public override CVar call(EnegyData data, VariabelDatabase db, params object[] parameters) { CVar[] stack = new CVar[method.Agument.size()]; VariabelDatabase vd = getShadowVariabelDatabase(db); for (int i = 0; i < parameters.Length && i <= method.Agument.size(); i++) { CVar context = ScriptConverter.convert(parameters[i], data, db); if (method.Agument.get(i).hasType() && !TypeHandler.controlType(context, method.Agument.get(i).Type)) { data.setError(new ScriptError("Cant convert " + context.type() + " to " + method.Agument.get(i).Type.ToString(), new Posision(0, 0)), db); } //okay let cache the parameters :) stack[0] = context; if(SetVariabel) vd.push(method.Agument.get(i).Name, stack[0], data); } //wee take a new for loop to get other parameters there is not has been set :) for (int i = stack.Length; i < method.Agument.size(); i++) { if (!method.Agument.get(i).hasValue()) { data.setError(new ScriptError("Missing agument to " + method.Name, new Posision(0, 0)), db); return new NullVariabel(); } stack[i] = method.Agument.get(i).Value; if(SetVariabel) vd.push(method.Agument.get(i).Name, method.Agument.get(i).Value, data); } return call(stack, db, data, new Posision(0,0)); }
public void push(string type, string name, CVar value) { container.Add(new AgumentStackData() { Type = type, Name = name, Value = value, }); }
public CVar callFunction(CVar[] stack, VariabelDatabase db, EnegyData data, Posision pos) { if (call == null) { return new NullVariabel(); } return call(stack, db, data, pos); }
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)]; }
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); }
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); }
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)); }
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); }
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); }
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); }
public bool appendToPointer(string name, CVar value) { int i; if((i=getIDByName(name)) != -1) { if (Items[i].IsPointer) { Items[i].Context = value; return true; } } return false; }
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; }
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; }
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; }
public static bool controlType(CVar variabel, string type) { //both int and string got a valid method toString and int has toInt if (variabel.type() == "object") { //wee control the object typer (string and int) if (type == "string") { return controlMethod((ObjectVariabel)variabel, "toString", 0); } else if (type == "int") { return controlMethod((ObjectVariabel)variabel, "toInt", 0); } } if (variabel.type() == "object" && ((ObjectVariabel)variabel).Name == type) return true; //control if the type is function if(type.IndexOf("function") == 0) { //control if the hole type contain 'function' if(type == "function") { return variabel.type() == "function" || variabel.type() == "method"; } if (type.Substring(8, 1) != "<" || type.Substring(type.Length-1) != ">") return false; string rt = type.Substring(9, type.Length - 10); return variabel.type() == "function" && ((FunctionVariabel)variabel).func.ReturnType == rt || variabel.type() == "method" && ((MethodVariabel)variabel).method.ReturnType == rt; } //funtion can also be method and method funtion if (variabel.type() == "function" && type == "method" || variabel.type() == "method" && type == "function") return true; return variabel.type() == type; }
public virtual CVar call(EnegyData data, VariabelDatabase db, params object[] parameters) { //wee push the parameters in vd :) CVar[] stack = new CVar[func.agument.size()]; AgumentStack agument = getStatck(); VariabelDatabase vd = getShadowVariabelDatabase(db); int i = 0; for (; i < parameters.Length; i++) { CVar context = ScriptConverter.convert(parameters[i], data, db); if(agument.get(i).hasType() && !TypeHandler.controlType(context, agument.get(i).Type)) { data.setError(new ScriptError("Cant convert " + context.type() + " to " + agument.get(i).Type.ToString(), new Posision(0, 0)), db); return new NullVariabel(); } stack[i] = context; if (SetVariabel) vd.push(agument.get(i).Name, context, data); } for (; i < stack.Length; i++) { if (!agument.get(i).hasType()) { data.setError(new ScriptError("Missing agument to " + func.Name, new Posision(0, 0)), db); return new NullVariabel(); } stack[i] = agument.get(i).Value; if (SetVariabel) vd.push(agument.get(i).Name, stack[i], data); } return call(stack, vd, data, new Posision(0, 0)); }
public override bool compare(CVar var, Posision pos, EnegyData data, VariabelDatabase db) { return false; }
private CVar Error_call(CVar[] stack, VariabelDatabase db, EnegyData data, Posision pos) { data.setError(new ScriptError(stack[0].toString(pos, data, db), pos), db); return new NullVariabel(); }
private CVar ErrorCallback_call(CVar[] stack, VariabelDatabase db, EnegyData data, Posision pos) { data.ErrorHandler = (FunctionVariabel)stack[0]; return new BooleanVariabel(true); }
public override bool compare(CVar var, Posision pos, EnegyData data, VariabelDatabase db) { if (Types.instanceof((ClassVariabel)db.get("string", data), this)) { return toString(pos, data, db) == var.toString(pos, data, db); }else if (Types.instanceof((ClassVariabel)db.get("int", data), this)) { return toInt(pos, data, db) == var.toInt(pos, data, db); } return this == var; }
private CVar IsScriptLock_caller(CVar c, VariabelDatabase db, CVar[] stack, EnegyData data, Posision pos) { return new BooleanVariabel(data.Config.isScriptLock); }
public static ObjectVariabel ToObjectVariabel(CVar var) { return (ObjectVariabel)var; }
public void setReturn(CVar r) { State = RunningState.Return; ReturnContext = r; }
private CVar Version_call(CVar[] stack, VariabelDatabase db, EnegyData data, Posision pos) { return Types.toString(Energy.VERSION, data, db, pos); }