Created
February 8, 2017 22:37
-
-
Save barafael/351a43889ebea07fbe9e8d7d23bd8999 to your computer and use it in GitHub Desktop.
Attempting to link to extern C code in this simple rust echo program
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
extern crate rustyline; | |
use rustyline::error::ReadlineError; | |
use rustyline::Editor; | |
#[link(name = "mpc")] | |
extern { | |
fn mpc_new(s: &str) -> *mut mpc_parser_t; | |
} | |
fn main() { | |
let mut rl = Editor::<()>::new(); | |
loop { | |
let readline = rl.readline("lispy >> "); | |
match readline { | |
Ok(line) => { | |
if line == "exit" || line == "quit" { | |
break | |
} | |
rl.add_history_entry(&line); | |
println!("{}", line); | |
}, | |
Err(ReadlineError::Interrupted) => { | |
println!("CTRL-C"); | |
break | |
}, | |
Err(ReadlineError::Eof) => { | |
println!("CTRL-D"); | |
break | |
}, | |
Err(err) => { | |
println!("Error: {:?}", err); | |
break | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
mpc.c and mpc.h are found here:
https://github.com/orangeduck/mpc