Created
November 17, 2015 17:26
-
-
Save ane/fef5b05882ad90511482 to your computer and use it in GitHub Desktop.
Guile REPL in Rust
This file contains hidden or 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
use std::ffi::CString; | |
use std::env; | |
use std::ptr; | |
use libc::{c_char, c_void, c_int}; | |
#[link(name="guile-2.0")] | |
extern { | |
fn scm_shell(argc: c_int, argv: *const *const c_char) -> c_void; | |
fn scm_boot_guile(argc: c_int, | |
argv: *const *const c_char, | |
main_func: extern fn(data: *mut c_void, argc: c_int, argv: *const *const c_char) -> c_void, | |
data: *mut c_void); | |
} | |
extern "C" fn inner_main(_: *mut c_void, argc: c_int, argv: *const *const c_char) -> c_void { | |
unsafe { | |
scm_shell(argc, argv) | |
} | |
} | |
pub fn start_repl() { | |
let argv: Vec<CString> = env::args().into_iter().map(|arg| { CString::new(arg).unwrap() } ).collect(); | |
let args: Vec<*const c_char> = argv.into_iter().map(|arg| { arg.as_ptr() } ).collect(); | |
unsafe { | |
scm_boot_guile(args.len() as c_int, args.as_ptr() as *const *const c_char, inner_main, ptr::null_mut()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment