Skip to content

Commit 9220b2e

Browse files
committed
make adding a single module simpler for interpreter users
1 parent 11d700d commit 9220b2e

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/interpreter.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ impl InterpreterConfig {
2929
self.init_hooks.push(hook);
3030
self
3131
}
32+
pub fn add_native_module(
33+
self,
34+
name: impl ToOwned<Owned = String>,
35+
make_module: fn(&VirtualMachine) -> rustpython_vm::PyObjectRef,
36+
) -> Self {
37+
let name = name.to_owned();
38+
self.init_hook(Box::new(move |vm| {
39+
vm.add_native_module(name, Box::new(make_module))
40+
}))
41+
}
3242
#[cfg(feature = "stdlib")]
3343
pub fn init_stdlib(self) -> Self {
3444
self.init_hook(Box::new(init_stdlib))

0 commit comments

Comments
 (0)