| 3033 | } |
| 3034 | |
| 3035 | COMPAT53_API char *luaL_prepbuffsize(luaL_Buffer_53 *B, size_t s) { |
| 3036 | if (B->capacity - B->nelems < s) { /* needs to grow */ |
| 3037 | char* newptr = NULL; |
| 3038 | size_t newcap = B->capacity * 2; |
| 3039 | if (newcap - B->nelems < s) |
| 3040 | newcap = B->nelems + s; |
| 3041 | if (newcap < B->capacity) /* overflow */ |
| 3042 | luaL_error(B->L2, "buffer too large"); |
| 3043 | newptr = (char*)lua_newuserdata(B->L2, newcap); |
| 3044 | memcpy(newptr, B->ptr, B->nelems); |
| 3045 | if (B->ptr != B->b.buffer) |
| 3046 | lua_replace(B->L2, -2); /* remove old buffer */ |
| 3047 | B->ptr = newptr; |
| 3048 | B->capacity = newcap; |
| 3049 | } |
| 3050 | return B->ptr + B->nelems; |
| 3051 | } |
| 3052 | |
| 3053 | COMPAT53_API void luaL_addlstring(luaL_Buffer_53 *B, const char *s, size_t l) { |
| 3054 | memcpy(luaL_prepbuffsize(B, l), s, l); |
no test coverage detected