Implement Process.pid & Process.ppid (#43)
* Implement `Process.pid` & `Process.ppid` * Update `os` test suite
This commit is contained in:
parent
bfc0935e80
commit
4acf7b395d
@ -25,8 +25,10 @@ extern void fileWriteBytes(WrenVM* vm);
|
||||
extern void platformIsPosix(WrenVM* vm);
|
||||
extern void platformName(WrenVM* vm);
|
||||
extern void processAllArguments(WrenVM* vm);
|
||||
extern void processVersion(WrenVM* vm);
|
||||
extern void processCwd(WrenVM* vm);
|
||||
extern void processPid(WrenVM* vm);
|
||||
extern void processPpid(WrenVM* vm);
|
||||
extern void processVersion(WrenVM* vm);
|
||||
extern void statPath(WrenVM* vm);
|
||||
extern void statBlockCount(WrenVM* vm);
|
||||
extern void statBlockSize(WrenVM* vm);
|
||||
@ -168,8 +170,10 @@ static ModuleRegistry modules[] =
|
||||
END_CLASS
|
||||
CLASS(Process)
|
||||
STATIC_METHOD("allArguments", processAllArguments)
|
||||
STATIC_METHOD("version", processVersion)
|
||||
STATIC_METHOD("cwd", processCwd)
|
||||
STATIC_METHOD("pid", processPid)
|
||||
STATIC_METHOD("ppid", processPpid)
|
||||
STATIC_METHOD("version", processVersion)
|
||||
END_CLASS
|
||||
END_MODULE
|
||||
MODULE(repl)
|
||||
|
||||
@ -71,12 +71,6 @@ void processAllArguments(WrenVM* vm)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void processVersion(WrenVM* vm) {
|
||||
wrenEnsureSlots(vm, 1);
|
||||
wrenSetSlotString(vm, 0, WREN_VERSION_STRING);
|
||||
}
|
||||
|
||||
void processCwd(WrenVM* vm)
|
||||
{
|
||||
wrenEnsureSlots(vm, 1);
|
||||
@ -92,3 +86,18 @@ void processCwd(WrenVM* vm)
|
||||
|
||||
wrenSetSlotString(vm, 0, buffer);
|
||||
}
|
||||
|
||||
void processPid(WrenVM* vm) {
|
||||
wrenEnsureSlots(vm, 1);
|
||||
wrenSetSlotDouble(vm, 0, uv_os_getpid());
|
||||
}
|
||||
|
||||
void processPpid(WrenVM* vm) {
|
||||
wrenEnsureSlots(vm, 1);
|
||||
wrenSetSlotDouble(vm, 0, uv_os_getppid());
|
||||
}
|
||||
|
||||
void processVersion(WrenVM* vm) {
|
||||
wrenEnsureSlots(vm, 1);
|
||||
wrenSetSlotString(vm, 0, WREN_VERSION_STRING);
|
||||
}
|
||||
|
||||
4
src/module/os.wren
vendored
4
src/module/os.wren
vendored
@ -10,6 +10,8 @@ class Process {
|
||||
static arguments { allArguments.count >= 2 ? allArguments[2..-1] : [] }
|
||||
|
||||
foreign static allArguments
|
||||
foreign static version
|
||||
foreign static cwd
|
||||
foreign static pid
|
||||
foreign static ppid
|
||||
foreign static version
|
||||
}
|
||||
|
||||
@ -14,6 +14,8 @@ static const char* osModuleSource =
|
||||
" static arguments { allArguments.count >= 2 ? allArguments[2..-1] : [] }\n"
|
||||
"\n"
|
||||
" foreign static allArguments\n"
|
||||
" foreign static version\n"
|
||||
" foreign static cwd\n"
|
||||
" foreign static pid\n"
|
||||
" foreign static ppid\n"
|
||||
" foreign static version\n"
|
||||
"}\n";
|
||||
|
||||
11
test/os/process/pid_and_ppid.wren
vendored
Normal file
11
test/os/process/pid_and_ppid.wren
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
import "os" for Process
|
||||
|
||||
System.print(Process.pid is Num) // expect: true
|
||||
System.print(Process.pid.isInteger) // expect: true
|
||||
System.print(Process.pid > 0) // expect: true
|
||||
|
||||
System.print(Process.ppid is Num) // expect: true
|
||||
System.print(Process.ppid.isInteger) // expect: true
|
||||
System.print(Process.ppid > 0) // expect: true
|
||||
|
||||
System.print(Process.pid > Process.ppid) // expect: true
|
||||
Loading…
Reference in New Issue
Block a user