From fbcca152f1360041fd4ab57f70ebe0fe202d63da Mon Sep 17 00:00:00 2001 From: Inori Date: Mon, 5 Aug 2019 12:59:26 -0400 Subject: [PATCH] Add FileInt.pos method --- binding/filesystem-binding.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/binding/filesystem-binding.cpp b/binding/filesystem-binding.cpp index 742f8849..277c0d32 100644 --- a/binding/filesystem-binding.cpp +++ b/binding/filesystem-binding.cpp @@ -130,6 +130,14 @@ RB_METHOD(fileIntBinmode) return Qnil; } +RB_METHOD(fileIntPos) +{ + SDL_RWops *ops = getPrivateData(self); + + long long pos = SDL_RWtell(ops); // Will return -1 if it doesn't work + return LL2NUM(pos); +} + VALUE kernelLoadDataInt(const char *filename, bool rubyExc) { @@ -227,8 +235,12 @@ fileIntBindingInit() _rb_define_method(klass, "read", fileIntRead); _rb_define_method(klass, "getbyte", fileIntGetByte); -#ifdef OLD_RUBY // Marshal looks for 'getc', not 'getbyte' +#ifdef OLD_RUBY + // Ruby doesn't see this as an initialized stream, + // so either that has to be fixed or necessary + // IO functions have to be overridden rb_define_alias(klass, "getc", "getbyte"); + _rb_define_method(klass, "pos", fileIntPos); #endif _rb_define_method(klass, "binmode", fileIntBinmode); _rb_define_method(klass, "close", fileIntClose);