private GSharpObject WriteAllBytes(VirtualMachine vm, GSharpObject self, GSharpObject[] arguments) { if (arguments.Length < 2) { throw new System.Exception("Expected file name in system.io.writeAllBytes()."); } else if (!(arguments[0] is GSharpString)) { throw new System.Exception("Expected file name as string in system.io.writeAllBytes()."); } string filename = ((GSharpString)arguments[0]).ToString(); System.Collections.Generic.List <byte> list = new System.Collections.Generic.List <byte>(); foreach (GSharpObject obj in arguments) { if (obj is GSharpInteger) { list.Add((byte)((GSharpInteger)obj).Value); } else if (obj is GSharpList) { foreach (GSharpObject i in ((GSharpList)obj).Objects) { if (i is GSharpInteger) { list.Add((byte)((GSharpInteger)i).Value); } } } } System.IO.File.WriteAllBytes(filename, list.ToArray()); return(null); }
private static GSharpObject getType(VirtualMachine vm, GSharpObject self, GSharpObject[] arguments) { if (arguments.Length != 1) { throw new System.Exception("Expected one argument to getType()."); } return(new GSharpString(arguments[0].Type)); }
private GSharpObject Print(VirtualMachine vm, GSharpObject self, GSharpObject[] arguments) { foreach (GSharpObject arg in arguments) { Console.Write(arg); } return(null); }
public override GSharpObject Invoke(VirtualMachine vm, GSharpObject[] arguments) { GSharpObject obj = new GSharpObject(); foreach (GSharpMethod method in instanceMethods) { obj.SetAttribute(method.Name, method); } vm.InvokeMethod(constructor, obj, arguments); return(obj); }
private GSharpObject ReadAllText(VirtualMachine vm, GSharpObject self, GSharpObject[] arguments) { if (arguments.Length != 1) { throw new System.Exception("Expected file name in system.io.readAllText()."); } else if (!(arguments[0] is GSharpString)) { throw new System.Exception("Expected file name as string in system.io.readlAllText()."); } return(new GSharpString(System.IO.File.ReadAllText(((GSharpString)arguments[0]).ToString()))); }
private GSharpObject Delete(VirtualMachine vm, GSharpObject self, GSharpObject[] arguments) { if (arguments.Length != 1) { throw new System.Exception("Expected file name in system.io.delete()."); } else if (!(arguments[0] is GSharpString)) { throw new System.Exception("Expected file name as string in system.io.delete()."); } System.IO.File.Delete(((GSharpString)arguments[0]).ToString()); return(null); }
public GSharpObject toString(VirtualMachine vm, GSharpObject self, GSharpObject[] arguments) { if (arguments.Length != 1) { throw new System.Exception("Invalid number of arguments in enum.ToString()."); } else { foreach (var a in attributes) { if (a.Value == arguments[0]) { return(new GSharpString(a.Key)); } } } throw new System.Exception("Invalid item in enum.ToString()."); }
private GSharpObject ReadAllBytes(VirtualMachine vm, GSharpObject self, GSharpObject[] arguments) { if (arguments.Length != 1) { throw new System.Exception("Expected file name in system.io.readAllBytes()."); } else if (!(arguments[0] is GSharpString)) { throw new System.Exception("Expected file name as string in system.io.readlAllBytes()."); } byte[] bytes = System.IO.File.ReadAllBytes(((GSharpString)arguments[0]).ToString()); GSharpList toRet = new GSharpList(new GSharpObject[] { }); foreach (byte b in bytes) { toRet.Add(new GSharpInteger(b)); } return(toRet); }
private GSharpObject WriteAllText(VirtualMachine vm, GSharpObject self, GSharpObject[] arguments) { if (arguments.Length < 2) { throw new System.Exception("Expected file name and new file contents in system.io.writeAllText()."); } else if (!(arguments[0] is GSharpString)) { throw new System.Exception("Expected file name as string in system.io.writeAllText()."); } string filename = ((GSharpString)arguments[0]).ToString(); string contents = ""; for (int i = 1; i < arguments.Length; i++) { contents += arguments[i].ToString(); } System.IO.File.WriteAllText(filename, contents); return(null); }
public InternalMethodCallback(GSharpMethodCallback callback, GSharpObject self) : base("Internal Method Callback") { this.self = self; this.callback = callback; }
private static GSharpObject String(VirtualMachine vm, GSharpObject self, GSharpObject[] arguments) { return(new GSharpString("")); }
private static GSharpObject Object(VirtualMachine vm, GSharpObject self, GSharpObject[] arguments) { return(new GSharpObject()); }
private static GSharpObject Integer(VirtualMachine vm, GSharpObject self, GSharpObject[] arguments) { return(new GSharpInteger(0)); }
private static GSharpObject Boolean(VirtualMachine vm, GSharpObject self, GSharpObject[] arguments) { return(new GSharpBool(false)); }