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>
|
#include <iostream>
|
||||||
#ifdef EMSCRIPTEN
|
#ifdef EMSCRIPTEN
|
||||||
#include <emscripten.h>
|
#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
|
#endif
|
||||||
|
|
||||||
namespace Yerbacon {
|
namespace Yerbacon {
|
||||||
|
@ -49,7 +56,7 @@ namespace Yerbacon {
|
||||||
std::cout << current_string;
|
std::cout << current_string;
|
||||||
});
|
});
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
std::exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
inline void fail(const char* reason) { fail({reason}); }
|
inline void fail(const char* reason) { fail({reason}); }
|
||||||
class Exception: public std::exception {
|
class Exception: public std::exception {
|
||||||
|
|
11
src/main.cpp
11
src/main.cpp
|
@ -19,6 +19,9 @@ int main(int argc, char* argv[]) {
|
||||||
using unit_result = pair<string, optional<Yerbacon::Exception>>;
|
using unit_result = pair<string, optional<Yerbacon::Exception>>;
|
||||||
using unit = future<unit_result>;
|
using unit = future<unit_result>;
|
||||||
map<string_view, unit> Units;
|
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)
|
for (signed int i = 1; i < argc; ++i)
|
||||||
{
|
{
|
||||||
const string_view currentArgument (argv[i]);
|
const string_view currentArgument (argv[i]);
|
||||||
|
@ -54,9 +57,8 @@ int main(int argc, char* argv[]) {
|
||||||
const string directory = filesystem::path(file_path.value()).remove_filename();
|
const string directory = filesystem::path(file_path.value()).remove_filename();
|
||||||
for (unsigned int character = 1; character < directory.size(); ++character) {
|
for (unsigned int character = 1; character < directory.size(); ++character) {
|
||||||
const string sub_directory = directory.substr(0, 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({
|
MAIN_THREAD_EM_ASM({
|
||||||
if ((typeof process !== 'undefined') && (process.release.name === 'node')) {
|
|
||||||
const sub_directory = UTF8ToString($0);
|
const sub_directory = UTF8ToString($0);
|
||||||
if (!FS.isMountpoint(sub_directory)) {
|
if (!FS.isMountpoint(sub_directory)) {
|
||||||
try {
|
try {
|
||||||
|
@ -64,7 +66,6 @@ int main(int argc, char* argv[]) {
|
||||||
FS.mount(NODEFS, {root: sub_directory}, sub_directory);
|
FS.mount(NODEFS, {root: sub_directory}, sub_directory);
|
||||||
} catch (exception) {}
|
} catch (exception) {}
|
||||||
};
|
};
|
||||||
}
|
|
||||||
}, sub_directory.c_str());
|
}, sub_directory.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,9 +109,9 @@ int main(int argc, char* argv[]) {
|
||||||
} else {
|
} else {
|
||||||
cout << "Compilation"; if (not text_provided) cout << " of " << result.first; cout << " has failed with the following error:" << endl;
|
cout << "Compilation"; if (not text_provided) cout << " of " << result.first; cout << " has failed with the following error:" << endl;
|
||||||
cerr << result.second.value().what() << '\n';
|
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";
|
} else cout << (!text_provided ? "No valid file provided" : "No text was provided") << ".\n";
|
||||||
return EXIT_SUCCESS;
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
Loading…
Reference in New Issue