Skip to content

Commit a977603

Browse files
Fixed compile warnings.
1 parent 5a097e8 commit a977603

File tree

7 files changed

+63
-42
lines changed

7 files changed

+63
-42
lines changed

sockets/CFunctions.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ int CFunctions::sockOpen(lua_State* luaVM)
3636
// Put the host in a string, and the port in an unsigned short
3737
string strHost = lua_tostring ( luaVM, 1 );
3838
unsigned short usPort = static_cast < unsigned short > ( lua_tonumber ( luaVM, 2 ) );
39-
//bool bListen = ( ( lua_type ( luaVM, 3 ) == LUA_TBOOLEAN ) ? lua_toboolean ( luaVM, 3 ) : false );
39+
//bool bListen = ( ( lua_type ( luaVM, 3 ) == LUA_TBOOLEAN ) ? lua_toboolean ( luaVM, 3 ) == 1 : false );
4040

4141
// Create the socket
4242
CSocket* pSocket = new CSocket(luaVM, strHost, usPort);
4343
void* pUserdata = pSocket->GetUserdata();
4444
int iError = pSocket->GetLastSocketError ( );
4545

46+
//printf ( "Socket returned (error) code: %d\n", iError );
47+
4648
// The socket has got a userdata value if successfully created. It doesn't otherwise
4749
if ( pUserdata == NULL /*|| pSocket->IsConnected () == false*/ )
4850
{

sockets/CSocket.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ bool CSocket::DoPulse()
8484
FD_SET(m_pSocket, &wfds);
8585
// See if socket it writable
8686
int ret = select(m_pSocket+1, NULL, &wfds, NULL, &tv);
87+
//printf ( "select(...) returned: %d\n", ret );
88+
8789
if (ret == 0)
8890
return true; // Not writable yet
8991
if (ret == -1)
@@ -96,6 +98,7 @@ bool CSocket::DoPulse()
9698

9799
// Receive the data
98100
int iLength = recv(m_pSocket, chBuffer, SOCK_RECV_LIMIT, 0);
101+
// printf ( "Bytes received: %d\n", iLenght );
99102

100103
// Check if there were any errors
101104
int iError = GetLastSocketError();
@@ -123,12 +126,8 @@ bool CSocket::DoPulse()
123126
}
124127
}
125128
}
126-
else
127-
// If the socket doesn't exist, well, error?
128-
return false;
129129

130-
// If the call makes it up till here, it has been a huge success! Cake and true as a reward!
131-
return true;
130+
return false;
132131
}
133132

134133
bool CSocket::IsConnected()
@@ -221,13 +220,11 @@ int CSocket::HandleConnection(const int& iError)
221220
{
222221
return 0;
223222
}
224-
else
225-
{
223+
226224
#ifdef _DEBUG
227-
printf ( "Could not connect due to error: %i\n", iError ); // TEMP DEBUG
225+
printf ( "Could not connect due to error: %i\n", iError ); // TEMP DEBUG
228226
#endif
229-
return ERR_CONNECT_FAILURE;
230-
}
227+
return ERR_CONNECT_FAILURE;
231228
}
232229

233230
void CSocket::TriggerEvent(const string eventName, const string arg1)

sockets/CSocketManager.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ bool CSocketManager::SocketLimitExceeded ( void )
4040
return false;
4141
}
4242

43-
bool CSocketManager::SocketAdd(CSocket*& pSocket, bool bListen )
43+
bool CSocketManager::SocketAdd ( CSocket*& pSocket, bool bListen )
4444
{
4545
// Add the socket to the loop stuff
4646
sSocketsStorage* pSocketStorage = new sSocketsStorage ( pSocket, bListen );
@@ -49,7 +49,7 @@ bool CSocketManager::SocketAdd(CSocket*& pSocket, bool bListen )
4949
return true;
5050
}
5151

52-
bool CSocketManager::SocketRemove(CSocket*& pSocket)
52+
bool CSocketManager::SocketRemove ( CSocket*& pSocket )
5353
{
5454
// Check if an socket was actually specified
5555
if ( pSocket == NULL )
@@ -71,7 +71,7 @@ bool CSocketManager::SocketRemove(CSocket*& pSocket)
7171
return false;
7272
}
7373

74-
bool CSocketManager::GetSocket(CSocket*& pSocket, void* pUserdata)
74+
bool CSocketManager::GetSocket ( CSocket*& pSocket, void* pUserdata )
7575
{
7676
// Make sure a value has been passed. Don't bother if there hasn't been
7777
if (pUserdata == NULL)
@@ -92,7 +92,7 @@ bool CSocketManager::GetSocket(CSocket*& pSocket, void* pUserdata)
9292
return false;
9393
}
9494

95-
void CSocketManager::HandleStop()
95+
void CSocketManager::HandleStop ( void )
9696
{
9797
// Triggered at module stop. Simply destroys all sockets
9898
for (unsigned int i = 0; i < vecSockets.size(); ++i)

sockets/CSocketManager.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,12 @@ struct sSocketsStorage
3333
class CSocketManager
3434
{
3535
public:
36-
static void DoPulse ();
37-
38-
static bool SocketLimitExceeded ( void );
39-
static bool SocketAdd ( CSocket*& pSocket, bool bListen = false );
40-
static bool SocketRemove( CSocket*& pSocket );
41-
static bool GetSocket ( CSocket*& pSocket, void* pUserdata );
42-
43-
static void HandleStop ();
36+
static void DoPulse ( void );
37+
static bool SocketLimitExceeded ( void );
38+
static bool SocketAdd ( CSocket*& pSocket, bool bListen = false );
39+
static bool SocketRemove ( CSocket*& pSocket );
40+
static bool GetSocket ( CSocket*& pSocket, void* pUserdata );
41+
static void HandleStop ( void );
4442
};
4543

4644
#endif

sockets/extra/CLuaArguments.cpp

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*********************************************************/
1818

1919
#include "CLuaArguments.h"
20+
#include "../ml_sockets.h"
2021
#include <assert.h>
2122

2223
CLuaArguments::CLuaArguments ( const CLuaArguments& Arguments )
@@ -99,13 +100,43 @@ bool CLuaArguments::Call ( lua_State* luaVM, const char* szFunction ) const
99100
// Push our arguments onto the stack
100101
PushArguments ( luaVM );
101102

102-
int iret = lua_pcall ( luaVM, m_Arguments.size (), 0, 0 ) ;
103-
if ( iret == LUA_ERRRUN || iret == LUA_ERRMEM )
104-
{
105-
//const char* szRes = lua_tostring( luaVM, -1 );
106-
return false; // the function call failed
107-
}
108-
103+
// Call the function.
104+
int iret = lua_pcall ( luaVM, m_Arguments.size (), LUA_MULTRET, 0 );
105+
if ( iret == LUA_ERRRUN || iret == LUA_ERRMEM )
106+
{
107+
//const char* szRes = lua_tostring ( luaVM, -1 );
108+
return false; // The function call failed.
109+
}
110+
111+
// Get the function return values.
112+
while ( lua_gettop ( luaVM ) )
113+
{
114+
switch ( lua_type ( luaVM, lua_gettop ( luaVM ) ) )
115+
{
116+
case LUA_TNUMBER:
117+
//lua_tonumber ( luaVM, lua_gettop ( luaVM ) );
118+
break;
119+
120+
case LUA_TTABLE:
121+
// TODO
122+
break;
123+
124+
case LUA_TSTRING:
125+
//lua_tostring ( luaVM, lua_gettop ( luaVM ) );
126+
break;
127+
128+
case LUA_TBOOLEAN:
129+
//lua_toboolean ( luaVM, lua_gettop ( luaVM ) );
130+
break;
131+
132+
default:
133+
// TODO
134+
break;
135+
}
136+
137+
lua_pop ( luaVM, 1 );
138+
}
139+
109140
return true;
110141
}
111142

sockets/ml_sockets.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ MTAEXPORT bool InitModule ( ILuaModuleManager10 *pManager, char *szModuleName, c
2626
pModuleManager = pManager;
2727

2828
// Set the module info
29-
strncpy ( szModuleName, MODULE_NAME, MAX_INFO_LENGTH );
30-
strncpy ( szAuthor, MODULE_AUTHOR, MAX_INFO_LENGTH );
29+
strncpy_s ( szModuleName, _countof ( MODULE_NAME ), MODULE_NAME, MAX_INFO_LENGTH );
30+
strncpy_s ( szAuthor, _countof ( MODULE_AUTHOR ), MODULE_AUTHOR, MAX_INFO_LENGTH );
3131
(*fVersion) = MODULE_VERSION;
3232

3333
#ifdef WIN32
@@ -38,11 +38,12 @@ MTAEXPORT bool InitModule ( ILuaModuleManager10 *pManager, char *szModuleName, c
3838
#endif
3939

4040
WSADATA wsaData;
41+
int iError = WSAStartup ( MAKEWORD ( 2, 2 ), &wsaData );
4142

42-
if ( WSAStartup ( MAKEWORD ( 2, 2 ), &wsaData ) != 0 )
43+
if ( iError != 0 )
4344
{
4445
assert ( false );
45-
pModuleManager->ErrorPrintf("[Sockets] Can't start Winsock, aborting...");
46+
pModuleManager->ErrorPrintf ( "[Sockets] Can't start Winsock (Error: %d), aborting...", iError );
4647
return false;
4748
}
4849
#endif

sockets/ml_sockets.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@
1919
#ifndef _MLSOCK_H
2020
#define _MLSOCK_H
2121

22-
// Disable Visual Studio warnings
23-
#ifdef WIN32
24-
#pragma warning (disable : 4267) // DISABLE: conversion from 'size_t' to 'int', possible loss of data.
25-
#pragma warning (disable : 4996) // DISABLE: 'strcpy': This function or variable may be unsafe.
26-
#pragma warning (disable : 4244) // DISABLE: conversion from 'SOCKET' to 'int', possible loss of data.
27-
#pragma warning (disable : 4800) // DISABLE: 'int' : forcing value to bool 'true' or 'false' (performance warning).
28-
#endif
29-
3022
#include <assert.h>
3123

3224
/** MODULE SPECIFIC INFORMATION **/

0 commit comments

Comments
 (0)