From adcbe1f23213cb16cfc1b194836b5d30bb36dbc1 Mon Sep 17 00:00:00 2001 From: Rexo35 <98764898+Rexo35@users.noreply.github.com> Date: Tue, 23 Aug 2022 18:29:36 +0200 Subject: [PATCH 1/4] Add the "ZS.System.Command" function Add the "ZS.System.Command" function in order to run console commands. Something like pythons os.system() function. --- ZSharp/builtin.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ZSharp/builtin.h b/ZSharp/builtin.h index 4fda055..83f8306 100644 --- a/ZSharp/builtin.h +++ b/ZSharp/builtin.h @@ -13,6 +13,7 @@ #include #include #include +#include // for console command printing #include "strops.h" #include "graphics.h" @@ -467,6 +468,8 @@ boost::any ZSFunction(const string& name, const vector& args) Vec2 v(AnyAsFloat(args.at(0)), AnyAsFloat(args.at(1))); return v; } + else if (name == "ZS.System.Command") + temp = system(StringRaw(AnyAsString(args.at(0)))); else LogWarning("ZS function \'" + name + "\' does not exist."); From 0af8f5fff73a882184a5fc26b74983511c267961 Mon Sep 17 00:00:00 2001 From: Rexo35 <98764898+Rexo35@users.noreply.github.com> Date: Tue, 23 Aug 2022 22:02:17 +0200 Subject: [PATCH 2/4] Update builtin.h --- ZSharp/builtin.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZSharp/builtin.h b/ZSharp/builtin.h index 83f8306..a845beb 100644 --- a/ZSharp/builtin.h +++ b/ZSharp/builtin.h @@ -469,7 +469,7 @@ boost::any ZSFunction(const string& name, const vector& args) return v; } else if (name == "ZS.System.Command") - temp = system(StringRaw(AnyAsString(args.at(0)))); + int temp = system(StringRaw(AnyAsString(args.at(0)))); else LogWarning("ZS function \'" + name + "\' does not exist."); From eda78e8c399a59ca0cb20d1ccce6cb10b60ab739 Mon Sep 17 00:00:00 2001 From: Rexo35 <98764898+Rexo35@users.noreply.github.com> Date: Tue, 23 Aug 2022 22:11:15 +0200 Subject: [PATCH 3/4] Update builtin.h --- ZSharp/builtin.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ZSharp/builtin.h b/ZSharp/builtin.h index a845beb..c66f1cd 100644 --- a/ZSharp/builtin.h +++ b/ZSharp/builtin.h @@ -468,8 +468,13 @@ boost::any ZSFunction(const string& name, const vector& args) Vec2 v(AnyAsFloat(args.at(0)), AnyAsFloat(args.at(1))); return v; } - else if (name == "ZS.System.Command") - int temp = system(StringRaw(AnyAsString(args.at(0)))); + else if (name == "ZS.System.Command"){ + string command = StringRaw(AnyAsString(args.at(0))); + int command_len = command.length(); + char command_char_arr[command_len + 1]; + strcpy(command_char_arr, command.c_str()); // string into char arr + int k = system(command_char_arr); + } else LogWarning("ZS function \'" + name + "\' does not exist."); From d7c79c66018d50cb10012be536cf7f1b108e2a9f Mon Sep 17 00:00:00 2001 From: sam-astro <77079540+sam-astro@users.noreply.github.com> Date: Sun, 28 Aug 2022 12:43:01 -0400 Subject: [PATCH 4/4] Simplify and make work without warnings --- ZSharp/builtin.h | 16 ++++++++++++---- examples/console_application.zs | 5 +++++ 2 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 examples/console_application.zs diff --git a/ZSharp/builtin.h b/ZSharp/builtin.h index c66f1cd..72f0669 100644 --- a/ZSharp/builtin.h +++ b/ZSharp/builtin.h @@ -1,6 +1,14 @@ #ifndef BUILTIN_H #define BUILTIN_H +#if defined(__unix__) +#define UNIX true +#define WINDOWS false +#elif defined(_MSC_VER) +#define UNIX false +#define WINDOWS true +#endif + #include #include #include @@ -470,10 +478,10 @@ boost::any ZSFunction(const string& name, const vector& args) } else if (name == "ZS.System.Command"){ string command = StringRaw(AnyAsString(args.at(0))); - int command_len = command.length(); - char command_char_arr[command_len + 1]; - strcpy(command_char_arr, command.c_str()); // string into char arr - int k = system(command_char_arr); + //int command_len = command.length(); + //char* command_char_arr=new char[command_len + 1]; + //strcpy(command_char_arr, command.c_str()); // string into char arr + int k = system(command.c_str()); } else LogWarning("ZS function \'" + name + "\' does not exist."); diff --git a/examples/console_application.zs b/examples/console_application.zs new file mode 100644 index 0000000..07d48b9 --- /dev/null +++ b/examples/console_application.zs @@ -0,0 +1,5 @@ +func Main() +{ + Printl("this is a test:") + ZS.System.Command("cls") +} \ No newline at end of file