vm.new_pyobj

This commit is contained in:
Jeong YunWon
2020-08-09 23:42:04 +09:00
parent 4506e21af9
commit df20a26253

View File

@@ -40,8 +40,8 @@ use crate::obj::objstr::{PyString, PyStringRef};
use crate::obj::objtuple::PyTuple;
use crate::obj::objtype::{self, PyClassRef};
use crate::pyobject::{
BorrowValue, IdProtocol, ItemProtocol, PyContext, PyObject, PyObjectRef, PyRef, PyResult,
PyValue, TryFromObject, TryIntoRef, TypeProtocol,
BorrowValue, IdProtocol, IntoPyObject, ItemProtocol, PyContext, PyObject, PyObjectRef, PyRef,
PyResult, PyValue, TryFromObject, TryIntoRef, TypeProtocol,
};
use crate::scope::Scope;
use crate::stdlib;
@@ -379,6 +379,11 @@ impl VirtualMachine {
class.downcast().expect("not a class")
}
/// Create a new python object
pub fn new_pyobj<T: IntoPyObject>(&self, value: T) -> PyObjectRef {
value.into_pyobject(self)
}
/// Create a new python string object.
pub fn new_str(&self, s: String) -> PyObjectRef {
self.ctx.new_str(s)