lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> We could add the appropriate conditionals to avoid calling system in
iOS but we don't have access to iOS development platforms.
I would love to help by testing on iOS platforms.

> We could not find official documentation on this issue.

The stack overflow post you mentioned (https://stackoverflow.com/a/5920028/107090) is the de facto best reference of the available conditionals. It is up to date and tried and tested in our development.

To see the exact platforms Apple has decided to remove system(…) from, here the relevant section of the stdlib.h from my local (macOS 12.3) SDK:

__swift_unavailable("Use posix_spawn APIs or NSTask instead. (On iOS, process spawning is unavailable.)")
__API_AVAILABLE(macos(10.0)) __IOS_PROHIBITED
__WATCHOS_PROHIBITED __TVOS_PROHIBITED
int system(const char *) __DARWIN_ALIAS_C(system);

> If someone can provide trusted and tested code for this that is
current, please post here.

I have tested both of the code snippets mentioned this morning (http://lua-users.org/lists/lua-l/2019-11/msg00095.html and http://lua-users.org/lists/lua-l/2018-07/msg00243.html) and both work well, however the first one does the if-conditionals better, since it exactly replicates the platforms where system is unavailable. Finally, as a third option, my current local solution to this issue is as following:

#if __APPLE__
#include "TargetConditionals.h"
#if TARGET_OS_IOS || TARGET_OS_WATCH || TARGET_OS_TV
#define LUA_SYSTEM_UNAVAILABLE 1
#endif
#endif

static int os_execute (lua_State *L) {
#if LUA_SYSTEM_UNAVAILABLE
  return luaL_error(L, "os_execute not available on iOS");
#else
  lua_pushinteger(L, system(luaL_optstring(L, 1, NULL)));
  return 1;
#endif
}

Thank you very much for your time.

Greetings,
Julian Müller-Huschke