diff options
| author | Li Jin <dragon-fly@qq.com> | 2026-07-03 09:49:00 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2026-07-03 09:49:00 +0800 |
| commit | c9f3a486cfdad6e134ec88b1e43717508e066796 (patch) | |
| tree | bf1ad02d9a590d438a552b481bc924715496ac97 /src | |
| parent | 7bb66616ff5a6d3f6f3b35c68fa9a908af034884 (diff) | |
| download | yuescript-0.34.1.tar.gz yuescript-0.34.1.tar.bz2 yuescript-0.34.1.zip | |
Fix execute arg table layoutv0.34.1
Diffstat (limited to '')
| -rw-r--r-- | src/yue.cpp | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/src/yue.cpp b/src/yue.cpp index 0493205..4bb4e70 100644 --- a/src/yue.cpp +++ b/src/yue.cpp | |||
| @@ -580,17 +580,28 @@ int main(int narg, const char** args) { | |||
| 580 | std::cout << lua_tostring(L, -1) << '\n'; | 580 | std::cout << lua_tostring(L, -1) << '\n'; |
| 581 | return 1; | 581 | return 1; |
| 582 | } | 582 | } |
| 583 | lua_newtable(L); | ||
| 584 | i++; | 583 | i++; |
| 585 | for (int j = i, index = 1; j < narg; j++) { | 584 | auto setArgTable = [&](std::string_view scriptName, int tokensBeforeScript) { |
| 586 | lua_pushstring(L, args[j]); | 585 | lua_newtable(L); |
| 587 | lua_rawseti(L, -2, index); | 586 | for (int j = i, index = 1; j < narg; j++) { |
| 588 | index++; | 587 | lua_pushstring(L, args[j]); |
| 589 | } | 588 | lua_rawseti(L, -2, index); |
| 590 | lua_setglobal(L, "arg"); | 589 | index++; |
| 590 | } | ||
| 591 | if (!scriptName.empty()) { | ||
| 592 | lua_pushlstring(L, scriptName.data(), scriptName.size()); | ||
| 593 | lua_rawseti(L, -2, 0); | ||
| 594 | for (int j = 0, index = -tokensBeforeScript; j < tokensBeforeScript; j++, index++) { | ||
| 595 | lua_pushstring(L, args[j]); | ||
| 596 | lua_rawseti(L, -2, index); | ||
| 597 | } | ||
| 598 | } | ||
| 599 | lua_setglobal(L, "arg"); | ||
| 600 | }; | ||
| 591 | std::ifstream input(evalStr, std::ios::in); | 601 | std::ifstream input(evalStr, std::ios::in); |
| 592 | int argNum = 2; | 602 | int argNum = 2; |
| 593 | if (input) { | 603 | if (input) { |
| 604 | setArgTable(evalStr, i - 1); | ||
| 594 | auto ext = fs::path(evalStr).extension().string(); | 605 | auto ext = fs::path(evalStr).extension().string(); |
| 595 | for (auto& ch : ext) ch = std::tolower(ch); | 606 | for (auto& ch : ext) ch = std::tolower(ch); |
| 596 | if (ext == ".lua") { | 607 | if (ext == ".lua") { |
| @@ -630,6 +641,7 @@ int main(int narg, const char** args) { | |||
| 630 | lua_setfield(L, -2, "options"); | 641 | lua_setfield(L, -2, "options"); |
| 631 | } | 642 | } |
| 632 | } else { | 643 | } else { |
| 644 | setArgTable({ }, 0); | ||
| 633 | pushYue(L, "loadstring"sv); | 645 | pushYue(L, "loadstring"sv); |
| 634 | lua_pushlstring(L, evalStr.c_str(), evalStr.size()); | 646 | lua_pushlstring(L, evalStr.c_str(), evalStr.size()); |
| 635 | lua_pushliteral(L, "=(eval str)"); | 647 | lua_pushliteral(L, "=(eval str)"); |
