diff options
Diffstat (limited to 'lobject.c')
-rw-r--r-- | lobject.c | 34 |
1 files changed, 22 insertions, 12 deletions
@@ -386,29 +386,39 @@ void luaO_tostring (lua_State *L, TValue *obj) { | |||
386 | ** =================================================================== | 386 | ** =================================================================== |
387 | */ | 387 | */ |
388 | 388 | ||
389 | /* size for buffer space used by 'luaO_pushvfstring' */ | 389 | /* |
390 | #define BUFVFS 200 | 390 | ** Size for buffer space used by 'luaO_pushvfstring'. It should be |
391 | ** (LUA_IDSIZE + MAXNUMBER2STR) + a minimal space for basic messages, | ||
392 | ** so that 'luaG_addinfo' can work directly on the buffer. | ||
393 | */ | ||
394 | #define BUFVFS (LUA_IDSIZE + MAXNUMBER2STR + 95) | ||
391 | 395 | ||
392 | /* buffer used by 'luaO_pushvfstring' */ | 396 | /* buffer used by 'luaO_pushvfstring' */ |
393 | typedef struct BuffFS { | 397 | typedef struct BuffFS { |
394 | lua_State *L; | 398 | lua_State *L; |
395 | int pushed; /* number of string pieces already on the stack */ | 399 | int pushed; /* true if there is a part of the result on the stack */ |
396 | int blen; /* length of partial string in 'space' */ | 400 | int blen; /* length of partial string in 'space' */ |
397 | char space[BUFVFS]; /* holds last part of the result */ | 401 | char space[BUFVFS]; /* holds last part of the result */ |
398 | } BuffFS; | 402 | } BuffFS; |
399 | 403 | ||
400 | 404 | ||
401 | /* | 405 | /* |
402 | ** Push given string to the stack, as part of the buffer, and | 406 | ** Push given string to the stack, as part of the result, and |
403 | ** join the partial strings in the stack into one. | 407 | ** join it to previous partial result if there is one. |
408 | ** It may call 'luaV_concat' while using one slot from EXTRA_STACK. | ||
409 | ** This call cannot invoke metamethods, as both operands must be | ||
410 | ** strings. It can, however, raise an error if the result is too | ||
411 | ** long. In that case, 'luaV_concat' frees the extra slot before | ||
412 | ** raising the error. | ||
404 | */ | 413 | */ |
405 | static void pushstr (BuffFS *buff, const char *str, size_t l) { | 414 | static void pushstr (BuffFS *buff, const char *str, size_t lstr) { |
406 | lua_State *L = buff->L; | 415 | lua_State *L = buff->L; |
407 | setsvalue2s(L, L->top, luaS_newlstr(L, str, l)); | 416 | setsvalue2s(L, L->top, luaS_newlstr(L, str, lstr)); |
408 | L->top++; /* may use one extra slot */ | 417 | L->top++; /* may use one slot from EXTRA_STACK */ |
409 | buff->pushed++; | 418 | if (!buff->pushed) /* no previous string on the stack? */ |
410 | luaV_concat(L, buff->pushed); /* join partial results into one */ | 419 | buff->pushed = 1; /* now there is one */ |
411 | buff->pushed = 1; | 420 | else /* join previous string with new one */ |
421 | luaV_concat(L, 2); | ||
412 | } | 422 | } |
413 | 423 | ||
414 | 424 | ||
@@ -454,7 +464,7 @@ static void addstr2buff (BuffFS *buff, const char *str, size_t slen) { | |||
454 | 464 | ||
455 | 465 | ||
456 | /* | 466 | /* |
457 | ** Add a number to the buffer. | 467 | ** Add a numeral to the buffer. |
458 | */ | 468 | */ |
459 | static void addnum2buff (BuffFS *buff, TValue *num) { | 469 | static void addnum2buff (BuffFS *buff, TValue *num) { |
460 | char *numbuff = getbuff(buff, MAXNUMBER2STR); | 470 | char *numbuff = getbuff(buff, MAXNUMBER2STR); |