Skip to content

Instantly share code, notes, and snippets.

@barafael
Created February 8, 2017 22:37
Show Gist options
  • Save barafael/351a43889ebea07fbe9e8d7d23bd8999 to your computer and use it in GitHub Desktop.
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
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
}
}
}
}
@barafael
Copy link
Author

barafael commented Feb 8, 2017

mpc.c and mpc.h are found here:
https://github.com/orangeduck/mpc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment