Created
January 12, 2014 22:21
-
-
Save Earlz/8391463 to your computer and use it in GitHub Desktop.
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
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