Skip to content

Instantly share code, notes, and snippets.

@Earlz
Created January 12, 2014 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Earlz/8391463 to your computer and use it in GitHub Desktop.
Save Earlz/8391463 to your computer and use it in GitHub Desktop.
use std::io::println;
use std::c_str::CString;
use std::libc::c_char;
#[no_mangle]
pub extern fn foorust() {
println("hello from rust!");
}
#[no_mangle]
pub extern fn rust_add(op1: i32, op2: i32) -> i32 {
return op1+op2;
}
#[no_mangle]
pub extern fn rust_strings(s: *c_char) -> i32{
unsafe{
let cs=CString::new(s. false);
let st=cs.as_str();
match(st){
Some(ref ts) => {
return 0;
},
None => println("Error!")
}
}
return 1;
}
rustc --dylib test.rs
test.rs:18:16: 18:39 error: this function takes 2 parameters but 1 parameter was supplied
test.rs:18 let cs=CString::new(s. false);
^~~~~~~~~~~~~~~~~~~~~~~
test.rs:18:29: 18:37 error: attempted access of field `false` on type `*i8`, but no field with that name was found
test.rs:18 let cs=CString::new(s. false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment