| 1407 | */ |
| 1408 | |
| 1409 | static int Sys_Serialize(lua_State* L) |
| 1410 | { |
| 1411 | DM_LUA_STACK_CHECK(L, 1); |
| 1412 | luaL_checktype(L, 1, LUA_TTABLE); |
| 1413 | |
| 1414 | uint32_t table_size = CheckTableSize(L, 1); |
| 1415 | char* buffer = Sys_SetupTableSerializationBuffer(table_size); |
| 1416 | if (!buffer) |
| 1417 | { |
| 1418 | return luaL_error(L, "Could not allocate %d bytes for table serialization.", table_size); |
| 1419 | } |
| 1420 | |
| 1421 | uint32_t n_used = CheckTable(L, buffer, table_size, 1); |
| 1422 | lua_pushlstring(L, (const char*)buffer, n_used); |
| 1423 | Sys_FreeTableSerializationBuffer(buffer); |
| 1424 | return 1; |
| 1425 | |
| 1426 | } |
| 1427 | |
| 1428 | /*# deserializes buffer into a lua table |
| 1429 | * This function will raise a Lua error if an error occurs while deserializing the buffer. |
nothing calls this directly
no test coverage detected