feat: add process module with arguments and allArguments static methods
- Introduce new 'process' module exposing a Process class with foreign static methods for accessing command-line arguments. - Implement processSetArguments in main.c to store argc/argv, and processAllArguments in process.c to return them as a Wren list. - Add --help flag support to CLI, printing usage with optional arguments. - Include documentation for Process.arguments and Process.allArguments, plus module index and template updates. - Register process module in modules.c and add Xcode project references for new source files. - Add test scripts for allArguments and arguments, verifying list type, count, and expected values.
This commit is contained in:
+8
-4
@@ -1,22 +1,26 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "process.h"
|
||||
#include "vm.h"
|
||||
#include "wren.h"
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
if (argc < 1 || argc > 2)
|
||||
if (argc == 2 && strcmp(argv[1], "--help") == 0)
|
||||
{
|
||||
fprintf(stderr, "Usage: wren [file]\n");
|
||||
return 64; // EX_USAGE.
|
||||
printf("Usage: wren [file] [arguments...]\n");
|
||||
printf(" --help Show command line usage\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
processSetArguments(argc, argv);
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
runRepl();
|
||||
}
|
||||
else if (argc == 2)
|
||||
else
|
||||
{
|
||||
runFile(argv[1]);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "modules.h"
|
||||
|
||||
#include "io.wren.inc"
|
||||
#include "process.wren.inc"
|
||||
#include "scheduler.wren.inc"
|
||||
#include "timer.wren.inc"
|
||||
|
||||
@@ -17,6 +18,7 @@ extern void fileClose(WrenVM* vm);
|
||||
extern void fileDescriptor(WrenVM* vm);
|
||||
extern void fileReadBytes(WrenVM* vm);
|
||||
extern void fileSize(WrenVM* vm);
|
||||
extern void processAllArguments(WrenVM* vm);
|
||||
extern void stdinReadStart(WrenVM* vm);
|
||||
extern void stdinReadStop(WrenVM* vm);
|
||||
extern void schedulerCaptureMethods(WrenVM* vm);
|
||||
@@ -109,6 +111,11 @@ static ModuleRegistry modules[] =
|
||||
STATIC_METHOD("readStop_()", stdinReadStop)
|
||||
END_CLASS
|
||||
END_MODULE
|
||||
MODULE(process)
|
||||
CLASS(Process)
|
||||
STATIC_METHOD("allArguments", processAllArguments)
|
||||
END_CLASS
|
||||
END_MODULE
|
||||
MODULE(scheduler)
|
||||
CLASS(Scheduler)
|
||||
STATIC_METHOD("captureMethods_()", schedulerCaptureMethods)
|
||||
|
||||
Reference in New Issue
Block a user