Skip to content

Instantly share code, notes, and snippets.

@pete
Created March 12, 2009 01:28
Show Gist options
  • Save pete/77854 to your computer and use it in GitHub Desktop.
Save pete/77854 to your computer and use it in GitHub Desktop.
# THIS SHOULD NOT BE
require 'readline'
# For whatever reason, loading libreadline.so *without* loading Ruby's
# readline first makes FFI die? Seriously, comment out the above require and
# watch it fail.
require 'rubygems'
require 'ffi'
module RL
extend FFI::Library
ffi_lib 'readline'
attach_function :readline, [:string], :pointer
attach_function :free, [:pointer], :void
end
while((line = RL.readline('> '); !line.address.zero?))
puts "Got #{line.inspect} #{line.address.inspect}"
puts RL.free(line).inspect
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment