Skip to content
Closed
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 @@ -27,6 +27,7 @@ extern void platformName(WrenVM* vm);
extern void processAllArguments(WrenVM* vm);
extern void processVersion(WrenVM* vm);
extern void processCwd(WrenVM* vm);
extern void processRunCommand(WrenVM* vm);
extern void statPath(WrenVM* vm);
extern void statBlockCount(WrenVM* vm);
extern void statBlockSize(WrenVM* vm);
Expand Down Expand Up @@ -169,6 +170,7 @@ static ModuleRegistry modules[] =
STATIC_METHOD("allArguments", processAllArguments)
STATIC_METHOD("version", processVersion)
STATIC_METHOD("cwd", processCwd)
STATIC_METHOD("runCommand_(_)", processRunCommand)
END_CLASS
END_MODULE
MODULE(repl)
Expand Down
10 changes: 8 additions & 2 deletions src/module/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void osSetArguments(int argc, const char* argv[])
void platformName(WrenVM* vm)
{
wrenEnsureSlots(vm, 1);

#ifdef _WIN32
wrenSetSlotString(vm, 0, "Windows");
#elif __APPLE__
Expand All @@ -43,7 +43,7 @@ void platformName(WrenVM* vm)
void platformIsPosix(WrenVM* vm)
{
wrenEnsureSlots(vm, 1);

#ifdef _WIN32
wrenSetSlotBool(vm, 0, false);
#elif __APPLE__
Expand Down Expand Up @@ -92,3 +92,9 @@ void processCwd(WrenVM* vm)

wrenSetSlotString(vm, 0, buffer);
}

void processRunCommand(WrenVM* vm)
{
char* command = (char*)wrenGetSlotString(vm, 1);
system(command);
}
5 changes: 5 additions & 0 deletions src/module/os.wren
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ class Process {
foreign static allArguments
foreign static version
foreign static cwd
static exec(command){
if(!(command is String)) Fiber.abort("Command must be a string")
runCommand_(command)
}
foreign static runCommand_(command)
}
5 changes: 5 additions & 0 deletions src/module/os.wren.inc
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ static const char* osModuleSource =
" foreign static allArguments\n"
" foreign static version\n"
" foreign static cwd\n"
" static exec(command){\n"
" if(!(command is String)) Fiber.abort(\"Command must be a string\")\n"
" runCommand_(command)\n"
" }\n"
" foreign static runCommand_(command)\n"
"}\n";