diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-01-11 15:03:01 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-01-11 15:03:01 -0300 |
commit | cc1692515e2a6aabc6d07159e7926656e38eda53 (patch) | |
tree | bc89a17cdc55a52897cc0d5a862cbc34314ada93 /lauxlib.c | |
parent | ce101dcaf73ff6d610593230d41b63c163a91519 (diff) | |
download | lua-cc1692515e2a6aabc6d07159e7926656e38eda53.tar.gz lua-cc1692515e2a6aabc6d07159e7926656e38eda53.tar.bz2 lua-cc1692515e2a6aabc6d07159e7926656e38eda53.zip |
New API function 'lua_closeslot'
Closing a to-be-closed variable with 'lua_settop' is too restrictive,
as it erases all slots above the variable. Moreover, it adds side
effects to 'lua_settop', which should be a fairly basic function.
Diffstat (limited to 'lauxlib.c')
-rw-r--r-- | lauxlib.c | 8 |
1 files changed, 3 insertions, 5 deletions
@@ -545,10 +545,8 @@ static char *prepbuffsize (luaL_Buffer *B, size_t sz, int boxidx) { | |||
545 | if (buffonstack(B)) /* buffer already has a box? */ | 545 | if (buffonstack(B)) /* buffer already has a box? */ |
546 | newbuff = (char *)resizebox(L, boxidx, newsize); /* resize it */ | 546 | newbuff = (char *)resizebox(L, boxidx, newsize); /* resize it */ |
547 | else { /* no box yet */ | 547 | else { /* no box yet */ |
548 | lua_pushnil(L); /* reserve slot for final result */ | ||
549 | newbox(L); /* create a new box */ | 548 | newbox(L); /* create a new box */ |
550 | /* move box (and slot) to its intended position */ | 549 | lua_insert(L, boxidx); /* move box to its intended position */ |
551 | lua_rotate(L, boxidx - 1, 2); | ||
552 | lua_toclose(L, boxidx); | 550 | lua_toclose(L, boxidx); |
553 | newbuff = (char *)resizebox(L, boxidx, newsize); | 551 | newbuff = (char *)resizebox(L, boxidx, newsize); |
554 | memcpy(newbuff, B->b, B->n * sizeof(char)); /* copy original content */ | 552 | memcpy(newbuff, B->b, B->n * sizeof(char)); /* copy original content */ |
@@ -585,8 +583,8 @@ LUALIB_API void luaL_pushresult (luaL_Buffer *B) { | |||
585 | lua_State *L = B->L; | 583 | lua_State *L = B->L; |
586 | lua_pushlstring(L, B->b, B->n); | 584 | lua_pushlstring(L, B->b, B->n); |
587 | if (buffonstack(B)) { | 585 | if (buffonstack(B)) { |
588 | lua_copy(L, -1, -3); /* move string to reserved slot */ | 586 | lua_closeslot(L, -2); /* close the box */ |
589 | lua_pop(L, 2); /* pop string and box (closing the box) */ | 587 | lua_remove(L, -2); /* remove box from the stack */ |
590 | } | 588 | } |
591 | } | 589 | } |
592 | 590 | ||