add bindings for the readline callback interface#8
add bindings for the readline callback interface#8tlilyh wants to merge 2 commits intoshaleh:masterfrom
Conversation
add bindings for `rl_callback_handler_install`, `rl_callback_read_char`, and `rl_callback_handler_remove`, as well as two private utility functions and a global store for the non-extern handler.
| /// panicking. | ||
| pub fn rl_callback_handler_install(prompt: &str, lhandler: fn(Option<String>)) { | ||
| let cprmt = CString::new(prompt).unwrap().as_ptr(); | ||
| unsafe { _lhandler = Some(lhandler); } |
There was a problem hiding this comment.
hmmmm. Not sure how I feel about this. lhandler is left as a Some value but it won't be useful to the next caller. what if coerced_callback was used as a curried/partial function instead?
There was a problem hiding this comment.
That's what I would like to do in the ideal case, however I don't know how to correctly pass a curried function (=closure) as a pointer to a c function.
|
I like the idea of this patch. However, I am not sold on the dangling static |
|
You're right; that's definitely a hack. I've been contemplating this for a bit, but I haven't thought of anything better (yet, hopefully!) The primary issue is that readline really wants a pointer to a (extern c) function, and I'm not sure how to coerce any kind of closure to that. |
|
I will take a swing at it but it might be a few days. |
|
Could you either update example.rs or include a new async-example.rs that demonstrates the use of the new routines? I am a big fan of shipping tests with code. Plus, it gives me something to work with when I try to experiment with patches. |
|
Done. It's pretty simple, closely paralleling the other example, and doesn't usefully use the aynchronous property of the callback interface, but it demos how it works. It may be worth abstracting from the C interface such that rl_callback_read_char() returns an Option directly, but the obvious way to do this still involves nasty bare globals. |
|
Perfect. Thank you. |
add bindings for
rl_callback_handler_install,rl_callback_read_char,and
rl_callback_handler_remove, as well as two private utilityfunctions and a global store for the non-extern handler.