Hello Python
This commit is contained in:
parent
e2260a534f
commit
d63bebe601
3
build.rs
Normal file
3
build.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
fn main() {
|
||||||
|
println!("cargo:rustc-link-search=./");
|
||||||
|
}
|
14
hello_python.c
Normal file
14
hello_python.c
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
#define PY_SSIZE_T_CLEAN
|
||||||
|
#include <Python.h>
|
||||||
|
|
||||||
|
int hello_python()
|
||||||
|
{
|
||||||
|
Py_Initialize();
|
||||||
|
PyRun_SimpleString("from time import time,ctime\n"
|
||||||
|
"print('Today is', ctime(time()), 'from cpython')\n");
|
||||||
|
if (Py_FinalizeEx() < 0) {
|
||||||
|
printf("Failure during FinalizeEx");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ mod errors;
|
||||||
mod exercises;
|
mod exercises;
|
||||||
mod jour1;
|
mod jour1;
|
||||||
mod jour2;
|
mod jour2;
|
||||||
|
mod python;
|
||||||
mod rpg;
|
mod rpg;
|
||||||
mod starwars;
|
mod starwars;
|
||||||
mod tests;
|
mod tests;
|
||||||
|
@ -19,4 +20,5 @@ fn main() {
|
||||||
doc::main();
|
doc::main();
|
||||||
errors::main();
|
errors::main();
|
||||||
concurrency::main();
|
concurrency::main();
|
||||||
|
python::main();
|
||||||
}
|
}
|
||||||
|
|
9
src/python.rs
Normal file
9
src/python.rs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
pub fn main() {
|
||||||
|
#[link(name = "hello_python")]
|
||||||
|
extern "C" {
|
||||||
|
fn hello_python();
|
||||||
|
}
|
||||||
|
unsafe {
|
||||||
|
hello_python();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user