sandal (owner)

Revisions

gist: 118802 Download_button fork
public
Public Clone URL: git://gist.github.com/118802.git
Embed All Files: show embed
miles_davis.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require "ffi"
 
module MilesDavis
  class Client
    def initialize
      @server_id = API.PCMSOpenServer(0,0)
    end
 
    def practical_distance(loc1, loc2)
      API.PCMSCalcDistance(@server_id, loc1, loc2) / 10.0
    end
 
    def disconnect
      API.PCMSCloseServer(@server_id)
    end
 
  end
 
  module API
    extend FFI::Library
    ffi_lib "C:/Windows/pcmsrv32.dll"
 
    attach_function :PCMSOpenServer, [:int, :int], :short
    attach_function :PCMSCloseServer, [:short], :int
    attach_function :PCMSCalcDistance, [:short, :string, :string], :long
  end
 
end
 
client = MilesDavis::Client.new
puts client.practical_distance("Chicago, IL", "New York, NY")
client.disconnect