Beispiel #1
0
        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);
        }
Beispiel #2
0
 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));
 }
Beispiel #3
0
 private GSharpObject Print(VirtualMachine vm, GSharpObject self, GSharpObject[] arguments)
 {
     foreach (GSharpObject arg in arguments)
     {
         Console.Write(arg);
     }
     return(null);
 }
Beispiel #4
0
        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);
        }
Beispiel #5
0
 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())));
 }
Beispiel #6
0
 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);
 }
Beispiel #7
0
 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().");
 }
Beispiel #8
0
        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);
        }
Beispiel #9
0
        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);
        }
Beispiel #10
0
 public InternalMethodCallback(GSharpMethodCallback callback, GSharpObject self) : base("Internal Method Callback")
 {
     this.self     = self;
     this.callback = callback;
 }
Beispiel #11
0
 private static GSharpObject String(VirtualMachine vm, GSharpObject self, GSharpObject[] arguments)
 {
     return(new GSharpString(""));
 }
Beispiel #12
0
 private static GSharpObject Object(VirtualMachine vm, GSharpObject self, GSharpObject[] arguments)
 {
     return(new GSharpObject());
 }
Beispiel #13
0
 private static GSharpObject Integer(VirtualMachine vm, GSharpObject self, GSharpObject[] arguments)
 {
     return(new GSharpInteger(0));
 }
Beispiel #14
0
 private static GSharpObject Boolean(VirtualMachine vm, GSharpObject self, GSharpObject[] arguments)
 {
     return(new GSharpBool(false));
 }