lua

A copy of the Lua development repository
Log | Files | Refs | README

commit 4450efc97e8ca236cdb076733e8078d6c1ba0f36
parent de65253f2d927603b6becf87b4d177aa96a54fc2
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date:   Mon, 20 Dec 1999 11:09:23 -0200

new chunkid for C functions (`luaL_chunkid')

Diffstat:
Mlauxlib.c | 27+++++++++++++++++----------
1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/lauxlib.c b/lauxlib.c @@ -1,5 +1,5 @@ /* -** $Id: lauxlib.c,v 1.20 1999/10/05 18:33:43 roberto Exp roberto $ +** $Id: lauxlib.c,v 1.21 1999/11/22 13:12:07 roberto Exp roberto $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ @@ -113,17 +113,24 @@ void luaL_verror (lua_State *L, const char *fmt, ...) { } +#define EXTRALEN 13 /* > strlen('string "..."\0') */ + void luaL_chunkid (char *out, const 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)"); + if (*source == '(') { + strncpy(out, source+1, len-1); /* remove first char */ + out[len-1] = '\0'; /* make sure `out' has an end */ + out[strlen(out)-1] = '\0'; /* remove last char */ + } else { - const 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") */ + len -= EXTRALEN; + if (*source == '@') + sprintf(out, "file `%.*s'", len, source+1); + else { + const char *b = strchr(source , '\n'); /* stop at first new line */ + int lim = (b && (b-source)<len) ? b-source : len; + sprintf(out, "string \"%.*s\"", lim, source); + strcpy(out+lim+(EXTRALEN-5), "...\""); /* 5 = strlen("...'\0") */ + } } }