Skip to content

Commit 3737f2a

Browse files
authored
make adding a single module simpler for interpreter users (#4792)
1 parent ac78517 commit 3737f2a

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/interpreter.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustpython_vm::{Interpreter, Settings, VirtualMachine};
1+
use rustpython_vm::{builtins::PyModule, Interpreter, PyRef, Settings, VirtualMachine};
22

33
pub type InitHook = Box<dyn FnOnce(&mut VirtualMachine)>;
44

@@ -63,6 +63,15 @@ impl InterpreterConfig {
6363
self.init_hooks.push(hook);
6464
self
6565
}
66+
pub fn add_native_module(
67+
self,
68+
name: String,
69+
make_module: fn(&VirtualMachine) -> PyRef<PyModule>,
70+
) -> Self {
71+
self.init_hook(Box::new(move |vm| {
72+
vm.add_native_module(name, Box::new(make_module))
73+
}))
74+
}
6675
#[cfg(feature = "stdlib")]
6776
pub fn init_stdlib(self) -> Self {
6877
self.init_hook(Box::new(init_stdlib))

0 commit comments

Comments
 (0)