Created
November 1, 2011 18:11
-
-
Save cjameshuff/1331403 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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