diff options
Diffstat (limited to 'src/lauxlib.c')
-rw-r--r-- | src/lauxlib.c | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/src/lauxlib.c b/src/lauxlib.c index 0a972af0..db929c4f 100644 --- a/src/lauxlib.c +++ b/src/lauxlib.c @@ -1,5 +1,5 @@ /* -** $Id: lauxlib.c,v 1.12 1998/06/19 16:14:09 roberto Exp $ +** $Id: lauxlib.c,v 1.17 1999/03/11 18:59:19 roberto Exp $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ @@ -10,9 +10,10 @@ #include <string.h> /* Please Notice: This file uses only the official API of Lua -** Any function declared here could be written as an application -** function. With care, these functions can be used by other libraries. +** Any function declared here could be written as an application function. +** With care, these functions can be used by other libraries. */ + #include "lauxlib.h" #include "lua.h" #include "luadebug.h" @@ -27,12 +28,13 @@ int luaL_findstring (char *name, char *list[]) { return -1; /* name not found */ } -void luaL_argerror (int numarg, char *extramsg) -{ +void luaL_argerror (int numarg, char *extramsg) { + lua_Function f = lua_stackedfunction(0); char *funcname; - lua_getobjname(lua_stackedfunction(0), &funcname); + lua_getobjname(f, &funcname); + numarg -= lua_nups(f); if (funcname == NULL) - funcname = "???"; + funcname = "?"; if (extramsg == NULL) luaL_verror("bad argument #%d to function `%.50s'", numarg, funcname); else @@ -109,3 +111,23 @@ void luaL_verror (char *fmt, ...) lua_error(buff); } + +void luaL_chunkid (char *out, char *source, int len) { + len -= 13; /* 13 = strlen("string ''...\0") */ + if (*source == '@') + sprintf(out, "file `%.*s'", len, source+1); + else if (*source == '(') + strcpy(out, "(C code)"); + else { + char *b = strchr(source , '\n'); /* stop string at first new line */ + int lim = (b && (b-source)<len) ? b-source : len; + sprintf(out, "string `%.*s'", lim, source); + strcpy(out+lim+(13-5), "...'"); /* 5 = strlen("...'\0") */ + } +} + + +void luaL_filesource (char *out, char *filename, int len) { + if (filename == NULL) filename = "(stdin)"; + sprintf(out, "@%.*s", len-2, filename); /* -2 for '@' and '\0' */ +} |