From b3090040f0795cb2afdae00a4ec709aaadac0405 Mon Sep 17 00:00:00 2001 From: Noah <33094578+coolreader18@users.noreply.github.com> Date: Tue, 1 Dec 2020 15:04:16 -0600 Subject: [PATCH] Move main.rs to lib.rs --- src/{main.rs => lib.rs} | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) rename src/{main.rs => lib.rs} (98%) diff --git a/src/main.rs b/src/lib.rs similarity index 98% rename from src/main.rs rename to src/lib.rs index 064b44567..56ab26413 100644 --- a/src/main.rs +++ b/src/lib.rs @@ -23,7 +23,12 @@ use std::str::FromStr; mod shell; -fn main() { +pub use rustpython_vm; + +pub fn run(init: F) -> ! +where + F: FnOnce(&mut VirtualMachine), +{ #[cfg(feature = "flame-it")] let main_guard = flame::start_guard("RustPython main"); env_logger::init(); @@ -45,13 +50,16 @@ fn main() { } // We only include the standard library bytecode in WASI when initializing - let init = if cfg!(target_os = "wasi") { + let init_param = if cfg!(target_os = "wasi") { InitParameter::Internal } else { InitParameter::External }; - let interp = Interpreter::new(settings, init); + let interp = Interpreter::new_with_init(settings, |vm| { + init(vm); + init_param + }); let exitcode = interp.enter(move |vm| { let res = run_rustpython(vm, &matches); @@ -110,7 +118,7 @@ fn main() { exitcode }); - process::exit(exitcode); + process::exit(exitcode) } fn flush_std(vm: &VirtualMachine) {