- Fix deprecated `system` in Lua for iOS 11 (not tested) ios-develop
authorantonc27 <antonc27@mail.ru>
Fri, 29 Dec 2017 19:06:10 +0100
branchios-develop
changeset 12872 0a18aaa0d329
parent 12871 13143137c2ff
child 12873 81433734052e
- Fix deprecated `system` in Lua for iOS 11 (not tested)
misc/liblua/loslib.c
--- a/misc/liblua/loslib.c	Fri Dec 29 16:53:37 2017 +0100
+++ b/misc/liblua/loslib.c	Fri Dec 29 19:06:10 2017 +0100
@@ -19,6 +19,17 @@
 #include "lauxlib.h"
 #include "lualib.h"
 
+#if ((defined __MACH__) && (defined __APPLE__))
+  #include <TargetConditionals.h>
+  #if TARGET_OS_IPHONE
+    #define LUA_PLATFORM_IOS 1
+  #endif
+#endif
+
+#ifdef LUA_PLATFORM_IOS
+  #include <spawn.h>
+  extern char **environ;
+#endif
 
 static int os_pushresult (lua_State *L, int i, const char *filename) {
   int en = errno;  /* calls to Lua API may change this value */
@@ -36,7 +47,18 @@
 
 
 static int os_execute (lua_State *L) {
-  lua_pushinteger(L, system(luaL_optstring(L, 1, NULL)));
+  const char *command = luaL_optstring(L, 1, NULL);
+  int status;
+#ifndef LUA_PLATFORM_IOS
+  status = system(command);
+#else
+  // untested, may require adjustments depending on `command`
+  pid_t pid;
+  char *argv[] = { (char *)command, NULL };
+  posix_spawn(&pid, argv[0], NULL, NULL, argv, environ);
+  waitpid(pid, &status, 0);
+#endif
+  lua_pushinteger(L, status);
   return 1;
 }