Skip to content

Commit c30efc1

Browse files
committed
Add compact argument for toJSON from ID #0008848
1 parent 7aeb6c5 commit c30efc1

File tree

6 files changed

+14
-8
lines changed

6 files changed

+14
-8
lines changed

MTA10/mods/shared_logic/lua/CLuaArguments.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,12 +529,12 @@ bool CLuaArguments::WriteToBitStream ( NetBitStreamInterface& bitStream, CFastHa
529529
}
530530

531531

532-
bool CLuaArguments::WriteToJSONString ( std::string& strJSON, bool bSerialize )
532+
bool CLuaArguments::WriteToJSONString ( std::string& strJSON, bool bSerialize, bool bCompact )
533533
{
534534
json_object * my_array = WriteToJSONArray ( bSerialize );
535535
if ( my_array )
536536
{
537-
strJSON = json_object_get_string ( my_array );
537+
strJSON = json_object_to_json_string_ext ( my_array, bCompact ? JSON_C_TO_STRING_PLAIN : JSON_C_TO_STRING_SPACED );
538538
json_object_put ( my_array ); // dereference - causes a crash, is actually commented out in the example too
539539
return true;
540540
}

MTA10/mods/shared_logic/lua/CLuaArguments.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class CLuaArguments
7575
bool WriteToBitStream ( NetBitStreamInterface& bitStream, CFastHashMap < CLuaArguments*, unsigned long > * pKnownTables = NULL ) const;
7676
void ValidateTableKeys ( void );
7777
bool ReadFromJSONString ( const char* szJSON );
78-
bool WriteToJSONString ( std::string& strJSON, bool bSerialize = false );
78+
bool WriteToJSONString ( std::string& strJSON, bool bSerialize = false, bool bCompact = false );
7979
json_object * WriteTableToJSONObject ( bool bSerialize = false, CFastHashMap < CLuaArguments*, unsigned long > * pKnownTables = NULL );
8080
json_object * WriteToJSONArray ( bool bSerialize );
8181
bool ReadFromJSONObject ( json_object * object, std::vector < CLuaArguments* > * pKnownTables = NULL );

MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Commands.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,16 @@ int CLuaFunctionDefs::toJSON ( lua_State* luaVM )
121121

122122
if ( !argStream.NextIsNil ( ) )
123123
{
124+
bool bCompact = false;
124125
// Read the argument
125126
CLuaArguments JSON;
126127
JSON.ReadArgument ( luaVM, 1 );
128+
argStream.Skip ( 1 );
129+
argStream.ReadBool ( bCompact, false );
127130

128131
// Convert it to a JSON string
129132
std::string strJSON;
130-
if ( JSON.WriteToJSONString ( strJSON ) )
133+
if ( JSON.WriteToJSONString ( strJSON, false, bCompact ) )
131134
{
132135
// Return the JSON string
133136
lua_pushstring ( luaVM, strJSON.c_str () );

MTA10_Server/mods/deathmatch/logic/lua/CLuaArguments.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,12 +589,12 @@ bool CLuaArguments::WriteToBitStream ( NetBitStreamInterface& bitStream, CFastHa
589589
}
590590

591591

592-
bool CLuaArguments::WriteToJSONString ( std::string& strJSON, bool bSerialize )
592+
bool CLuaArguments::WriteToJSONString ( std::string& strJSON, bool bSerialize, bool bCompact )
593593
{
594594
json_object * my_array = WriteToJSONArray ( bSerialize );
595595
if ( my_array )
596596
{
597-
strJSON = json_object_get_string ( my_array );
597+
strJSON = json_object_to_json_string_ext ( my_array, bCompact ? JSON_C_TO_STRING_PLAIN : JSON_C_TO_STRING_SPACED );
598598
json_object_put ( my_array ); // dereference - causes a crash, is actually commented out in the example too
599599
return true;
600600
}

MTA10_Server/mods/deathmatch/logic/lua/CLuaArguments.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class CLuaArguments
9393
bool ReadFromBitStream ( NetBitStreamInterface& bitStream, std::vector < CLuaArguments* > * pKnownTables = NULL );
9494
bool ReadFromJSONString ( const char* szJSON );
9595
bool WriteToBitStream ( NetBitStreamInterface& bitStream, CFastHashMap < CLuaArguments*, unsigned long > * pKnownTables = NULL ) const;
96-
bool WriteToJSONString ( std::string& strJSON, bool bSerialize = false );
96+
bool WriteToJSONString ( std::string& strJSON, bool bSerialize = false, bool bCompact = false );
9797
json_object * WriteTableToJSONObject ( bool bSerialize = false, CFastHashMap < CLuaArguments*, unsigned long > * pKnownTables = NULL );
9898
json_object * WriteToJSONArray ( bool bSerialize );
9999
bool ReadFromJSONObject ( json_object * object, std::vector < CLuaArguments* > * pKnownTables = NULL );

MTA10_Server/mods/deathmatch/logic/lua/CLuaFunctionDefs.Utility.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,13 +376,16 @@ int CLuaFunctionDefs::toJSON ( lua_State* luaVM )
376376
CScriptArgReader argStream ( luaVM );
377377
if ( !argStream.NextIsNil () )
378378
{
379+
bool bCompact = false;
379380
// Read the argument
380381
CLuaArguments JSON;
381382
JSON.ReadArgument ( luaVM, 1 );
383+
argStream.Skip ( 1 );
384+
argStream.ReadBool ( bCompact, false );
382385

383386
// Convert it to a JSON string
384387
std::string strJSON;
385-
if ( JSON.WriteToJSONString ( strJSON ) )
388+
if ( JSON.WriteToJSONString ( strJSON, false, bCompact ) )
386389
{
387390
// Return the JSON string
388391
lua_pushstring ( luaVM, strJSON.c_str () );

0 commit comments

Comments
 (0)