feat: rename process module to os and add Platform class with name and isPosix methods

Rename the "process" module to "os" across all source files, documentation, tests, and build configuration. Add a new Platform class to the os module with static methods `name` (returns OS string like "Windows", "Linux", "OS X", "iOS", "Unix", "POSIX", or "Unknown") and `isPosix` (returns bool indicating POSIX compliance). Update all import paths from "process" to "os" in test files and module registrations. Move process.c/h to os.c/h, rename processSetArguments to osSetArguments, and regenerate the os.wren.inc bytecode source. Add documentation pages for the os module and Platform class.
This commit is contained in:
Bob Nystrom
2016-05-21 19:44:17 +00:00
parent c5e1c2e57f
commit 95ef1a2814
20 changed files with 170 additions and 65 deletions
+71
View File
@@ -0,0 +1,71 @@
#include "os.h"
#include "wren.h"
#if __APPLE__
#include "TargetConditionals.h"
#endif
int numArgs;
const char** args;
void osSetArguments(int argc, const char* argv[])
{
numArgs = argc;
args = argv;
}
void platformName(WrenVM* vm)
{
wrenEnsureSlots(vm, 1);
#ifdef _WIN32
wrenSetSlotString(vm, 0, "Windows");
#elif __APPLE__
#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
wrenSetSlotString(vm, 0, "iOS");
#elif TARGET_OS_MAC
wrenSetSlotString(vm, 0, "OS X");
#else
wrenSetSlotString(vm, 0, "Unknown");
#endif
#elif __linux__
wrenSetSlotString(vm, 0, "Linux");
#elif __unix__
wrenSetSlotString(vm, 0, "Unix");
#elif defined(_POSIX_VERSION)
wrenSetSlotString(vm, 0, "POSIX");
#else
wrenSetSlotString(vm, 0, "Unknown");
#endif
}
void platformIsPosix(WrenVM* vm)
{
wrenEnsureSlots(vm, 1);
#ifdef _WIN32
wrenSetSlotBool(vm, 0, false);
#elif __APPLE__
wrenSetSlotBool(vm, 0, true);
#elif __linux__
wrenSetSlotBool(vm, 0, true);
#elif __unix__
wrenSetSlotBool(vm, 0, true);
#elif defined(_POSIX_VERSION)
wrenSetSlotBool(vm, 0, true);
#else
wrenSetSlotString(vm, 0, false);
#endif
}
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);
}
}
+1 -1
View File
@@ -4,6 +4,6 @@
#include "wren.h"
// Stores the command line arguments passed to the CLI.
void processSetArguments(int argc, const char* argv[]);
void osSetArguments(int argc, const char* argv[]);
#endif
@@ -1,3 +1,8 @@
class Platform {
foreign static isPosix
foreign static name
}
class Process {
// TODO: This will need to be smarter when wren supports CLI options.
static arguments { allArguments[2..-1] }
+13
View File
@@ -0,0 +1,13 @@
// Generated automatically from src/module/os.wren. Do not edit.
static const char* osModuleSource =
"class Platform {\n"
" foreign static isPosix\n"
" foreign static name\n"
"}\n"
"\n"
"class Process {\n"
" // TODO: This will need to be smarter when wren supports CLI options.\n"
" static arguments { allArguments[2..-1] }\n"
"\n"
" foreign static allArguments\n"
"}\n";
-23
View File
@@ -1,23 +0,0 @@
#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);
}
}
-7
View File
@@ -1,7 +0,0 @@
// 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";