@@ -22,13 +22,13 @@ namespace pyjs
2222 namespace py = pybind11;
2323
2424
25- em::val eval (const std::string & code, py::object & globals)
25+ em::val eval (const std::string & code, py::object & globals , py::object & locals )
2626 {
2727 em::val ret = em::val::object ();;
2828 ret.set (" has_err" , false );
2929 try
3030 {
31- py::object py_ret = py::eval (code, globals);
31+ py::object py_ret = py::eval (code, globals, locals );
3232 auto [jsval, is_proxy] = implicit_py_to_js (py_ret);
3333 ret.set (" ret" ,jsval);
3434 ret.set (" is_proxy" ,is_proxy);
@@ -45,13 +45,13 @@ namespace pyjs
4545
4646
4747
48- em::val exec (const std::string & code, py::object & globals)
48+ em::val exec (const std::string & code, py::object & globals, py::object & locals )
4949 {
5050 em::val ret = em::val::object ();
5151 ret.set (" has_err" , false );
5252 try
5353 {
54- py::exec (code, globals);
54+ py::exec (code, globals, locals );
5555 return ret;
5656 }
5757 catch (py::error_already_set& e)
@@ -65,12 +65,12 @@ namespace pyjs
6565 }
6666
6767
68- em::val eval_file (const std::string & filename, py::object & globals)
68+ em::val eval_file (const std::string & filename, py::object & globals, py::object & locals)
6969 {
7070 em::val ret = em::val::object ();
7171 try
7272 {
73- py::eval_file (filename, globals);
73+ py::eval_file (filename, globals, locals );
7474 ret.set (" has_err" ,em::val (false ));
7575 return ret;
7676 }
@@ -138,15 +138,15 @@ namespace pyjs
138138 export_py_object ();
139139
140140 // // main scope
141- // em::function("main_scope",em::select_overload<py::object()>(
142- // []()->py::object{
143- // std::cout<<"get scope"<<std::endl;
144- // auto scope = py::module_::import("__main__").attr("__dict__");
145- // //py::exec("import pyjs;import asyncio", scope);
146- // std::cout<<"get scope DONE"<<std::endl;
147- // return scope;
148- // }
149- // ));
141+ em::function (" main_scope" ,em::select_overload<py::object ()>(
142+ []()->py ::object{
143+ std::cout<<" get scope" <<std::endl;
144+ auto scope = py::module_::import (" __main__" ).attr (" __dict__" );
145+ // py::exec("import pyjs;import asyncio", scope);
146+ std::cout<<" get scope DONE" <<std::endl;
147+ return scope;
148+ }
149+ ));
150150
151151
152152 em::function (" globals" , +[]()->py ::object{
0 commit comments