MCPcopy Create free account
hub / github.com/axmolengine/axmol / luaL_prepbuffsize

Function luaL_prepbuffsize

3rdparty/lua/sol/sol.hpp:4188–4208  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4186}
4187
4188COMPAT53_API char* luaL_prepbuffsize(luaL_Buffer_53* B, size_t s) {
4189 if (B->capacity - B->nelems < s) { /* needs to grow */
4190 char* newptr = NULL;
4191 size_t newcap = B->capacity * 2;
4192 if (newcap - B->nelems < s)
4193 newcap = B->nelems + s;
4194 if (newcap < B->capacity) /* overflow */
4195 luaL_error(B->L2, "buffer too large");
4196#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 504
4197 newptr = (char*)lua_newuserdatauv(B->L2, newcap, 0);
4198#else
4199 newptr = (char*)lua_newuserdata(B->L2, newcap);
4200#endif
4201 memcpy(newptr, B->ptr, B->nelems);
4202 if (B->ptr != B->b.buffer)
4203 lua_replace(B->L2, -2); /* remove old buffer */
4204 B->ptr = newptr;
4205 B->capacity = newcap;
4206 }
4207 return B->ptr + B->nelems;
4208}
4209
4210COMPAT53_API void luaL_addlstring(luaL_Buffer_53* B, const char* s, size_t l) {
4211 memcpy(luaL_prepbuffsize(B, l), s, l);

Callers 1

luaL_addlstringFunction · 0.70

Calls 2

luaL_errorFunction · 0.85
lua_newuserdatauvFunction · 0.85

Tested by

no test coverage detected