diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-08-08 17:08:41 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-08-08 17:08:41 -0300 |
commit | 9998082839bfffe01d7b614ab61ad35629a2c356 (patch) | |
tree | 3722acbcdda6fff4bdccc059c443618a59978726 /lauxlib.c | |
parent | 08da48a73ce9ec8d0672c45f67ff32650e937477 (diff) | |
download | lua-9998082839bfffe01d7b614ab61ad35629a2c356.tar.gz lua-9998082839bfffe01d7b614ab61ad35629a2c356.tar.bz2 lua-9998082839bfffe01d7b614ab61ad35629a2c356.zip |
external messages add their own extra information
Diffstat (limited to 'lauxlib.c')
-rw-r--r-- | lauxlib.c | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.81 2002/08/06 17:26:45 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.82 2002/08/06 18:01:50 roberto Exp roberto $ |
3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -62,11 +62,27 @@ static void tag_error (lua_State *L, int narg, int tag) { | |||
62 | } | 62 | } |
63 | 63 | ||
64 | 64 | ||
65 | LUALIB_API void luaL_where (lua_State *L, int level) { | ||
66 | lua_Debug ar; | ||
67 | if (lua_getstack(L, level, &ar)) { /* check function at level */ | ||
68 | lua_getinfo(L, "Snl", &ar); /* get info about it */ | ||
69 | if (ar.currentline > 0) { /* is there info? */ | ||
70 | lua_pushfstring(L, "%s:%d: ", ar.short_src, ar.currentline); | ||
71 | return; | ||
72 | } | ||
73 | } | ||
74 | lua_pushliteral(L, ""); /* else, no information available... */ | ||
75 | } | ||
76 | |||
77 | |||
65 | LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) { | 78 | LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) { |
66 | va_list argp; | 79 | va_list argp; |
67 | va_start(argp, fmt); | 80 | va_start(argp, fmt); |
81 | luaL_where(L, 1); | ||
68 | lua_pushvfstring(L, fmt, argp); | 82 | lua_pushvfstring(L, fmt, argp); |
69 | va_end(argp); | 83 | va_end(argp); |
84 | lua_pushliteral(L, "\n"); | ||
85 | lua_concat(L, 3); | ||
70 | return lua_error(L); | 86 | return lua_error(L); |
71 | } | 87 | } |
72 | 88 | ||