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

    if ( !argStream.NextIsNil ( ) )
    {
        // Read the argument
        CLuaArguments JSON;
        JSON.ReadArgument ( luaVM, 1 );

        // Convert it to a JSON string
        std::string strJSON;
        if ( JSON.WriteToJSONString ( strJSON ) )
        {
            // Return the JSON string
            lua_pushstring ( luaVM, strJSON.c_str () );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogBadType ( luaVM );

    // Failed
    lua_pushnil ( luaVM );
    return 1;
}
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 );

        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 );

    // Failed
    lua_pushnil ( luaVM );
    return 1;
}
int CLuaFunctionDefs::toJSON ( lua_State* luaVM )
{
    // Got a string argument?
    CScriptArgReader argStream ( luaVM );

    if ( !argStream.NextIsNil () )
    {
        int jsonFlags = 0;
        // Read the argument
        CLuaArguments JSON;
        JSON.ReadArgument ( luaVM, 1 );
        argStream.Skip ( 1 );

        bool bCompact;
        argStream.ReadBool ( bCompact, false );
        jsonFlags |= bCompact ? JSON_C_TO_STRING_PLAIN : JSON_C_TO_STRING_SPACED;
        
        eJSONPrettyType jsonPrettyType;
        argStream.ReadEnumString ( jsonPrettyType, JSONPRETTY_NONE );
        if ( jsonPrettyType != JSONPRETTY_NONE )
            jsonFlags |= jsonPrettyType;

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

    // Failed
    lua_pushnil ( luaVM );
    return 1;
}
int CLuaFunctionDefs::toJSON ( lua_State* luaVM )
{
    // Got a string argument?
    if ( lua_type ( luaVM, 1 ) > LUA_TNIL )
    {
        // Read the argument
        CLuaArguments JSON;
        JSON.ReadArgument ( luaVM, 1 );

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

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