diff options
Diffstat (limited to 'lobject.c')
| -rw-r--r-- | lobject.c | 30 |
1 files changed, 10 insertions, 20 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.c,v 1.78 2002/05/06 15:51:41 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 1.79 2002/05/07 17:36:56 roberto Exp roberto $ |
| 3 | ** Some generic functions over Lua objects | 3 | ** Some generic functions over Lua objects |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -100,7 +100,8 @@ static void pushstr (lua_State *L, const char *str) { | |||
| 100 | 100 | ||
| 101 | /* this function handles only `%d', `%c', %f, and `%s' formats */ | 101 | /* this function handles only `%d', `%c', %f, and `%s' formats */ |
| 102 | const char *luaO_vpushstr (lua_State *L, const char *fmt, va_list argp) { | 102 | const char *luaO_vpushstr (lua_State *L, const char *fmt, va_list argp) { |
| 103 | int n = 0; | 103 | int n = 1; |
| 104 | pushstr(L, ""); | ||
| 104 | for (;;) { | 105 | for (;;) { |
| 105 | const char *e = strchr(fmt, '%'); | 106 | const char *e = strchr(fmt, '%'); |
| 106 | if (e == NULL) break; | 107 | if (e == NULL) break; |
| @@ -150,47 +151,36 @@ const char *luaO_pushstr (lua_State *L, const char *fmt, ...) { | |||
| 150 | } | 151 | } |
| 151 | 152 | ||
| 152 | 153 | ||
| 153 | void luaO_verror (lua_State *L, const char *fmt, ...) { | ||
| 154 | const char *msg; | ||
| 155 | va_list argp; | ||
| 156 | va_start(argp, fmt); | ||
| 157 | msg = luaO_vpushstr(L, fmt, argp); | ||
| 158 | va_end(argp); | ||
| 159 | luaD_runerror(L, msg); | ||
| 160 | } | ||
| 161 | |||
| 162 | |||
| 163 | void luaO_chunkid (char *out, const char *source, int bufflen) { | 154 | void luaO_chunkid (char *out, const char *source, int bufflen) { |
| 164 | if (*source == '=') { | 155 | if (*source == '=') { |
| 165 | strncpy(out, source+1, bufflen); /* remove first char */ | 156 | strncpy(out, source+1, bufflen); /* remove first char */ |
| 166 | out[bufflen-1] = '\0'; /* ensures null termination */ | 157 | out[bufflen-1] = '\0'; /* ensures null termination */ |
| 167 | } | 158 | } |
| 168 | else { /* out = "file `source'", or "file `...source'" */ | 159 | else { /* out = "source", or "...source" */ |
| 169 | if (*source == '@') { | 160 | if (*source == '@') { |
| 170 | int l; | 161 | int l; |
| 171 | source++; /* skip the `@' */ | 162 | source++; /* skip the `@' */ |
| 172 | bufflen -= sizeof(" file `...' "); | 163 | bufflen -= sizeof(" `...' "); |
| 173 | l = strlen(source); | 164 | l = strlen(source); |
| 174 | strcpy(out, "file `"); | 165 | strcpy(out, ""); |
| 175 | if (l>bufflen) { | 166 | if (l>bufflen) { |
| 176 | source += (l-bufflen); /* get last part of file name */ | 167 | source += (l-bufflen); /* get last part of file name */ |
| 177 | strcat(out, "..."); | 168 | strcat(out, "..."); |
| 178 | } | 169 | } |
| 179 | strcat(out, source); | 170 | strcat(out, source); |
| 180 | strcat(out, "'"); | ||
| 181 | } | 171 | } |
| 182 | else { | 172 | else { /* out = [string "string"] */ |
| 183 | int len = strcspn(source, "\n"); /* stop at first newline */ | 173 | int len = strcspn(source, "\n"); /* stop at first newline */ |
| 184 | bufflen -= sizeof(" string \"...\" "); | 174 | bufflen -= sizeof(" [string \"...\"] "); |
| 185 | if (len > bufflen) len = bufflen; | 175 | if (len > bufflen) len = bufflen; |
| 186 | strcpy(out, "string \""); | 176 | strcpy(out, "[string \""); |
| 187 | if (source[len] != '\0') { /* must truncate? */ | 177 | if (source[len] != '\0') { /* must truncate? */ |
| 188 | strncat(out, source, len); | 178 | strncat(out, source, len); |
| 189 | strcat(out, "..."); | 179 | strcat(out, "..."); |
| 190 | } | 180 | } |
| 191 | else | 181 | else |
| 192 | strcat(out, source); | 182 | strcat(out, source); |
| 193 | strcat(out, "\""); | 183 | strcat(out, "\"]"); |
| 194 | } | 184 | } |
| 195 | } | 185 | } |
| 196 | } | 186 | } |
