Example #1
0
 public static object Close(RubyContext /*!*/ context, object self)
 {
     //TODO: See http://redmine.ruby-lang.org/issues/show/1633
     // this should raise an error if called twice on an object, currently
     // it will just advance the stream which actually matches 1.8.6 behavior
     // but matz has said current 1.8.6 behavior is a bug.
     RubyIOOps.Close(context.InputProvider.GetOrResetCurrentStream());
     return(self);
 }
Example #2
0
 public static RubyFile /*!*/ CreateFile(RubyClass /*!*/ self,
                                         [DefaultProtocol, NotNull] Union <int, MutableString> descriptorOrPath, int mode, [Optional] int permission)
 {
     if (descriptorOrPath.IsFixnum())
     {
         return(new RubyFile(
                    self.Context, RubyIOOps.GetDescriptorStream(self.Context, descriptorOrPath.Fixnum()), descriptorOrPath.Fixnum(), (IOMode)mode
                    ));
     }
     else
     {
         // TODO: permissions
         return(CreateFile(self, descriptorOrPath.Second, mode));
     }
 }
Example #3
0
        public static RubyArray /*!*/ TOA(RubyContext /*!*/ context, object self)
        {
            RubyArray result = new RubyArray();
            RubyArray lines;

            while (context.InputProvider.HasMoreFiles())
            {
                lines = RubyIOOps.ReadLines(context, context.InputProvider.GetOrResetCurrentStream(), -1);
                //TODO: result.append(lines)???
                foreach (var line in lines)
                {
                    result.Add(line);
                }
            }
            return(result);
        }
Example #4
0
        public static object Load(ReaderSites /*!*/ sites, RespondToStorage /*!*/ respondToStorage,
                                  RubyScope /*!*/ scope, RubyModule /*!*/ self, object source, [Optional] Proc proc)
        {
            Stream stream = null;

            if (source != null)
            {
                stream = RubyIOOps.CreateIOWrapper(respondToStorage, source, FileAccess.Read);
            }
            if (stream == null || !stream.CanRead)
            {
                throw RubyExceptions.CreateTypeError("instance of IO needed");
            }
            BinaryReader  reader = new BinaryReader(stream);
            MarshalReader loader = new MarshalReader(sites, reader, scope.GlobalScope, proc);

            return(loader.Load());
        }
Example #5
0
        public static object Dump(WriterSites /*!*/ sites, RespondToStorage /*!*/ respondToStorage,
                                  RubyModule /*!*/ self, object obj, object io, [Optional] int?limit)
        {
            Stream stream = null;

            if (io != null)
            {
                stream = RubyIOOps.CreateIOWrapper(respondToStorage, io, FileAccess.Write);
            }
            if (stream == null || !stream.CanWrite)
            {
                throw RubyExceptions.CreateTypeError("instance of IO needed");
            }

            BinaryWriter  writer = new BinaryWriter(stream);
            MarshalWriter dumper = new MarshalWriter(sites, writer, self.Context, limit);

            dumper.Dump(obj);
            return(io);
        }
Example #6
0
 public static object BinMode(RubyContext /*!*/ context, object self)
 {
     RubyIOOps.Binmode(context.InputProvider.GetCurrentStream());
     context.InputProvider.DefaultMode = context.InputProvider.DefaultMode | IOMode.PreserveEndOfLines;
     return(self);
 }
Example #7
0
 public static int FileNo(RubyContext /*!*/ context, object self)
 {
     return(RubyIOOps.FileNo(context.InputProvider.GetCurrentStream()));
 }
Example #8
0
 public static MutableString /*!*/ ReadLine(RubyScope /*!*/ scope, object self)
 {
     return(RubyIOOps.ReadLine(scope, scope.RubyContext.InputProvider.GetOrResetCurrentStream()));
 }
Example #9
0
        public static object Open(BlockParam /*!*/ block, RubyClass /*!*/ self, object path)
        {
            RubyIO io = RubyIOOps._CreateIOSharedSite3.Target(RubyIOOps._CreateIOSharedSite3, self.Context, self, Protocols.CastToString(self.Context, path));

            return(RubyIOOps.TryInvokeOpenBlock(self.Context, block, io));
        }
Example #10
0
 public static int GetLineNumber(RubyContext /*!*/ context, object self)
 {
     return(RubyIOOps.GetLineNumber(context.InputProvider.GetCurrentStream()));
 }
Example #11
0
 public static void Pos(RubyContext /*!*/ context, object self, [DefaultProtocol] IntegerValue pos)
 {
     RubyIOOps.Pos(context.InputProvider.GetCurrentStream(), pos);
 }
Example #12
0
 public static RubyArray /*!*/ ReadLines(RubyContext /*!*/ context, object self, [DefaultProtocol] MutableString separator, [DefaultProtocol] int limit)
 {
     return(RubyIOOps.ReadLines(context, context.InputProvider.GetOrResetCurrentStream(), separator, limit));
 }
Example #13
0
 public static RubyArray /*!*/ ReadLines(RubyContext /*!*/ context, object self, [DefaultProtocol, NotNull] Union <MutableString, int> separatorOrLimit)
 {
     return(RubyIOOps.ReadLines(context, context.InputProvider.GetOrResetCurrentStream(), separatorOrLimit));
 }
Example #14
0
 public static RubyArray /*!*/ ReadLines(RubyContext /*!*/ context, object self, DynamicNull separator)
 {
     return(RubyIOOps.ReadLines(context, context.InputProvider.GetOrResetCurrentStream(), separator));
 }
Example #15
0
 public static RubyArray /*!*/ ReadLines(RubyContext /*!*/ context, object self)
 {
     return(RubyIOOps.ReadLines(context, context.InputProvider.GetOrResetCurrentStream()));
 }
Example #16
0
 public static int ReadChar(RubyContext /*!*/ context, object self)
 {
     return(RubyIOOps.ReadChar(context.InputProvider.GetOrResetCurrentStream()));
 }
Example #17
0
 public static MutableString /*!*/ Read(RubyContext /*!*/ context, [DefaultProtocol] int bytes, [DefaultProtocol, Optional] MutableString buffer)
 {
     return(RubyIOOps.Read(context.InputProvider.GetOrResetCurrentStream(), bytes, buffer));
 }
Example #18
0
 public static MutableString /*!*/ Read(RubyContext /*!*/ context, object self)
 {
     return(RubyIOOps.Read(context.InputProvider.GetOrResetCurrentStream()));
 }
Example #19
0
 public static object Pos(RubyContext /*!*/ context, object self)
 {
     return(RubyIOOps.Pos(context.InputProvider.GetCurrentStream()));
 }
Example #20
0
 public static MutableString Gets(RubyScope /*!*/ scope, object self, DynamicNull separator)
 {
     return(RubyIOOps.Gets(scope, scope.RubyContext.InputProvider.GetOrResetCurrentStream(), separator));
 }
Example #21
0
 public static void SetLineNumber(RubyContext /*!*/ context, object self, [DefaultProtocol] int value)
 {
     RubyIOOps.SetLineNumber(context, context.InputProvider.GetCurrentStream(), value);
 }
Example #22
0
 public static MutableString Gets(RubyScope /*!*/ scope, object self, [DefaultProtocol, NotNull] Union <MutableString, int> separatorOrLimit)
 {
     return(RubyIOOps.Gets(scope, scope.RubyContext.InputProvider.GetOrResetCurrentStream(), separatorOrLimit));
 }
Example #23
0
 public static void Rewind(RubyContext /*!*/ context, object self)
 {
     RubyIOOps.Rewind(context, context.InputProvider.GetCurrentStream());
 }
Example #24
0
 public static MutableString Gets(RubyScope /*!*/ scope, object self, [DefaultProtocol] MutableString separator, [DefaultProtocol] int limit)
 {
     return(RubyIOOps.Gets(scope, scope.RubyContext.InputProvider.GetOrResetCurrentStream(), separator, limit));
 }
Example #25
0
        public static object Open(BlockParam /*!*/ block, RubyClass /*!*/ self, object path, int fileMode, int permissions)
        {
            RubyIO io = RubyIOOps._CreateIOSharedSite5.Target(RubyIOOps._CreateIOSharedSite5, self.Context, self, Protocols.CastToString(self.Context, path), fileMode, permissions);

            return(RubyIOOps.TryInvokeOpenBlock(self.Context, block, io));
        }
Example #26
0
 public static object Each(RubyContext /*!*/ context, BlockParam block, object self, [DefaultProtocol] MutableString separator, [DefaultProtocol] int limit)
 {
     RubyIOOps.Each(context, block, context.InputProvider.GetOrResetCurrentStream(), separator, limit);
     return(self);
 }
Example #27
0
        public static object Open(BlockParam /*!*/ block, RubyClass /*!*/ self, [NotNull] MutableString /*!*/ path, int fileMode)
        {
            RubyIO io = RubyIOOps._CreateIOSharedSite4.Target(RubyIOOps._CreateIOSharedSite4, self.Context, self, path, fileMode);

            return(RubyIOOps.TryInvokeOpenBlock(self.Context, block, io));
        }
Example #28
0
 public static object EachByte(RubyContext /*!*/ context, BlockParam block, object self)
 {
     RubyIOOps.EachByte(block, context.InputProvider.GetOrResetCurrentStream());
     return(self);
 }
Example #29
0
        public static object Open(BlockParam /*!*/ block, RubyClass /*!*/ self, MutableString /*!*/ path, MutableString /*!*/ mode, int permissions)
        {
            RubyIO io = RubyIOOps._CreateIOSharedSite7.Target(RubyIOOps._CreateIOSharedSite7, self.Context, self, path, mode, permissions);

            return(RubyIOOps.TryInvokeOpenBlock(self.Context, block, io));
        }
Example #30
0
 public static bool Closed(RubyContext /*!*/ context, object self)
 {
     return(RubyIOOps.Closed(context.InputProvider.GetCurrentStream()));
 }