** 'luaL_addvalue' is the only function in the Buffer system where the ** box (if existent) is not on the top of the stack. So, instead of ** calling 'luaL_addlstring', it replicates the code using -2 as the ** last argument to 'prepbuffsize', signaling that the box is (or will ** be) below the string being added to the buffer. (Box creation can ** trigger an emergency GC, so we should not remove
| 648 | ** stack before we have the space guaranteed.) |
| 649 | */ |
| 650 | LUALIB_API void luaL_addvalue (luaL_Buffer *B) { |
| 651 | lua_State *L = B->L; |
| 652 | size_t len; |
| 653 | const char *s = lua_tolstring(L, -1, &len); |
| 654 | char *b = prepbuffsize(B, len, -2); |
| 655 | memcpy(b, s, len * sizeof(char)); |
| 656 | luaL_addsize(B, len); |
| 657 | lua_pop(L, 1); /* pop string */ |
| 658 | } |
| 659 | |
| 660 | |
| 661 | LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B) { |
no test coverage detected