Skip to content

Commit 1ebb120

Browse files
author
unfetchable
authored
Fix argument parsing: Properly handle -- to separate files and script arguments (#90)
Previously, lute treated arguments after -- as files instead of script arguments. This caused errors like: ```sh Error opening ./1 Error opening ./2 Error opening ./3 ``` since ```1 2 3``` were misinterpreted as file paths. This PR does the following: - Ensures -- properly marks the transition between files and arguments. - Converts argv[i] from char* to std::string before pushing it into files. (Misc) Closes #86
1 parent b2cab3c commit 1ebb120

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

cli/main.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,28 @@ int main(int argc, char** argv)
201201
program_argc = argc - program_args;
202202
program_argv = &argv[program_args];
203203

204-
const std::vector<std::string> files = getSourceFiles(argc, argv);
204+
std::vector<std::string> files;
205+
206+
bool parsingFiles = true;
207+
208+
for (int i = 1; i < argc; i++)
209+
{
210+
if (strcmp(argv[i], "--") == 0)
211+
{
212+
parsingFiles = false; // stop collecting files
213+
program_argc = argc - (i + 1);
214+
program_argv = &argv[i + 1];
215+
break;
216+
}
217+
218+
if (parsingFiles)
219+
files.push_back(std::string(argv[i])); // fix: Explicit conversion
220+
}
221+
222+
if (program_argc == 0) // default to just running the script if no args are passed
223+
{
224+
program_argv = nullptr;
225+
}
205226

206227
// Given the source files, perform a typecheck here
207228
if (runTypecheck)

extern/luau/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ if(EXT_PLATFORM_STRING)
44
return()
55
endif()
66

7-
cmake_minimum_required(VERSION 3.0)
7+
cmake_minimum_required(VERSION 3.5)
88

99
option(LUAU_BUILD_CLI "Build CLI" ON)
1010
option(LUAU_BUILD_TESTS "Build tests" ON)

0 commit comments

Comments
 (0)