File tree Expand file tree Collapse file tree 5 files changed +23
-26
lines changed Expand file tree Collapse file tree 5 files changed +23
-26
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ namespace xcpp
1919 {
2020 public:
2121
22- wasm_interpreter (const std::vector<std::string>& args );
22+ wasm_interpreter (int argc = 0 , char ** argv = nullptr );
2323 virtual ~wasm_interpreter () = default ;
2424
2525 };
Original file line number Diff line number Diff line change @@ -32,9 +32,6 @@ namespace xcpp
3232
3333 XEUS_CPP_API
3434 std::string retrieve_tagfile_dir ();
35-
36- XEUS_CPP_API
37- std::pair<int , char **> convert_to_argv (const std::vector<std::string>& args);
3835}
3936
4037#endif
Original file line number Diff line number Diff line change 1515
1616#include " xeus-cpp/xinterpreter_wasm.hpp"
1717
18+ template <class interpreter_type >
19+ interpreter_type* builder_with_args (emscripten::val js_args)
20+ {
21+ static std::vector<std::string> args = emscripten::vecFromJSArray<std::string>(js_args);
22+ static std::vector<const char *> argv_vec;
23+
24+ for (const auto & s : args)
25+ {
26+ argv_vec.push_back (s.c_str ());
27+ }
28+
29+ int argc = static_cast <int >(argv_vec.size ());
30+ char ** argv = const_cast <char **>(argv_vec.data ());
31+
32+ return new interpreter_type (argc, argv);
33+ }
34+
1835EMSCRIPTEN_BINDINGS (my_module)
1936{
2037 xeus::export_core ();
2138 using interpreter_type = xcpp::wasm_interpreter;
22- xeus::export_kernel<interpreter_type>(" xkernel" );
39+ xeus::export_kernel<interpreter_type, &builder_with_args<interpreter_type> >(" xkernel" );
2340}
Original file line number Diff line number Diff line change 1212
1313#include " xeus-cpp/xinterpreter.hpp"
1414#include " xeus-cpp/xinterpreter_wasm.hpp"
15- #include " xeus-cpp/xutils.hpp"
1615
1716namespace xcpp
1817{
19- wasm_interpreter::wasm_interpreter (const std::vector<std::string>& args)
20- : interpreter(convert_to_argv(args).first, convert_to_argv(args).second)
21- {}
18+ wasm_interpreter::wasm_interpreter (int argc, char ** argv)
19+ : interpreter(argc, argv)
20+ {
21+ }
2222}
Original file line number Diff line number Diff line change @@ -102,21 +102,4 @@ namespace xcpp
102102
103103 return prefix + " share" + separator + " xeus-cpp" + separator + " tagfiles" ;
104104 }
105-
106- std::pair<int , char **> convert_to_argv (const std::vector<std::string>& args)
107- {
108- static std::vector<std::string> persistent_args = args;
109- static std::vector<const char *> argv_vec;
110-
111- argv_vec.clear ();
112- for (const auto & s : persistent_args)
113- {
114- argv_vec.push_back (s.c_str ());
115- }
116-
117- return {
118- static_cast <int >(argv_vec.size ()),
119- const_cast <char **>(argv_vec.data ())
120- };
121- }
122105}
You can’t perform that action at this time.
0 commit comments