| 609 | |
| 610 | |
| 611 | LUALIB_API void luaL_pushresult (luaL_Buffer *B) { |
| 612 | lua_State *L = B->L; |
| 613 | checkbufferlevel(B, -1); |
| 614 | if (!buffonstack(B)) /* using static buffer? */ |
| 615 | lua_pushlstring(L, B->b, B->n); /* save result as regular string */ |
| 616 | else { /* reuse buffer already allocated */ |
| 617 | UBox *box = (UBox *)lua_touserdata(L, -1); |
| 618 | void *ud; |
| 619 | lua_Alloc allocf = lua_getallocf(L, &ud); /* function to free buffer */ |
| 620 | size_t len = B->n; /* final string length */ |
| 621 | char *s; |
| 622 | resizebox(L, -1, len + 1); /* adjust box size to content size */ |
| 623 | s = (char*)box->box; /* final buffer address */ |
| 624 | s[len] = '\0'; /* add ending zero */ |
| 625 | /* clear box, as Lua will take control of the buffer */ |
| 626 | box->bsize = 0; box->box = NULL; |
| 627 | lua_pushexternalstring(L, s, len, allocf, ud); |
| 628 | lua_closeslot(L, -2); /* close the box */ |
| 629 | lua_gc(L, LUA_GCSTEP, len); |
| 630 | } |
| 631 | lua_remove(L, -2); /* remove box or placeholder from the stack */ |
| 632 | } |
| 633 | |
| 634 | |
| 635 | LUALIB_API void luaL_pushresultsize (luaL_Buffer *B, size_t sz) { |
no test coverage detected