Skip to content

Commit 01f29df

Browse files
committed
Update constructor for wasm interpreter
1 parent 90238d0 commit 01f29df

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

include/xeus-cpp/xinterpreter_wasm.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ namespace xcpp
1919
{
2020
public:
2121

22-
wasm_interpreter();
23-
wasm_interpreter(int argc, char** argv);
22+
wasm_interpreter(const std::vector<std::string>& args);
2423
virtual ~wasm_interpreter() = default;
2524

2625
};

include/xeus-cpp/xutils.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ 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);
3538
}
3639

3740
#endif

src/xinterpreter_wasm.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,11 @@
1212

1313
#include "xeus-cpp/xinterpreter.hpp"
1414
#include "xeus-cpp/xinterpreter_wasm.hpp"
15+
#include "xeus-cpp/xutils.hpp"
1516

1617
namespace xcpp
1718
{
18-
19-
wasm_interpreter::wasm_interpreter()
20-
: interpreter(0, nullptr)
21-
{
22-
}
23-
24-
wasm_interpreter::wasm_interpreter(int argc, char** argv)
25-
: interpreter(argc, argv)
26-
{
27-
}
19+
wasm_interpreter::wasm_interpreter(const std::vector<std::string>& args)
20+
: interpreter(convert_to_argv(args).first, convert_to_argv(args).second)
21+
{}
2822
}

src/xutils.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,21 @@ 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+
}
105122
}

0 commit comments

Comments
 (0)