Very new to Ruby--needs help


#1

Dear Ruby Gurus,

I would like to load a *.lib file into my *.rb file. How to do that. I
did mentioned the path but was not successful. I did this:

load (or require) “PATH name:*.lib”

thx,
Mankan


#2

Beginner wrote:

Dear Ruby Gurus,

I would like to load a *.lib file into my *.rb file. How to do that. I
did mentioned the path but was not successful. I did this:

load (or require) “PATH name:*.lib”

What is in the .lib file?

If it is ruby code (in which case you should just
change it to .rb anyway:),

require “#{path}/foobar.lib”

Should work fine.

If it is object code, I believe ruby can only load
.so (and, I assume, .dll) files so you may need to
extract the shared library.

If it is just plain text or something, you would
want to use File.open(filename) {|f| do_something_with f }.

Please clarify a bit and I am sure we can help you
get it working right!

thx,
Mankan

E


#3

Dear Eero,

Thank you very much. it is a low-level APIs named power32.lib and I
would like to call this APIs from ruby to find the hardware parameters
like number of boards etc.

Hence I am looking for loading this power32.lib file and then call the
low-level API from Ruby.

Pls do let me know if the question is still not clear.

thx in advance,
Mankan


#4

Beginner wrote:

Mankan

The “require” statement loads Ruby extensions, either those written in
pure Ruby or those written in C using the Ruby extension API. So you
can’t use it to interface to an arbitrary .dll or .lib file.

There is a Ruby library that allows you to call functions in .dll files,
though. Check out the Win32API class:
http://www.rubycentral.com/book/lib_windows.html

You might also learn more about the Win32API library by searching
through old postings to this list. Search for “Win32API”.

Welcome to Ruby!


#5

Dear Eero,

I am not able to load even .dll, this is what I did:

require “C:\WINDOWS\SYSTEM32\abc.dll”

I am doing anything wrong. The .dll does exist in the directory, I get
the erro, “the specified procedure could not be found”.(loadError)

thx,
Mankan


#6

Thank you Timothy and Patrick, I got the answer to what I am looking
for.

-Mankna


#7

On 12/20/05, Beginner removed_email_address@domain.invalid wrote:

I am not able to load even .dll, this is what I did:

require “C:\WINDOWS\SYSTEM32\abc.dll”

Is abc.dll the dll associated with power32.lib? Or just an example. I
am unfamiliar (as is at least a cursory Google :slight_smile: with this
particular library. Without a specific API document, I doubt we can
provide you with the level of detail you will need at this stage in
your programming career.

From a high level there are two ways normally used to access external
libraries from within Ruby:

  1. Create an extension – this requires a certain amount of C
    programming either by hand or using something like SWIG.

  2. Or using DL (http://ttsky.net/ruby/ruby-dl.html)

If you can provide a specific API for the library you may get some
additional help (even more so if the library in question is free/open
source).

Good Luck