Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Process.version #42

Merged
merged 3 commits into from
Jun 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/cli/modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 processVersion(WrenVM* vm);
extern void processCwd(WrenVM* vm);
extern void statPath(WrenVM* vm);
extern void statBlockCount(WrenVM* vm);
Expand Down Expand Up @@ -166,6 +167,7 @@ static ModuleRegistry modules[] =
END_CLASS
CLASS(Process)
STATIC_METHOD("allArguments", processAllArguments)
STATIC_METHOD("version", processVersion)
STATIC_METHOD("cwd", processCwd)
END_CLASS
END_MODULE
Expand Down
6 changes: 6 additions & 0 deletions src/module/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ void processAllArguments(WrenVM* vm)
}
}


void processVersion(WrenVM* vm) {
wrenEnsureSlots(vm, 1);
wrenSetSlotString(vm, 0, WREN_VERSION_STRING);
}

void processCwd(WrenVM* vm)
{
wrenEnsureSlots(vm, 1);
Expand Down
1 change: 1 addition & 0 deletions src/module/os.wren
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ class Process {
static arguments { allArguments[2..-1] }

foreign static allArguments
foreign static version
foreign static cwd
}
1 change: 1 addition & 0 deletions src/module/os.wren.inc
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ static const char* osModuleSource =
" static arguments { allArguments[2..-1] }\n"
"\n"
" foreign static allArguments\n"
" foreign static version\n"
" foreign static cwd\n"
"}\n";
7 changes: 7 additions & 0 deletions test/os/process/version.wren
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import "os" for Process

System.print(Process.version is String) // expect: true
System.print(Process.version.isEmpty) // expect: false

var isNumber = Fn.new {|str| Num.fromString(str) != null }
System.print(Process.version.split(".").all(isNumber)) // expect: true