From 4450efc97e8ca236cdb076733e8078d6c1ba0f36 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 20 Dec 1999 11:09:45 -0200 Subject: new chunkid for C functions (`luaL_chunkid') --- lauxlib.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/lauxlib.c b/lauxlib.c index d713cd2e..5a333d3e 100644 --- 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)