Implement Process.cwd (#41)
* Implement `Process.cwd` * Update `os` test suite
This commit is contained in:
parent
2de2d26528
commit
1ab88ed201
@ -25,6 +25,7 @@ extern void fileWriteBytes(WrenVM* vm);
|
||||
extern void platformIsPosix(WrenVM* vm);
|
||||
extern void platformName(WrenVM* vm);
|
||||
extern void processAllArguments(WrenVM* vm);
|
||||
extern void processCwd(WrenVM* vm);
|
||||
extern void statPath(WrenVM* vm);
|
||||
extern void statBlockCount(WrenVM* vm);
|
||||
extern void statBlockSize(WrenVM* vm);
|
||||
@ -165,6 +166,7 @@ static ModuleRegistry modules[] =
|
||||
END_CLASS
|
||||
CLASS(Process)
|
||||
STATIC_METHOD("allArguments", processAllArguments)
|
||||
STATIC_METHOD("cwd", processCwd)
|
||||
END_CLASS
|
||||
END_MODULE
|
||||
MODULE(repl)
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
#include "os.h"
|
||||
#include "uv.h"
|
||||
#include "wren.h"
|
||||
|
||||
#if __APPLE__
|
||||
@ -68,4 +69,19 @@ void processAllArguments(WrenVM* vm)
|
||||
wrenSetSlotString(vm, 1, args[i]);
|
||||
wrenInsertInList(vm, 0, -1, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void processCwd(WrenVM* vm)
|
||||
{
|
||||
wrenEnsureSlots(vm, 1);
|
||||
|
||||
char buffer[PATH_MAX * 4];
|
||||
size_t length = sizeof(buffer);
|
||||
if (uv_cwd(buffer, &length) != 0)
|
||||
{
|
||||
wrenSetSlotString(vm, 0, "Cannot get current working directory.");
|
||||
return wrenAbortFiber(vm, 0);
|
||||
}
|
||||
|
||||
wrenSetSlotString(vm, 0, buffer);
|
||||
}
|
||||
|
||||
@ -10,4 +10,5 @@ class Process {
|
||||
static arguments { allArguments[2..-1] }
|
||||
|
||||
foreign static allArguments
|
||||
foreign static cwd
|
||||
}
|
||||
|
||||
@ -12,4 +12,5 @@ static const char* osModuleSource =
|
||||
" static arguments { allArguments[2..-1] }\n"
|
||||
"\n"
|
||||
" foreign static allArguments\n"
|
||||
" foreign static cwd\n"
|
||||
"}\n";
|
||||
|
||||
8
test/os/process/cwd.wren
Normal file
8
test/os/process/cwd.wren
Normal file
@ -0,0 +1,8 @@
|
||||
import "io" for File, Directory
|
||||
import "os" for Process
|
||||
|
||||
System.print(Process.cwd is String) // expect: true
|
||||
System.print(!Process.cwd.isEmpty) // expect: true
|
||||
System.print(Process.cwd.startsWith("/")) // expect: true
|
||||
System.print(File.realPath(Process.cwd) == Process.cwd) // expect: true
|
||||
System.print(Directory.exists(Process.cwd)) // expect: true
|
||||
Loading…
Reference in New Issue
Block a user