MCPcopy Create free account
hub / github.com/defold/defold / SaveTSTRING

Function SaveTSTRING

engine/script/src/script_table.cpp:263–279  ·  view source on GitHub ↗

When storing/packing lua data to a byte array, we now use the binary lua string interface

Source from the content-addressed store, hash-verified

261
262 // When storing/packing lua data to a byte array, we now use the binary lua string interface
263 static uint32_t SaveTSTRING(lua_State* L, int index, char* buffer, uint32_t buffer_size, const char* buffer_end, uint32_t count, dmArray<const void*>& table_stack)
264 {
265 size_t value_len = 0;
266 const char* value = lua_tolstring(L, index, &value_len);
267 uint32_t total_size = value_len + sizeof(uint32_t);
268 if (buffer_end - buffer < (intptr_t)total_size)
269 {
270 table_stack.SetCapacity(0);
271 luaL_error(L, "buffer (%d bytes) too small for table, exceeded at '%s' for element #%d", buffer_size, value, count);
272 }
273
274 uint32_t len = (uint32_t)value_len;
275 memcpy(buffer, &len, sizeof(uint32_t));
276 buffer += sizeof(uint32_t);
277 memcpy(buffer, value, value_len);
278 return total_size;
279 }
280
281 // When loading older save games, we will use the old unpack method (with truncated c strings)
282 static uint32_t LoadOldTSTRING(lua_State* L, const char* buffer, const char* buffer_end, uint32_t count, PushTableLogger& logger)

Callers 1

DoCheckTableFunction · 0.85

Calls 3

lua_tolstringFunction · 0.85
luaL_errorFunction · 0.85
SetCapacityMethod · 0.45

Tested by

no test coverage detected