main.cpp: Force runtime exit when using node.js
Signed-off-by: Username404 <w.iron.zombie@gmail.com>
This commit is contained in:
parent
dedb12470e
commit
1aada9d23f
|
@ -34,6 +34,13 @@
|
|||
#include <iostream>
|
||||
#ifdef EMSCRIPTEN
|
||||
#include <emscripten.h>
|
||||
static bool is_node;
|
||||
void exit(int status) {
|
||||
if (is_node) emscripten_force_exit(status); else emscripten_exit_with_live_runtime();
|
||||
std::exit(status);
|
||||
}
|
||||
#else
|
||||
using std::exit;
|
||||
#endif
|
||||
|
||||
namespace Yerbacon {
|
||||
|
@ -49,7 +56,7 @@ namespace Yerbacon {
|
|||
std::cout << current_string;
|
||||
});
|
||||
std::cout << std::endl;
|
||||
std::exit(EXIT_FAILURE);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
inline void fail(const char* reason) { fail({reason}); }
|
||||
class Exception: public std::exception {
|
||||
|
|
25
src/main.cpp
25
src/main.cpp
|
@ -19,6 +19,9 @@ int main(int argc, char* argv[]) {
|
|||
using unit_result = pair<string, optional<Yerbacon::Exception>>;
|
||||
using unit = future<unit_result>;
|
||||
map<string_view, unit> Units;
|
||||
#ifdef EMSCRIPTEN
|
||||
is_node = MAIN_THREAD_EM_ASM_INT({ return ENVIRONMENT_IS_NODE; });
|
||||
#endif
|
||||
for (signed int i = 1; i < argc; ++i)
|
||||
{
|
||||
const string_view currentArgument (argv[i]);
|
||||
|
@ -54,17 +57,15 @@ int main(int argc, char* argv[]) {
|
|||
const string directory = filesystem::path(file_path.value()).remove_filename();
|
||||
for (unsigned int character = 1; character < directory.size(); ++character) {
|
||||
const string sub_directory = directory.substr(0, character);
|
||||
if ((directory[character] == '/') and not filesystem::is_directory(sub_directory)) {
|
||||
if (is_node and (directory[character] == '/') and not filesystem::is_directory(sub_directory)) {
|
||||
MAIN_THREAD_EM_ASM({
|
||||
if ((typeof process !== 'undefined') && (process.release.name === 'node')) {
|
||||
const sub_directory = UTF8ToString($0);
|
||||
if (!FS.isMountpoint(sub_directory)) {
|
||||
try {
|
||||
FS.mkdir(sub_directory);
|
||||
FS.mount(NODEFS, {root: sub_directory}, sub_directory);
|
||||
} catch (exception) {}
|
||||
};
|
||||
}
|
||||
const sub_directory = UTF8ToString($0);
|
||||
if (!FS.isMountpoint(sub_directory)) {
|
||||
try {
|
||||
FS.mkdir(sub_directory);
|
||||
FS.mount(NODEFS, {root: sub_directory}, sub_directory);
|
||||
} catch (exception) {}
|
||||
};
|
||||
}, sub_directory.c_str());
|
||||
}
|
||||
}
|
||||
|
@ -108,9 +109,9 @@ int main(int argc, char* argv[]) {
|
|||
} else {
|
||||
cout << "Compilation"; if (not text_provided) cout << " of " << result.first; cout << " has failed with the following error:" << endl;
|
||||
cerr << result.second.value().what() << '\n';
|
||||
return EXIT_FAILURE;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
} else cout << (!text_provided ? "No valid file provided" : "No text was provided") << ".\n";
|
||||
return EXIT_SUCCESS;
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
Loading…
Reference in New Issue