diff options
-rw-r--r-- | lauxlib.c | 12 | ||||
-rw-r--r-- | lauxlib.h | 4 | ||||
-rw-r--r-- | lbaselib.c | 8 |
3 files changed, 19 insertions, 5 deletions
@@ -21,6 +21,18 @@ | |||
21 | #include "lualib.h" | 21 | #include "lualib.h" |
22 | 22 | ||
23 | 23 | ||
24 | LUALIB_API const char *luaL_errstr (int errcode) { | ||
25 | static const char *const errstr[] = { | ||
26 | "ok", | ||
27 | "run-time error", | ||
28 | "cannot open file", | ||
29 | "syntax error", | ||
30 | "memory allocation error", | ||
31 | "error in error handling" | ||
32 | }; | ||
33 | return errstr[errcode]; | ||
34 | } | ||
35 | |||
24 | 36 | ||
25 | LUALIB_API int luaL_findstring (const char *name, const char *const list[]) { | 37 | LUALIB_API int luaL_findstring (const char *name, const char *const list[]) { |
26 | int i; | 38 | int i; |
@@ -20,6 +20,7 @@ | |||
20 | #endif | 20 | #endif |
21 | 21 | ||
22 | 22 | ||
23 | |||
23 | typedef struct luaL_reg { | 24 | typedef struct luaL_reg { |
24 | const char *name; | 25 | const char *name; |
25 | lua_CFunction func; | 26 | lua_CFunction func; |
@@ -48,6 +49,9 @@ LUALIB_API int luaL_findstring (const char *name, | |||
48 | LUALIB_API int luaL_ref (lua_State *L, int t); | 49 | LUALIB_API int luaL_ref (lua_State *L, int t); |
49 | LUALIB_API void luaL_unref (lua_State *L, int t, int ref); | 50 | LUALIB_API void luaL_unref (lua_State *L, int t, int ref); |
50 | 51 | ||
52 | /* error messages corresponding to error codes */ | ||
53 | LUALIB_API const char *luaL_errstr (int errcode); | ||
54 | |||
51 | 55 | ||
52 | /* | 56 | /* |
53 | ** =============================================================== | 57 | ** =============================================================== |
@@ -213,9 +213,6 @@ static int luaB_next (lua_State *L) { | |||
213 | 213 | ||
214 | 214 | ||
215 | static int passresults (lua_State *L, int status, int oldtop) { | 215 | static int passresults (lua_State *L, int status, int oldtop) { |
216 | static const char *const errornames[] = | ||
217 | {"ok", "run-time error", "file error", "syntax error", | ||
218 | "memory error", "error in error handling"}; | ||
219 | if (status == 0) { | 216 | if (status == 0) { |
220 | int nresults = lua_gettop(L) - oldtop; | 217 | int nresults = lua_gettop(L) - oldtop; |
221 | if (nresults > 0) | 218 | if (nresults > 0) |
@@ -227,7 +224,7 @@ static int passresults (lua_State *L, int status, int oldtop) { | |||
227 | } | 224 | } |
228 | else { /* error */ | 225 | else { /* error */ |
229 | lua_pushnil(L); | 226 | lua_pushnil(L); |
230 | lua_pushstring(L, errornames[status]); /* error code */ | 227 | lua_pushstring(L, luaL_errstr(status)); /* error code */ |
231 | return 2; | 228 | return 2; |
232 | } | 229 | } |
233 | } | 230 | } |
@@ -415,7 +412,8 @@ static int luaB_tostring (lua_State *L) { | |||
415 | 412 | ||
416 | static int luaB_resume (lua_State *L) { | 413 | static int luaB_resume (lua_State *L) { |
417 | lua_State *co = (lua_State *)lua_touserdata(L, lua_upvalueindex(1)); | 414 | lua_State *co = (lua_State *)lua_touserdata(L, lua_upvalueindex(1)); |
418 | lua_resume(L, co); | 415 | if (lua_resume(L, co) != 0) |
416 | lua_error(L, "error running co-routine"); | ||
419 | return lua_gettop(L); | 417 | return lua_gettop(L); |
420 | } | 418 | } |
421 | 419 | ||