Skip to content

Instantly share code, notes, and snippets.

@cjameshuff
Created November 1, 2011 18:11
Show Gist options
  • Save cjameshuff/1331403 to your computer and use it in GitHub Desktop.
Save cjameshuff/1331403 to your computer and use it in GitHub Desktop.
require 'inline'
class BetterReadline
inline :C do |builder|
builder.include '<ruby.h>'
builder.include '<readline/readline.h>'
src = <<END
VALUE readline_intern(void * data) {
char ** rstr = (char **)data;
*rstr = readline(NULL);
return Qnil;
}
END
builder.prefix(src)
src = <<END
VALUE rb_readline(void) {
char * str = NULL;
rb_thread_blocking_region(readline_intern, &str, NULL, NULL);
return rb_str_new2(str);
}
END
builder.c(src, method_name: 'readline')
end
end # class BetterReadline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment