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
19
19
{
20
20
public:
21
21
22
- wasm_interpreter (const std::vector<std::string>& args );
22
+ wasm_interpreter (int argc = 0 , char ** argv = nullptr );
23
23
virtual ~wasm_interpreter () = default ;
24
24
25
25
};
Original file line number Diff line number Diff line change @@ -32,9 +32,6 @@ namespace xcpp
32
32
33
33
XEUS_CPP_API
34
34
std::string retrieve_tagfile_dir ();
35
-
36
- XEUS_CPP_API
37
- std::pair<int , char **> convert_to_argv (const std::vector<std::string>& args);
38
35
}
39
36
40
37
#endif
Original file line number Diff line number Diff line change 15
15
16
16
#include " xeus-cpp/xinterpreter_wasm.hpp"
17
17
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
+
18
35
EMSCRIPTEN_BINDINGS (my_module)
19
36
{
20
37
xeus::export_core ();
21
38
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" );
23
40
}
Original file line number Diff line number Diff line change 12
12
13
13
#include " xeus-cpp/xinterpreter.hpp"
14
14
#include " xeus-cpp/xinterpreter_wasm.hpp"
15
- #include " xeus-cpp/xutils.hpp"
16
15
17
16
namespace xcpp
18
17
{
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
+ }
22
22
}
Original file line number Diff line number Diff line change @@ -102,21 +102,4 @@ namespace xcpp
102
102
103
103
return prefix + " share" + separator + " xeus-cpp" + separator + " tagfiles" ;
104
104
}
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
- }
122
105
}
You can’t perform that action at this time.
0 commit comments