Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed argument error logging
Fixed, that second value can not be any type
  • Loading branch information
Audifire committed May 27, 2015
1 parent c30efc1 commit 846703c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 29 deletions.
39 changes: 22 additions & 17 deletions MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Commands.cpp
Expand Up @@ -119,23 +119,28 @@ int CLuaFunctionDefs::toJSON ( lua_State* luaVM )
// Got a string argument?
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, false, bCompact ) )
{
// Return the JSON string
lua_pushstring ( luaVM, strJSON.c_str () );
return 1;
}
if ( !argStream.NextIsNil () )
{
bool bCompact = false;
// Read the argument
CLuaArguments JSON;
JSON.ReadArgument ( luaVM, 1 );
argStream.Skip ( 1 );
argStream.ReadBool ( bCompact, false );

if ( !argStream.HasErrors () )
{
// Convert it to a JSON string
std::string strJSON;
if ( JSON.WriteToJSONString ( strJSON, false, bCompact ) )
{
// Return the JSON string
lua_pushstring ( luaVM, strJSON.c_str () );
return 1;
}
}
else
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
}
else
m_pScriptDebugging->LogBadType ( luaVM );
Expand Down
32 changes: 20 additions & 12 deletions MTA10_Server/mods/deathmatch/logic/lua/CLuaFunctionDefs.Utility.cpp
Expand Up @@ -370,10 +370,11 @@ int CLuaFunctionDefs::GetTok ( lua_State* luaVM )
return 1;
}

int CLuaFunctionDefs::toJSON ( lua_State* luaVM )
{
int CLuaFunctionDefs::toJSON ( lua_State* luaVM )
{
// Got a string argument?
CScriptArgReader argStream ( luaVM );

if ( !argStream.NextIsNil () )
{
bool bCompact = false;
Expand All @@ -383,19 +384,26 @@ int CLuaFunctionDefs::toJSON ( lua_State* luaVM )
argStream.Skip ( 1 );
argStream.ReadBool ( bCompact, false );

// Convert it to a JSON string
std::string strJSON;
if ( JSON.WriteToJSONString ( strJSON, false, bCompact ) )
if ( !argStream.HasErrors () )
{
// Return the JSON string
lua_pushstring ( luaVM, strJSON.c_str () );
return 1;
// Convert it to a JSON string
std::string strJSON;
if ( JSON.WriteToJSONString ( strJSON, false, bCompact ) )
{
// Return the JSON string
lua_pushstring ( luaVM, strJSON.c_str () );
return 1;
}
}
else
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
}

// Failed
lua_pushnil ( luaVM );
return 1;
else
m_pScriptDebugging->LogBadType ( luaVM );

// Failed
lua_pushnil ( luaVM );
return 1;
}


Expand Down

0 comments on commit 846703c

Please sign in to comment.