Working example

This commit is contained in:
2025-08-24 22:40:48 +02:00
parent f55ca91cf9
commit 6c58156286
7 changed files with 62 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
use std::{ffi::CString, fs, path::Path};
#[link(name = "python3.13")]
extern "C" {
fn Py_Initialize();
fn PyRun_SimpleString(command: *const i8) -> i32;
fn Py_Finalize();
}
pub fn run_py(path: &Path) {
let code = fs::read_to_string(path).expect("Failed to read python script");
unsafe {
Py_Initialize();
let code = CString::new(code.as_str()).unwrap();
PyRun_SimpleString(code.as_ptr());
Py_Finalize();
}
}
+6
View File
@@ -0,0 +1,6 @@
use std::path::Path;
use flux_rt::run_py;
fn main() {
run_py(Path::new("bro.py"));
}