new function luaL_errstr
This commit is contained in:
12
lauxlib.c
12
lauxlib.c
@@ -21,6 +21,18 @@
|
|||||||
#include "lualib.h"
|
#include "lualib.h"
|
||||||
|
|
||||||
|
|
||||||
|
LUALIB_API const char *luaL_errstr (int errcode) {
|
||||||
|
static const char *const errstr[] = {
|
||||||
|
"ok",
|
||||||
|
"run-time error",
|
||||||
|
"cannot open file",
|
||||||
|
"syntax error",
|
||||||
|
"memory allocation error",
|
||||||
|
"error in error handling"
|
||||||
|
};
|
||||||
|
return errstr[errcode];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
LUALIB_API int luaL_findstring (const char *name, const char *const list[]) {
|
LUALIB_API int luaL_findstring (const char *name, const char *const list[]) {
|
||||||
int i;
|
int i;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct luaL_reg {
|
typedef struct luaL_reg {
|
||||||
const char *name;
|
const char *name;
|
||||||
lua_CFunction func;
|
lua_CFunction func;
|
||||||
@@ -48,6 +49,9 @@ LUALIB_API int luaL_findstring (const char *name,
|
|||||||
LUALIB_API int luaL_ref (lua_State *L, int t);
|
LUALIB_API int luaL_ref (lua_State *L, int t);
|
||||||
LUALIB_API void luaL_unref (lua_State *L, int t, int ref);
|
LUALIB_API void luaL_unref (lua_State *L, int t, int ref);
|
||||||
|
|
||||||
|
/* error messages corresponding to error codes */
|
||||||
|
LUALIB_API const char *luaL_errstr (int errcode);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** ===============================================================
|
** ===============================================================
|
||||||
|
|||||||
@@ -213,9 +213,6 @@ static int luaB_next (lua_State *L) {
|
|||||||
|
|
||||||
|
|
||||||
static int passresults (lua_State *L, int status, int oldtop) {
|
static int passresults (lua_State *L, int status, int oldtop) {
|
||||||
static const char *const errornames[] =
|
|
||||||
{"ok", "run-time error", "file error", "syntax error",
|
|
||||||
"memory error", "error in error handling"};
|
|
||||||
if (status == 0) {
|
if (status == 0) {
|
||||||
int nresults = lua_gettop(L) - oldtop;
|
int nresults = lua_gettop(L) - oldtop;
|
||||||
if (nresults > 0)
|
if (nresults > 0)
|
||||||
@@ -227,7 +224,7 @@ static int passresults (lua_State *L, int status, int oldtop) {
|
|||||||
}
|
}
|
||||||
else { /* error */
|
else { /* error */
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
lua_pushstring(L, errornames[status]); /* error code */
|
lua_pushstring(L, luaL_errstr(status)); /* error code */
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -415,7 +412,8 @@ static int luaB_tostring (lua_State *L) {
|
|||||||
|
|
||||||
static int luaB_resume (lua_State *L) {
|
static int luaB_resume (lua_State *L) {
|
||||||
lua_State *co = (lua_State *)lua_touserdata(L, lua_upvalueindex(1));
|
lua_State *co = (lua_State *)lua_touserdata(L, lua_upvalueindex(1));
|
||||||
lua_resume(L, co);
|
if (lua_resume(L, co) != 0)
|
||||||
|
lua_error(L, "error running co-routine");
|
||||||
return lua_gettop(L);
|
return lua_gettop(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user