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:
@@ -0,0 +1,23 @@
|
||||
#include "process.h"
|
||||
#include "wren.h"
|
||||
|
||||
int numArgs;
|
||||
const char** args;
|
||||
|
||||
void processSetArguments(int argc, const char* argv[])
|
||||
{
|
||||
numArgs = argc;
|
||||
args = argv;
|
||||
}
|
||||
|
||||
void processAllArguments(WrenVM* vm)
|
||||
{
|
||||
wrenEnsureSlots(vm, 2);
|
||||
wrenSetSlotNewList(vm, 0);
|
||||
|
||||
for (int i = 0; i < numArgs; i++)
|
||||
{
|
||||
wrenSetSlotString(vm, 1, args[i]);
|
||||
wrenInsertInList(vm, 0, -1, 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#ifndef process_h
|
||||
#define process_h
|
||||
|
||||
#include "wren.h"
|
||||
|
||||
// Stores the command line arguments passed to the CLI.
|
||||
void processSetArguments(int argc, const char* argv[]);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,6 @@
|
||||
class Process {
|
||||
// TODO: This will need to be smarter when wren supports CLI options.
|
||||
static arguments { allArguments[2..-1] }
|
||||
|
||||
foreign static allArguments
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// Generated automatically from src/module/process.wren. Do not edit.
|
||||
static const char* processModuleSource =
|
||||
"class Process {\n"
|
||||
" static arguments { allArguments[2..-1] }\n"
|
||||
"\n"
|
||||
" foreign static allArguments\n"
|
||||
"}\n";
|
||||
Reference in New Issue
Block a user