aboutsummaryrefslogtreecommitdiff
path: root/src/lib_aux.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib_aux.c')
-rw-r--r--src/lib_aux.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/lib_aux.c b/src/lib_aux.c
index 8fbee71b..4419fde9 100644
--- a/src/lib_aux.c
+++ b/src/lib_aux.c
@@ -19,8 +19,63 @@
19#include "lj_obj.h" 19#include "lj_obj.h"
20#include "lj_err.h" 20#include "lj_err.h"
21#include "lj_state.h" 21#include "lj_state.h"
22#include "lj_trace.h"
22#include "lj_lib.h" 23#include "lj_lib.h"
23 24
25#if LJ_TARGET_POSIX
26#include <sys/wait.h>
27#endif
28
29/* -- I/O error handling -------------------------------------------------- */
30
31LUALIB_API int luaL_fileresult(lua_State *L, int stat, const char *fname)
32{
33 if (stat) {
34 setboolV(L->top++, 1);
35 return 1;
36 } else {
37 int en = errno; /* Lua API calls may change this value. */
38 setnilV(L->top++);
39 if (fname)
40 lua_pushfstring(L, "%s: %s", fname, strerror(en));
41 else
42 lua_pushfstring(L, "%s", strerror(en));
43 setintV(L->top++, en);
44 lj_trace_abort(G(L));
45 return 3;
46 }
47}
48
49LUALIB_API int luaL_execresult(lua_State *L, int stat)
50{
51 if (stat != -1) {
52#if LJ_TARGET_POSIX
53 if (WIFSIGNALED(stat)) {
54 stat = WTERMSIG(stat);
55 setnilV(L->top++);
56 lua_pushliteral(L, "signal");
57 } else {
58 if (WIFEXITED(stat))
59 stat = WEXITSTATUS(stat);
60 if (stat == 0)
61 setboolV(L->top++, 1);
62 else
63 setnilV(L->top++);
64 lua_pushliteral(L, "exit");
65 }
66#else
67 if (stat == 0)
68 setboolV(L->top++, 1);
69 else
70 setnilV(L->top++);
71 lua_pushliteral(L, "exit");
72#endif
73 setintV(L->top++, stat);
74 return 3;
75 }
76 return luaL_fileresult(L, 0, NULL);
77}
78
24/* -- Module registration ------------------------------------------------- */ 79/* -- Module registration ------------------------------------------------- */
25 80
26LUALIB_API const char *luaL_findtable(lua_State *L, int idx, 81LUALIB_API const char *luaL_findtable(lua_State *L, int idx,