diff options
author | Li Jin <dragon-fly@qq.com> | 2023-07-31 14:56:49 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2023-07-31 14:56:49 +0800 |
commit | 0380be2756cd2513a2b42e6e334eaa010489ae31 (patch) | |
tree | 1c8952a58418a7fc4728e41a865d9760d8177e9d /src/yue.cpp | |
parent | a89680fe48dd1520843d7629e2006f732e313200 (diff) | |
download | yuescript-0380be2756cd2513a2b42e6e334eaa010489ae31.tar.gz yuescript-0380be2756cd2513a2b42e6e334eaa010489ae31.tar.bz2 yuescript-0380be2756cd2513a2b42e6e334eaa010489ae31.zip |
fix the way options table passing to compiler.
Diffstat (limited to 'src/yue.cpp')
-rw-r--r-- | src/yue.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/yue.cpp b/src/yue.cpp index dc42ff5..96bee0b 100644 --- a/src/yue.cpp +++ b/src/yue.cpp | |||
@@ -510,6 +510,7 @@ int main(int narg, const char** args) { | |||
510 | } | 510 | } |
511 | lua_setglobal(L, "arg"); | 511 | lua_setglobal(L, "arg"); |
512 | std::ifstream input(evalStr, std::ios::in); | 512 | std::ifstream input(evalStr, std::ios::in); |
513 | int argNum = 2; | ||
513 | if (input) { | 514 | if (input) { |
514 | auto ext = fs::path(evalStr).extension().string(); | 515 | auto ext = fs::path(evalStr).extension().string(); |
515 | for (auto& ch : ext) ch = std::tolower(ch); | 516 | for (auto& ch : ext) ch = std::tolower(ch); |
@@ -523,12 +524,38 @@ int main(int narg, const char** args) { | |||
523 | std::istreambuf_iterator<char>()); | 524 | std::istreambuf_iterator<char>()); |
524 | lua_pushlstring(L, s.c_str(), s.size()); | 525 | lua_pushlstring(L, s.c_str(), s.size()); |
525 | lua_pushlstring(L, evalStr.c_str(), evalStr.size()); | 526 | lua_pushlstring(L, evalStr.c_str(), evalStr.size()); |
527 | if (ext != ".lua") { | ||
528 | argNum = 3; | ||
529 | lua_newtable(L); | ||
530 | lua_newtable(L); | ||
531 | for (int j = i; j < narg; j++) { | ||
532 | std::string argItem = args[j]; | ||
533 | if (argItem.size() > 2 && argItem.substr(0, 2) == "--"sv && argItem.substr(2, 1) != "-"sv) { | ||
534 | auto argStr = argItem.substr(2); | ||
535 | yue::Utils::trim(argStr); | ||
536 | size_t idx = argStr.find('='); | ||
537 | if (idx != std::string::npos) { | ||
538 | auto key = argStr.substr(0, idx); | ||
539 | auto value = argStr.substr(idx + 1); | ||
540 | yue::Utils::trim(key); | ||
541 | yue::Utils::trim(value); | ||
542 | lua_pushlstring(L, key.c_str(), key.size()); | ||
543 | lua_pushlstring(L, value.c_str(), value.size()); | ||
544 | } else { | ||
545 | lua_pushlstring(L, argStr.c_str(), argStr.size()); | ||
546 | lua_pushliteral(L, ""); | ||
547 | } | ||
548 | lua_rawset(L, -3); | ||
549 | } | ||
550 | } | ||
551 | lua_setfield(L, -2, "options"); | ||
552 | } | ||
526 | } else { | 553 | } else { |
527 | pushYue(L, "loadstring"sv); | 554 | pushYue(L, "loadstring"sv); |
528 | lua_pushlstring(L, evalStr.c_str(), evalStr.size()); | 555 | lua_pushlstring(L, evalStr.c_str(), evalStr.size()); |
529 | lua_pushliteral(L, "=(eval str)"); | 556 | lua_pushliteral(L, "=(eval str)"); |
530 | } | 557 | } |
531 | if (lua_pcall(L, 2, 2, 0) != 0) { | 558 | if (lua_pcall(L, argNum, 2, 0) != 0) { |
532 | std::cout << lua_tostring(L, -1) << '\n'; | 559 | std::cout << lua_tostring(L, -1) << '\n'; |
533 | return 1; | 560 | return 1; |
534 | } | 561 | } |