mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
...
This commit is contained in:
parent
406e10aedc
commit
6ffcbce647
@ -1069,6 +1069,23 @@ struct PyREPL{
|
|||||||
other.repl = nullptr;
|
other.repl = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct TempOut{
|
||||||
|
PrintFunc backup;
|
||||||
|
VM* vm;
|
||||||
|
TempOut(VM* vm, PrintFunc f){
|
||||||
|
this->vm = vm;
|
||||||
|
this->backup = vm->_stdout;
|
||||||
|
vm->_stdout = f;
|
||||||
|
}
|
||||||
|
~TempOut(){
|
||||||
|
vm->_stdout = backup;
|
||||||
|
}
|
||||||
|
TempOut(const TempOut&) = delete;
|
||||||
|
TempOut& operator=(const TempOut&) = delete;
|
||||||
|
TempOut(TempOut&&) = delete;
|
||||||
|
TempOut& operator=(TempOut&&) = delete;
|
||||||
|
};
|
||||||
|
|
||||||
static void _register(VM* vm, PyObject* mod, PyObject* type){
|
static void _register(VM* vm, PyObject* mod, PyObject* type){
|
||||||
vm->bind_constructor<1>(type, [](VM* vm, ArgsView args){
|
vm->bind_constructor<1>(type, [](VM* vm, ArgsView args){
|
||||||
return VAR_T(PyREPL, vm);
|
return VAR_T(PyREPL, vm);
|
||||||
@ -1077,7 +1094,11 @@ struct PyREPL{
|
|||||||
vm->bind_method<1>(type, "input", [](VM* vm, ArgsView args){
|
vm->bind_method<1>(type, "input", [](VM* vm, ArgsView args){
|
||||||
PyREPL& self = _CAST(PyREPL&, args[0]);
|
PyREPL& self = _CAST(PyREPL&, args[0]);
|
||||||
const Str& s = CAST(Str&, args[1]);
|
const Str& s = CAST(Str&, args[1]);
|
||||||
return VAR(self.repl->input(s.str()));
|
static std::stringstream ss_out;
|
||||||
|
ss_out.str("");
|
||||||
|
TempOut _(vm, [](VM* vm, const Str& s){ ss_out << s; });
|
||||||
|
bool ok = self.repl->input(s.str());
|
||||||
|
return VAR(Tuple({VAR(ok), VAR(ss_out.str())}));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user