aboutsummaryrefslogtreecommitdiff
path: root/c-api
diff options
context:
space:
mode:
authorPhilipp Janda <siffiejoe@gmx.net>2015-05-20 07:25:48 +0200
committerPhilipp Janda <siffiejoe@gmx.net>2015-05-20 07:25:48 +0200
commitba065189ae67822ac9c69cc6ba633e3e8e123ef6 (patch)
tree8f064b13129834749ae72c03c15e46ab20adadc2 /c-api
parentae91294546c2edc60e3349e909740f15c939f1af (diff)
downloadlua-compat-5.3-ba065189ae67822ac9c69cc6ba633e3e8e123ef6.tar.gz
lua-compat-5.3-ba065189ae67822ac9c69cc6ba633e3e8e123ef6.tar.bz2
lua-compat-5.3-ba065189ae67822ac9c69cc6ba633e3e8e123ef6.zip
Add luaL_execresult to C API.
Diffstat (limited to 'c-api')
-rw-r--r--c-api/compat-5.3.c40
-rw-r--r--c-api/compat-5.3.h4
2 files changed, 42 insertions, 2 deletions
diff --git a/c-api/compat-5.3.c b/c-api/compat-5.3.c
index 962b951..0e06176 100644
--- a/c-api/compat-5.3.c
+++ b/c-api/compat-5.3.c
@@ -14,7 +14,7 @@
14 14
15 15
16/* definitions for Lua 5.1 only */ 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
20COMPAT53_API int lua_absindex (lua_State *L, int i) { 20COMPAT53_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 return 3; 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
392COMPAT53_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#endif /* not COMPAT53_IS_LUAJIT */ 407#endif /* not COMPAT53_IS_LUAJIT */
370 408
371 409
diff --git a/c-api/compat-5.3.h b/c-api/compat-5.3.h
index dc8d3ea..cd6764c 100644
--- a/c-api/compat-5.3.h
+++ b/c-api/compat-5.3.h
@@ -45,7 +45,6 @@
45 * lua_upvaluejoin 45 * lua_upvaluejoin
46 * lua_version 46 * lua_version
47 * lua_yieldk 47 * lua_yieldk
48 * luaL_execresult
49 * luaL_loadbufferx 48 * luaL_loadbufferx
50 * luaL_loadfilex 49 * luaL_loadfilex
51 */ 50 */
@@ -150,6 +149,9 @@ COMPAT53_API void luaL_traceback (lua_State *L, lua_State *L1, const char *msg,
150 149
151#define luaL_fileresult COMPAT53_CONCAT(COMPAT53_PREFIX, L_fileresult) 150#define luaL_fileresult COMPAT53_CONCAT(COMPAT53_PREFIX, L_fileresult)
152COMPAT53_API int luaL_fileresult (lua_State *L, int stat, const char *fname); 151COMPAT53_API int luaL_fileresult (lua_State *L, int stat, const char *fname);
152
153#define luaL_execresult COMPAT53_CONCAT(COMPAT53_PREFIX, L_execresult)
154COMPAT53_API int luaL_execresult (lua_State *L, int stat);
153#endif /* COMPAT53_IS_LUAJIT */ 155#endif /* COMPAT53_IS_LUAJIT */
154 156
155#define lua_callk(L, na, nr, ctx, cont) \ 157#define lua_callk(L, na, nr, ctx, cont) \