Add a Platform class.
- Rename the "process" module to "os". - Add Platform to it. - Static "name" method. - Static "isPosix" method. - Docs and tests!
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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] }
|
||||
@@ -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";
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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";
|
||||
Reference in New Issue
Block a user