aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lauxlib.c12
-rw-r--r--lauxlib.h4
-rw-r--r--lbaselib.c8
3 files changed, 19 insertions, 5 deletions
diff --git a/lauxlib.c b/lauxlib.c
index b6903013..831d3e34 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -21,6 +21,18 @@
21#include "lualib.h" 21#include "lualib.h"
22 22
23 23
24LUALIB_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
25LUALIB_API int luaL_findstring (const char *name, const char *const list[]) { 37LUALIB_API int luaL_findstring (const char *name, const char *const list[]) {
26 int i; 38 int i;
diff --git a/lauxlib.h b/lauxlib.h
index 92f8b5d6..57d259c0 100644
--- a/lauxlib.h
+++ b/lauxlib.h
@@ -20,6 +20,7 @@
20#endif 20#endif
21 21
22 22
23
23typedef struct luaL_reg { 24typedef 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,
48LUALIB_API int luaL_ref (lua_State *L, int t); 49LUALIB_API int luaL_ref (lua_State *L, int t);
49LUALIB_API void luaL_unref (lua_State *L, int t, int ref); 50LUALIB_API void luaL_unref (lua_State *L, int t, int ref);
50 51
52/* error messages corresponding to error codes */
53LUALIB_API const char *luaL_errstr (int errcode);
54
51 55
52/* 56/*
53** =============================================================== 57** ===============================================================
diff --git a/lbaselib.c b/lbaselib.c
index 1b1d4d96..74d176dd 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -213,9 +213,6 @@ static int luaB_next (lua_State *L) {
213 213
214 214
215static int passresults (lua_State *L, int status, int oldtop) { 215static 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
416static int luaB_resume (lua_State *L) { 413static 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