X Tutup
Skip to content

Commit b309004

Browse files
committed
Move main.rs to lib.rs
1 parent 0cbdb8a commit b309004

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/main.rs renamed to src/lib.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ use std::str::FromStr;
2323

2424
mod shell;
2525

26-
fn main() {
26+
pub use rustpython_vm;
27+
28+
pub fn run<F>(init: F) -> !
29+
where
30+
F: FnOnce(&mut VirtualMachine),
31+
{
2732
#[cfg(feature = "flame-it")]
2833
let main_guard = flame::start_guard("RustPython main");
2934
env_logger::init();
@@ -45,13 +50,16 @@ fn main() {
4550
}
4651

4752
// We only include the standard library bytecode in WASI when initializing
48-
let init = if cfg!(target_os = "wasi") {
53+
let init_param = if cfg!(target_os = "wasi") {
4954
InitParameter::Internal
5055
} else {
5156
InitParameter::External
5257
};
5358

54-
let interp = Interpreter::new(settings, init);
59+
let interp = Interpreter::new_with_init(settings, |vm| {
60+
init(vm);
61+
init_param
62+
});
5563

5664
let exitcode = interp.enter(move |vm| {
5765
let res = run_rustpython(vm, &matches);
@@ -110,7 +118,7 @@ fn main() {
110118
exitcode
111119
});
112120

113-
process::exit(exitcode);
121+
process::exit(exitcode)
114122
}
115123

116124
fn flush_std(vm: &VirtualMachine) {

0 commit comments

Comments
 (0)
X Tutup