Hi, I''ve been using FFI with a Ruby 1.9.3 built with MSVC++ and it''s been working well. One thing I''ve run into though is this: ffi_lib :msvcrt But that''s not the runtime I want. But I don''t want to hard code the runtime name either. I realize I could parse it out of RbConfig, but I was hoping for something nicer. Is there a way we could create an analogue to FFI::Library::LIBC for the MSVC runtime? Something like FFI::Library::MSVCRT ? Regards, Dan
Hi, 2012/4/7 Daniel Berger <djberg96 at gmail.com>> Hi, > > I''ve been using FFI with a Ruby 1.9.3 built with MSVC++ and it''s been > working well. One thing I''ve run into though is this: > > ffi_lib :msvcrt > > But that''s not the runtime I want. But I don''t want to hard code the > runtime name either. I realize I could parse it out of RbConfig, but I > was hoping for something nicer. > > Is there a way we could create an analogue to FFI::Library::LIBC for > the MSVC runtime? Something like FFI::Library::MSVCRT ? > >I can find msvcrt runtime like this: def find_msvcrt require ''rbconfig'' RbConfig::CONFIG[''RUBY_SO_NAME''].split(''-'')[-2]+''.dll'' end Did you mean this seems ugly? Well, I cannot find a nicer method than above one. Regards, Park Heesob -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/win32utils-devel/attachments/20120407/3a51251f/attachment-0001.html>
On Sat, Apr 7, 2012 at 11:47 AM, Heesob Park <phasis at gmail.com> wrote:> Hi, > > > 2012/4/7 Daniel Berger <djberg96 at gmail.com> >> >> Hi, >> >> I''ve been using FFI with a Ruby 1.9.3 built with MSVC++ and it''s been >> working well. One thing I''ve run into though is this: >> >> ffi_lib :msvcrt >> >> But that''s not the runtime I want. But I don''t want to hard code the >> runtime name either. I realize I could parse it out of RbConfig, but I >> was hoping for something nicer. >> >> Is there a way we could create an analogue to FFI::Library::LIBC for >> the MSVC runtime? Something like FFI::Library::MSVCRT ? >> > > I can find msvcrt runtime like this: > > def find_msvcrt > require ''rbconfig'' > RbConfig::CONFIG[''RUBY_SO_NAME''].split(''-'')[-2]+''.dll'' > end > > Did you mean this seems ugly? > > Well, I cannot find a nicer method than above one. >Maybe something that correct the MSVCRT issue instead? Here is the source of FFI::Library::MSVCRT: https://github.com/ffi/ffi/blob/master/lib/ffi/platform.rb#L92-98 Perhaps something that uses RbConfig::CONFIG["RUBY_SO_NAME"] and extract from it? I bet Wayne (from FFI project) would love the contribution. -- Luis Lavena AREA 17 - Perfection in design is achieved not when there is nothing more to add, but rather when there is nothing more to take away. Antoine de Saint-Exup?ry
On Sat, Apr 7, 2012 at 8:47 AM, Heesob Park <phasis at gmail.com> wrote:> Hi, > > > 2012/4/7 Daniel Berger <djberg96 at gmail.com> >> >> Hi, >> >> I''ve been using FFI with a Ruby 1.9.3 built with MSVC++ and it''s been >> working well. One thing I''ve run into though is this: >> >> ffi_lib :msvcrt >> >> But that''s not the runtime I want. But I don''t want to hard code the >> runtime name either. I realize I could parse it out of RbConfig, but I >> was hoping for something nicer. >> >> Is there a way we could create an analogue to FFI::Library::LIBC for >> the MSVC runtime? Something like FFI::Library::MSVCRT ? >> > > I can find msvcrt runtime like this: > > def find_msvcrt > require ''rbconfig'' > RbConfig::CONFIG[''RUBY_SO_NAME''].split(''-'')[-2]+''.dll'' > end > > Did you mean this seems ugly? > > Well, I cannot find a nicer method than above one.Ok, thanks. I thought maybe there was a better way. I''ve submitted a pull request: https://github.com/ffi/ffi/pull/199 It does feel a little funny overloading LIBC like that, but I guess I''m ok with it. :) Thanks again. Dan
Hi, <snip>>> I can find msvcrt runtime like this: >> >> def find_msvcrt >> require ''rbconfig'' >> RbConfig::CONFIG[''RUBY_SO_NAME''].split(''-'')[-2]+''.dll'' >> end >> >> Did you mean this seems ugly? >> >> Well, I cannot find a nicer method than above one. > > Ok, thanks. I thought maybe there was a better way. > > I''ve submitted a pull request: https://github.com/ffi/ffi/pull/199Oops, I discovered that at least one company renamed it. Their RUBY_SO_NAME value is the name of their company, which does not have a hyphen in it. How''s this? RbConfig::CONFIG[''RUBY_SO_NAME''].split(''-'').first + ''.dll'' Or was the -2 index significant? Regards, Dan
Hi, 2012/7/31 Daniel Berger <djberg96 at gmail.com>> Hi, > > <snip> > > >> I can find msvcrt runtime like this: > >> > >> def find_msvcrt > >> require ''rbconfig'' > >> RbConfig::CONFIG[''RUBY_SO_NAME''].split(''-'')[-2]+''.dll'' > >> end > >> > >> Did you mean this seems ugly? > >> > >> Well, I cannot find a nicer method than above one. > > > > Ok, thanks. I thought maybe there was a better way. > > > > I''ve submitted a pull request: https://github.com/ffi/ffi/pull/199 > > Oops, I discovered that at least one company renamed it. Their > RUBY_SO_NAME value is the name of their company, which does not have a > hyphen in it. > > How''s this? > > RbConfig::CONFIG[''RUBY_SO_NAME''].split(''-'').first + ''.dll'' > > Or was the -2 index significant? > > Why we should consider the modified RUBY_SO_NAME?The -2 index is due to the 64 bit RUBY_SO_NAME which is like "*x64*-*msvcrt* -*ruby191**".* Regards, Park Heesob -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/win32utils-devel/attachments/20120731/d2ce6c48/attachment.html>