When storing/packing lua data to a byte array, we now use the binary lua string interface
| 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) |
no test coverage detected