diff --git a/src/cli/modules.c b/src/cli/modules.c index 481c284d..1e4a1d12 100644 --- a/src/cli/modules.c +++ b/src/cli/modules.c @@ -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); @@ -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) diff --git a/src/module/os.c b/src/module/os.c index ea887196..f717e3ff 100644 --- a/src/module/os.c +++ b/src/module/os.c @@ -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__ @@ -43,7 +43,7 @@ void platformName(WrenVM* vm) void platformIsPosix(WrenVM* vm) { wrenEnsureSlots(vm, 1); - + #ifdef _WIN32 wrenSetSlotBool(vm, 0, false); #elif __APPLE__ @@ -92,3 +92,9 @@ void processCwd(WrenVM* vm) wrenSetSlotString(vm, 0, buffer); } + +void processRunCommand(WrenVM* vm) +{ + char* command = (char*)wrenGetSlotString(vm, 1); + system(command); +} diff --git a/src/module/os.wren b/src/module/os.wren index 05cc645a..8ed2edff 100644 --- a/src/module/os.wren +++ b/src/module/os.wren @@ -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) } diff --git a/src/module/os.wren.inc b/src/module/os.wren.inc index 29094989..f9175c30 100644 --- a/src/module/os.wren.inc +++ b/src/module/os.wren.inc @@ -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";