Skip to content

Commit c65c2ff

Browse files
committed
make adding a single module simpler for interpreter users
1 parent a6a9212 commit c65c2ff

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

@@ -29,6 +29,15 @@ impl InterpreterConfig {
2929
self.init_hooks.push(hook);
3030
self
3131
}
32+
pub fn add_native_module(
33+
self,
34+
name: String,
35+
make_module: fn(&VirtualMachine) -> PyRef<PyModule>,
36+
) -> Self {
37+
self.init_hook(Box::new(move |vm| {
38+
vm.add_native_module(name, Box::new(make_module))
39+
}))
40+
}
3241
#[cfg(feature = "stdlib")]
3342
pub fn init_stdlib(self) -> Self {
3443
self.init_hook(Box::new(init_stdlib))

0 commit comments

Comments
 (0)