misc/liblua/loslib.c
branchios-develop
changeset 12872 0a18aaa0d329
parent 2812 0a24853de796
equal deleted inserted replaced
12871:13143137c2ff 12872:0a18aaa0d329
    17 #include "lua.h"
    17 #include "lua.h"
    18 
    18 
    19 #include "lauxlib.h"
    19 #include "lauxlib.h"
    20 #include "lualib.h"
    20 #include "lualib.h"
    21 
    21 
       
    22 #if ((defined __MACH__) && (defined __APPLE__))
       
    23   #include <TargetConditionals.h>
       
    24   #if TARGET_OS_IPHONE
       
    25     #define LUA_PLATFORM_IOS 1
       
    26   #endif
       
    27 #endif
       
    28 
       
    29 #ifdef LUA_PLATFORM_IOS
       
    30   #include <spawn.h>
       
    31   extern char **environ;
       
    32 #endif
    22 
    33 
    23 static int os_pushresult (lua_State *L, int i, const char *filename) {
    34 static int os_pushresult (lua_State *L, int i, const char *filename) {
    24   int en = errno;  /* calls to Lua API may change this value */
    35   int en = errno;  /* calls to Lua API may change this value */
    25   if (i) {
    36   if (i) {
    26     lua_pushboolean(L, 1);
    37     lua_pushboolean(L, 1);
    34   }
    45   }
    35 }
    46 }
    36 
    47 
    37 
    48 
    38 static int os_execute (lua_State *L) {
    49 static int os_execute (lua_State *L) {
    39   lua_pushinteger(L, system(luaL_optstring(L, 1, NULL)));
    50   const char *command = luaL_optstring(L, 1, NULL);
       
    51   int status;
       
    52 #ifndef LUA_PLATFORM_IOS
       
    53   status = system(command);
       
    54 #else
       
    55   // untested, may require adjustments depending on `command`
       
    56   pid_t pid;
       
    57   char *argv[] = { (char *)command, NULL };
       
    58   posix_spawn(&pid, argv[0], NULL, NULL, argv, environ);
       
    59   waitpid(pid, &status, 0);
       
    60 #endif
       
    61   lua_pushinteger(L, status);
    40   return 1;
    62   return 1;
    41 }
    63 }
    42 
    64 
    43 
    65 
    44 static int os_remove (lua_State *L) {
    66 static int os_remove (lua_State *L) {