Skip to content

Instantly share code, notes, and snippets.

@practicingruby
Created May 27, 2009 18:27
Show Gist options
  • Select an option

  • Save practicingruby/118802 to your computer and use it in GitHub Desktop.

Select an option

Save practicingruby/118802 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment