From 9998082839bfffe01d7b614ab61ad35629a2c356 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 8 Aug 2002 17:08:41 -0300 Subject: external messages add their own extra information --- lauxlib.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'lauxlib.c') diff --git a/lauxlib.c b/lauxlib.c index c37135e2..4ad7e0a2 100644 --- a/lauxlib.c +++ b/lauxlib.c @@ -1,5 +1,5 @@ /* -** $Id: lauxlib.c,v 1.81 2002/08/06 17:26:45 roberto Exp roberto $ +** $Id: lauxlib.c,v 1.82 2002/08/06 18:01:50 roberto Exp roberto $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ @@ -62,11 +62,27 @@ static void tag_error (lua_State *L, int narg, int tag) { } +LUALIB_API void luaL_where (lua_State *L, int level) { + lua_Debug ar; + if (lua_getstack(L, level, &ar)) { /* check function at level */ + lua_getinfo(L, "Snl", &ar); /* get info about it */ + if (ar.currentline > 0) { /* is there info? */ + lua_pushfstring(L, "%s:%d: ", ar.short_src, ar.currentline); + return; + } + } + lua_pushliteral(L, ""); /* else, no information available... */ +} + + LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) { va_list argp; va_start(argp, fmt); + luaL_where(L, 1); lua_pushvfstring(L, fmt, argp); va_end(argp); + lua_pushliteral(L, "\n"); + lua_concat(L, 3); return lua_error(L); } -- cgit v1.2.3-55-g6feb