Created
January 13, 2015 12:17
-
-
Save Inari-Whitebear/fcee70f34d2d3cdce396 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
#[no_mangle] | |
pub extern "C" fn test() -> int { | |
return 1; | |
} |
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::dynamic_lib::DynamicLibrary; | |
use std::os; | |
fn print_type_of<T>(_: &T) -> () { | |
let type_name = | |
unsafe { | |
(*std::intrinsics::get_tydesc::<T>()).name | |
}; | |
println!("{}", type_name); | |
} | |
fn load_plugin(raw_path: &'static str) { | |
let path = Path::new(raw_path); | |
let path = os::make_absolute(&path).unwrap(); | |
let lib = match DynamicLibrary::open(Some(&path)) { | |
Ok(lib) => lib, | |
Err(error) => panic!("Could not load lib: {}", error) | |
}; | |
let test: *mut fn() -> int = unsafe { | |
match lib.symbol::<fn() -> int>("test") { | |
Err(error) => panic!("Could not load function: {}", error), | |
Ok(test) => test | |
} | |
}; | |
println!("a"); | |
print_type_of(&test); | |
let c = unsafe { | |
(*test)() | |
}; | |
print_type_of(&c); | |
println!("Returned: {}", c); | |
} | |
fn main() { | |
load_plugin("./plugins/plugintest.dll") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment