diff options
author | Li Jin <dragon-fly@qq.com> | 2020-04-09 11:17:09 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2020-04-09 11:17:09 +0800 |
commit | c987e51417b54df0fd84ebb32919e68630779e82 (patch) | |
tree | 11d489ad7946316efb3244af40d79dabe9c0222c /src | |
parent | 3e022c96f9ee16fc5d47e56b7b1d0595e30eb938 (diff) | |
download | yuescript-c987e51417b54df0fd84ebb32919e68630779e82.tar.gz yuescript-c987e51417b54df0fd84ebb32919e68630779e82.tar.bz2 yuescript-c987e51417b54df0fd84ebb32919e68630779e82.zip |
make -p option work with other compile options for moonp.
Diffstat (limited to 'src')
-rw-r--r-- | src/moonp.cpp | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/src/moonp.cpp b/src/moonp.cpp index e056aad..94cba03 100644 --- a/src/moonp.cpp +++ b/src/moonp.cpp | |||
@@ -417,9 +417,9 @@ int main(int narg, const char** args) { | |||
417 | } | 417 | } |
418 | } | 418 | } |
419 | auto result = MoonP::MoonCompiler{nullptr, openlibs}.compile(s, config); | 419 | auto result = MoonP::MoonCompiler{nullptr, openlibs}.compile(s, config); |
420 | if (!std::get<0>(result).empty()) { | 420 | if (std::get<1>(result).empty()) { |
421 | if (!writeToFile) { | 421 | if (!writeToFile) { |
422 | return std::tuple{1, file.first, std::get<0>(result) + '\n'}; | 422 | return std::tuple{0, file.first, std::get<0>(result) + '\n'}; |
423 | } else { | 423 | } else { |
424 | fs::path targetFile; | 424 | fs::path targetFile; |
425 | if (!resultFile.empty()) { | 425 | if (!resultFile.empty()) { |
@@ -483,9 +483,14 @@ int main(int narg, const char** args) { | |||
483 | if (minify) { | 483 | if (minify) { |
484 | std::ifstream input(file, std::ios::in); | 484 | std::ifstream input(file, std::ios::in); |
485 | if (input) { | 485 | if (input) { |
486 | std::string s( | 486 | std::string s; |
487 | (std::istreambuf_iterator<char>(input)), | 487 | if (writeToFile) { |
488 | std::istreambuf_iterator<char>()); | 488 | s = std::string( |
489 | (std::istreambuf_iterator<char>(input)), | ||
490 | std::istreambuf_iterator<char>()); | ||
491 | } else { | ||
492 | s = msg; | ||
493 | } | ||
489 | input.close(); | 494 | input.close(); |
490 | int top = lua_gettop(L); | 495 | int top = lua_gettop(L); |
491 | DEFER(lua_settop(L, top)); | 496 | DEFER(lua_settop(L, top)); |
@@ -498,10 +503,14 @@ int main(int narg, const char** args) { | |||
498 | } else { | 503 | } else { |
499 | size_t size = 0; | 504 | size_t size = 0; |
500 | const char* minifiedCodes = lua_tolstring(L, -1, &size); | 505 | const char* minifiedCodes = lua_tolstring(L, -1, &size); |
501 | std::ofstream output(file, std::ios::trunc | std::ios::out); | 506 | if (writeToFile) { |
502 | output.write(minifiedCodes, size); | 507 | std::ofstream output(file, std::ios::trunc | std::ios::out); |
503 | output.close(); | 508 | output.write(minifiedCodes, size); |
504 | std::cout << "Minified built "sv << file << '\n'; | 509 | output.close(); |
510 | std::cout << "Minified built "sv << file << '\n'; | ||
511 | } else { | ||
512 | std::cout << minifiedCodes << '\n'; | ||
513 | } | ||
505 | } | 514 | } |
506 | } else { | 515 | } else { |
507 | ret = 2; | 516 | ret = 2; |