Permalink
Browse files

Add compact argument for toJSON from ID #0008848

  • Loading branch information...
Audifire committed May 10, 2015
1 parent 7aeb6c5 commit c30efc1190bf6f66a00dd2461f1978503364ca4e
@@ -529,12 +529,12 @@ bool CLuaArguments::WriteToBitStream ( NetBitStreamInterface& bitStream, CFastHa
}


bool CLuaArguments::WriteToJSONString ( std::string& strJSON, bool bSerialize )
bool CLuaArguments::WriteToJSONString ( std::string& strJSON, bool bSerialize, bool bCompact )
{
json_object * my_array = WriteToJSONArray ( bSerialize );
if ( my_array )
{
strJSON = json_object_get_string ( my_array );
strJSON = json_object_to_json_string_ext ( my_array, bCompact ? JSON_C_TO_STRING_PLAIN : JSON_C_TO_STRING_SPACED );
json_object_put ( my_array ); // dereference - causes a crash, is actually commented out in the example too
return true;
}
@@ -75,7 +75,7 @@ class CLuaArguments
bool WriteToBitStream ( NetBitStreamInterface& bitStream, CFastHashMap < CLuaArguments*, unsigned long > * pKnownTables = NULL ) const;
void ValidateTableKeys ( void );
bool ReadFromJSONString ( const char* szJSON );
bool WriteToJSONString ( std::string& strJSON, bool bSerialize = false );
bool WriteToJSONString ( std::string& strJSON, bool bSerialize = false, bool bCompact = false );
json_object * WriteTableToJSONObject ( bool bSerialize = false, CFastHashMap < CLuaArguments*, unsigned long > * pKnownTables = NULL );
json_object * WriteToJSONArray ( bool bSerialize );
bool ReadFromJSONObject ( json_object * object, std::vector < CLuaArguments* > * pKnownTables = NULL );
@@ -121,13 +121,16 @@ int CLuaFunctionDefs::toJSON ( lua_State* luaVM )

if ( !argStream.NextIsNil ( ) )
{
bool bCompact = false;
// Read the argument
CLuaArguments JSON;
JSON.ReadArgument ( luaVM, 1 );
argStream.Skip ( 1 );
argStream.ReadBool ( bCompact, false );

// Convert it to a JSON string
std::string strJSON;
if ( JSON.WriteToJSONString ( strJSON ) )
if ( JSON.WriteToJSONString ( strJSON, false, bCompact ) )
{
// Return the JSON string
lua_pushstring ( luaVM, strJSON.c_str () );
@@ -589,12 +589,12 @@ bool CLuaArguments::WriteToBitStream ( NetBitStreamInterface& bitStream, CFastHa
}


bool CLuaArguments::WriteToJSONString ( std::string& strJSON, bool bSerialize )
bool CLuaArguments::WriteToJSONString ( std::string& strJSON, bool bSerialize, bool bCompact )
{
json_object * my_array = WriteToJSONArray ( bSerialize );
if ( my_array )
{
strJSON = json_object_get_string ( my_array );
strJSON = json_object_to_json_string_ext ( my_array, bCompact ? JSON_C_TO_STRING_PLAIN : JSON_C_TO_STRING_SPACED );
json_object_put ( my_array ); // dereference - causes a crash, is actually commented out in the example too
return true;
}
@@ -93,7 +93,7 @@ class CLuaArguments
bool ReadFromBitStream ( NetBitStreamInterface& bitStream, std::vector < CLuaArguments* > * pKnownTables = NULL );
bool ReadFromJSONString ( const char* szJSON );
bool WriteToBitStream ( NetBitStreamInterface& bitStream, CFastHashMap < CLuaArguments*, unsigned long > * pKnownTables = NULL ) const;
bool WriteToJSONString ( std::string& strJSON, bool bSerialize = false );
bool WriteToJSONString ( std::string& strJSON, bool bSerialize = false, bool bCompact = false );
json_object * WriteTableToJSONObject ( bool bSerialize = false, CFastHashMap < CLuaArguments*, unsigned long > * pKnownTables = NULL );
json_object * WriteToJSONArray ( bool bSerialize );
bool ReadFromJSONObject ( json_object * object, std::vector < CLuaArguments* > * pKnownTables = NULL );
@@ -376,13 +376,16 @@ int CLuaFunctionDefs::toJSON ( lua_State* luaVM )
CScriptArgReader argStream ( luaVM );
if ( !argStream.NextIsNil () )
{
bool bCompact = false;
// Read the argument
CLuaArguments JSON;
JSON.ReadArgument ( luaVM, 1 );
argStream.Skip ( 1 );
argStream.ReadBool ( bCompact, false );

// Convert it to a JSON string
std::string strJSON;
if ( JSON.WriteToJSONString ( strJSON ) )
if ( JSON.WriteToJSONString ( strJSON, false, bCompact ) )
{
// Return the JSON string
lua_pushstring ( luaVM, strJSON.c_str () );

0 comments on commit c30efc1

Please sign in to comment.