@@ -291,7 +291,7 @@ void TableToJSONRecursive(GarrysMod::Lua::ILuaInterface* pLua, LuaUtilModuleData
291291 // }
292292
293293 while (pLua->Next (-2 )) {
294- // In bootil, you just don't give a child a name to indicate that it's sequentail .
294+ // In bootil, you just don't give a child a name to indicate that it's sequential .
295295 // so we need to support that.
296296 bool isSequential = false ;
297297 int iKeyType = pLua->GetType (-2 );
@@ -340,10 +340,14 @@ void TableToJSONRecursive(GarrysMod::Lua::ILuaInterface* pLua, LuaUtilModuleData
340340 case GarrysMod::Lua::Type::Number:
341341 {
342342 double pNumber = pLua->GetNumber (-1 );
343- if (IsInt (pNumber))
344- value.SetInt (pNumber);
345- else
346- value.SetDouble (pNumber);
343+ if (isfinite (pNumber)) { // Needed for math.huge
344+ if (IsInt (pNumber))
345+ value.SetInt (pNumber);
346+ else
347+ value.SetDouble (pNumber);
348+ } else {
349+ value.SetNull ();
350+ }
347351 }
348352 break ;
349353 case GarrysMod::Lua::Type::Bool:
@@ -483,6 +487,9 @@ void PushJSONValue(GarrysMod::Lua::ILuaInterface* pLua, const rapidjson::Value&
483487void JSONToTableRecursive (GarrysMod::Lua::ILuaInterface* pLua, const rapidjson::Value& jsonValue, bool noSet)
484488{
485489 if (jsonValue.IsObject ()) {
490+ if (!noSet)
491+ pLua->PreCreateTable (0 , jsonValue.MemberCount ());
492+
486493 for (rapidjson::Value::ConstMemberIterator itr = jsonValue.MemberBegin (); itr != jsonValue.MemberEnd (); ++itr) {
487494 const rapidjson::Value& value = itr->value ;
488495
@@ -500,12 +507,11 @@ void JSONToTableRecursive(GarrysMod::Lua::ILuaInterface* pLua, const rapidjson::
500507 PushJSONValue (pLua, itr->value );
501508
502509 if (!noSet)
503- {
504510 pLua->SetTable (-3 );
505- }
506511 }
507512 } else if (jsonValue.IsArray ()) {
508513 int idx = 0 ;
514+ pLua->PreCreateTable (jsonValue.Size (), 0 );
509515 for (rapidjson::SizeType i = 0 ; i < jsonValue.Size (); ++i)
510516 {
511517 JSONToTableRecursive (pLua, jsonValue[i], true );
@@ -528,7 +534,6 @@ LUA_FUNCTION_STATIC(util_JSONToTable)
528534 return 0 ;
529535 }
530536
531- LUA->CreateTable ();
532537 JSONToTableRecursive (LUA, doc);
533538 return 1 ;
534539}
@@ -790,10 +795,11 @@ void CUtilModule::LuaShutdown(GarrysMod::Lua::ILuaInterface* pLua)
790795 Util::RemoveField (pLua, " AsyncCompress" );
791796 Util::RemoveField (pLua, " AsyncDecompress" );
792797 Util::RemoveField (pLua, " FancyTableToJSON" );
798+ Util::RemoveField (pLua, " FancyJSONToTable" );
793799 Util::RemoveField (pLua, " CompressLZ4" );
794800 Util::RemoveField (pLua, " DecompressLZ4" );
795801 Util::RemoveField (pLua, " AsyncTableToJSON" );
796- Util::RemoveField (pLua, " AsyncJSONToTable" );
802+ // Util::RemoveField(pLua, "AsyncJSONToTable");
797803 Util::PopTable (pLua);
798804 }
799805}
0 commit comments