|
14 | 14 |
|
15 | 15 |
|
16 | 16 | /* definitions for Lua 5.1 only */ |
17 | | -#if defined( LUA_VERSION_NUM ) && LUA_VERSION_NUM == 501 |
| 17 | +#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM == 501 |
18 | 18 |
|
19 | 19 |
|
20 | 20 | COMPAT53_API int lua_absindex (lua_State *L, int i) { |
@@ -366,6 +366,44 @@ COMPAT53_API int luaL_fileresult (lua_State *L, int stat, const char *fname) { |
366 | 366 | return 3; |
367 | 367 | } |
368 | 368 | } |
| 369 | + |
| 370 | + |
| 371 | +#if !defined(l_inspectstat) && \ |
| 372 | + (defined(unix) || defined(__unix) || defined(__unix__) || \ |
| 373 | + defined(__TOS_AIX__) || defined(_SYSTYPE_BSD)) |
| 374 | +/* some form of unix; check feature macros in unistd.h for details */ |
| 375 | +# include <unistd.h> |
| 376 | +/* check posix version; the relevant include files and macros probably |
| 377 | + * were available before 2001, but I'm not sure */ |
| 378 | +# if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L |
| 379 | +# include <sys/wait.h> |
| 380 | +# define l_inspectstat(stat,what) \ |
| 381 | + if (WIFEXITED(stat)) { stat = WEXITSTATUS(stat); } \ |
| 382 | + else if (WIFSIGNALED(stat)) { stat = WTERMSIG(stat); what = "signal"; } |
| 383 | +# endif |
| 384 | +#endif |
| 385 | + |
| 386 | +/* provide default (no-op) version */ |
| 387 | +#if !defined(l_inspectstat) |
| 388 | +# define l_inspectstat(stat,what) ((void)0) |
| 389 | +#endif |
| 390 | + |
| 391 | + |
| 392 | +COMPAT53_API int luaL_execresult (lua_State *L, int stat) { |
| 393 | + const char *what = "exit"; |
| 394 | + if (stat == -1) |
| 395 | + return luaL_fileresult(L, 0, NULL); |
| 396 | + else { |
| 397 | + l_inspectstat(stat, what); |
| 398 | + if (*what == 'e' && stat == 0) |
| 399 | + lua_pushboolean(L, 1); |
| 400 | + else |
| 401 | + lua_pushnil(L); |
| 402 | + lua_pushstring(L, what); |
| 403 | + lua_pushinteger(L, stat); |
| 404 | + return 3; |
| 405 | + } |
| 406 | +} |
369 | 407 | #endif /* not COMPAT53_IS_LUAJIT */ |
370 | 408 |
|
371 | 409 |
|
|
0 commit comments