diff options
author | Lua Team <team@lua.org> | 2014-10-23 12:00:00 +0000 |
---|---|---|
committer | repogen <> | 2014-10-23 12:00:00 +0000 |
commit | 92fdb95364ed274752b8634c8ba3dca1f1dc5fb3 (patch) | |
tree | d1747f7ed2d0ed06b83ee3073fe4256aefd4a928 /src/lua.c | |
parent | d7648e85b78d53a2248de909868192598ad0eb69 (diff) | |
download | lua-github-5.3.0-beta.tar.gz |
Lua 5.3.0-beta5.3.0-beta
Diffstat (limited to 'src/lua.c')
-rw-r--r-- | src/lua.c | 43 |
1 files changed, 21 insertions, 22 deletions
@@ -1,5 +1,5 @@ /* -** $Id: lua.c,v 1.213 2014/06/30 19:48:08 roberto Exp $ +** $Id: lua.c,v 1.217 2014/10/20 22:21:05 roberto Exp $ ** Lua stand-alone interpreter ** See Copyright Notice in lua.h */ @@ -134,9 +134,9 @@ static void print_usage (const char *badoption) { luai_writestringerror( "usage: %s [options] [script [args]]\n" "Available options are:\n" - " -e stat execute string " LUA_QL("stat") "\n" - " -i enter interactive mode after executing " LUA_QL("script") "\n" - " -l name require library " LUA_QL("name") "\n" + " -e stat execute string 'stat'\n" + " -i enter interactive mode after executing 'script'\n" + " -l name require library 'name'\n" " -v show version information\n" " -E ignore environment variables\n" " -- stop handling options\n" @@ -158,34 +158,34 @@ static void l_message (const char *pname, const char *msg) { /* ** Check whether 'status' is not OK and, if so, prints the error -** message on the top of the stack. Because this function can be called -** unprotected, it only accepts actual strings as error messages. (A -** coercion could raise a memory error.) +** message on the top of the stack. It assumes that the error object +** is a string, as it was either generated by Lua or by 'msghandler'. */ static int report (lua_State *L, int status) { if (status != LUA_OK) { - const char *msg = (lua_type(L, -1) == LUA_TSTRING) ? lua_tostring(L, -1) - : NULL; - if (msg == NULL) msg = "(error object is not a string)"; + const char *msg = lua_tostring(L, -1); l_message(progname, msg); - lua_pop(L, 1); + lua_pop(L, 1); /* remove message */ } return status; } /* -** Message handler to be used to run all chunks +** Message handler used to run all chunks */ static int msghandler (lua_State *L) { const char *msg = lua_tostring(L, 1); - if (msg) /* is error object a string? */ - luaL_traceback(L, L, msg, 1); /* use standard traceback */ - else if (!lua_isnoneornil(L, 1)) { /* non-string error object? */ - if (!luaL_callmeta(L, 1, "__tostring")) /* try its 'tostring' metamethod */ - lua_pushliteral(L, "(no error message)"); - } /* else no error object, does nothing */ - return 1; + if (msg == NULL) { /* is error object not a string? */ + if (luaL_callmeta(L, 1, "__tostring") && /* does it have a metamethod */ + lua_type(L, -1) == LUA_TSTRING) /* that produces a string? */ + return 1; /* that is the message */ + else + msg = lua_pushfstring(L, "(error object is a %s value)", + luaL_typename(L, 1)); + } + luaL_traceback(L, L, msg, 1); /* append a standard traceback */ + return 1; /* return the traceback */ } @@ -389,9 +389,8 @@ static void l_print (lua_State *L) { lua_getglobal(L, "print"); lua_insert(L, 1); if (lua_pcall(L, n, 0, 0) != LUA_OK) - l_message(progname, lua_pushfstring(L, - "error calling " LUA_QL("print") " (%s)", - lua_tostring(L, -1))); + l_message(progname, lua_pushfstring(L, "error calling 'print' (%s)", + lua_tostring(L, -1))); } } |