Command line arguments

This commit is contained in:
2025-08-25 19:13:00 +10:00
parent 1c5ca8d201
commit c952be1fe6
2 changed files with 22 additions and 0 deletions

View File

@@ -2194,6 +2194,16 @@ int main(int argc, char** argv) {
cout << "Usage: " << argv[0] << " (file)" << endl; cout << "Usage: " << argv[0] << " (file)" << endl;
exit(0); exit(0);
} }
// Get args
List argsList;
for (int i = 2; i < argc; i++) {
Literal lit;
lit.val = argv[i];
argsList.val.push_back(lit);
}
lists["args"] = argsList;
ifstream file(argv[1]); ifstream file(argv[1]);
string lns; string lns;
string in; string in;

12
tests/args.grnd Executable file
View File

@@ -0,0 +1,12 @@
#!/usr/bin/env ground
stdlnout "Program args: "
getlistsize *args &argsSize
set &counter 0
@loopstart
equal $counter $argsSize &bool
if $bool %end
getlistat *args $counter &item
stdlnout $item
add 1 $counter &counter
jump %loopstart
@end