Skip to content

Commit 0bd1a3e

Browse files
committed
vm.print
1 parent 08e7ec9 commit 0bd1a3e

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

vm/src/vm/vm_object.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@ impl VirtualMachine {
156156
.invoke(args, self)
157157
}
158158

159+
/// Same as __builtins__.print in Python.
160+
/// A convenience function to provide a simple way to print objects for debug purpose.
161+
// NOTE: Keep the interface simple.
162+
pub fn print(&self, args: impl IntoFuncArgs) -> PyResult<()> {
163+
let ret = self.builtins.get_attr("print", self)?.call(args, self)?;
164+
debug_assert!(self.is_none(&ret));
165+
Ok(())
166+
}
167+
159168
#[deprecated(note = "in favor of `obj.call(args, vm)`")]
160169
pub fn invoke(&self, obj: &impl AsObject, args: impl IntoFuncArgs) -> PyResult {
161170
obj.as_object().call(args, self)

0 commit comments

Comments
 (0)