aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-12-20 11:09:45 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-12-20 11:09:45 -0200
commit4450efc97e8ca236cdb076733e8078d6c1ba0f36 (patch)
tree4be76e6e7f74c8da3d6b0f508cc1807916460810
parentde65253f2d927603b6becf87b4d177aa96a54fc2 (diff)
downloadlua-4450efc97e8ca236cdb076733e8078d6c1ba0f36.tar.gz
lua-4450efc97e8ca236cdb076733e8078d6c1ba0f36.tar.bz2
lua-4450efc97e8ca236cdb076733e8078d6c1ba0f36.zip
new chunkid for C functions (`luaL_chunkid')
-rw-r--r--lauxlib.c27
1 files 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 @@
1/* 1/*
2** $Id: lauxlib.c,v 1.20 1999/10/05 18:33:43 roberto Exp roberto $ 2** $Id: lauxlib.c,v 1.21 1999/11/22 13:12:07 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*/
@@ -113,17 +113,24 @@ void luaL_verror (lua_State *L, const char *fmt, ...) {
113} 113}
114 114
115 115
116#define EXTRALEN 13 /* > strlen('string "..."\0') */
117
116void luaL_chunkid (char *out, const char *source, int len) { 118void luaL_chunkid (char *out, const char *source, int len) {
117 len -= 13; /* 13 = strlen("string ''...\0") */ 119 if (*source == '(') {
118 if (*source == '@') 120 strncpy(out, source+1, len-1); /* remove first char */
119 sprintf(out, "file `%.*s'", len, source+1); 121 out[len-1] = '\0'; /* make sure `out' has an end */
120 else if (*source == '(') 122 out[strlen(out)-1] = '\0'; /* remove last char */
121 strcpy(out, "(C code)"); 123 }
122 else { 124 else {
123 const char *b = strchr(source , '\n'); /* stop string at first new line */ 125 len -= EXTRALEN;
124 int lim = (b && (b-source)<len) ? b-source : len; 126 if (*source == '@')
125 sprintf(out, "string `%.*s'", lim, source); 127 sprintf(out, "file `%.*s'", len, source+1);
126 strcpy(out+lim+(13-5), "...'"); /* 5 = strlen("...'\0") */ 128 else {
129 const char *b = strchr(source , '\n'); /* stop at first new line */
130 int lim = (b && (b-source)<len) ? b-source : len;
131 sprintf(out, "string \"%.*s\"", lim, source);
132 strcpy(out+lim+(EXTRALEN-5), "...\""); /* 5 = strlen("...'\0") */
133 }
127 } 134 }
128} 135}
129 136