diff options
Diffstat (limited to '')
| -rw-r--r-- | lauxlib.c | 27 |
1 files changed, 17 insertions, 10 deletions
| @@ -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 | |||
| 116 | void luaL_chunkid (char *out, const char *source, int len) { | 118 | void 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 | ||
