Skip to content

Commit e21c3df

Browse files
committed
Changed Lua unsigned type check from error to warning
(This is just a temporary tolerance and will be reverted asap!)
1 parent e83d25e commit e21c3df

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class CRegisteredCommands;
3232

3333
class CLuaFunctionDefs
3434
{
35+
friend class CScriptArgReader;
36+
3537
public:
3638
static void Initialize ( class CLuaManager* pLuaManager,
3739
class CScriptDebugging* pScriptDebugging,

Shared/sdk/CScriptArgReader.h

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@
99
* Multi Theft Auto is available from http://www.multitheftauto.com/
1010
*
1111
*****************************************************************************/
12+
#pragma once
1213
#include <limits>
1314

15+
#ifdef MTA_CLIENT
16+
#include "CScriptDebugging.h"
17+
#endif
18+
1419
/////////////////////////////////////////////////////////////////////////
1520
//
1621
// CScriptArgReader
@@ -58,7 +63,7 @@ class CScriptArgReader
5863

5964
if ( std::is_unsigned < T > () && number < -FLT_EPSILON )
6065
{
61-
SetCustomError ( "Expected positive value, got negative", "Bad argument" );
66+
SetCustomWarning ( "Expected positive value, got negative. This warning may be an error in future versions." );
6267
return;
6368
}
6469

@@ -90,7 +95,7 @@ class CScriptArgReader
9095

9196
if ( std::is_unsigned < T > () && number < -FLT_EPSILON )
9297
{
93-
SetCustomError ( "Expected positive value, got negative", "Bad argument" );
98+
SetCustomWarning ( "Expected positive value, got negative. This warning may be an error in future versions." );
9499
return;
95100
}
96101

@@ -1121,11 +1126,24 @@ class CScriptArgReader
11211126
//
11221127
// HasErrors - Optional check if there are any unread arguments
11231128
//
1124-
bool HasErrors ( bool bCheckUnusedArgs = false ) const
1129+
bool HasErrors ( bool bCheckUnusedArgs = false )
11251130
{
11261131
assert ( !IsReadFunctionPending () );
11271132
if ( bCheckUnusedArgs && lua_type ( m_luaVM, m_iIndex ) != LUA_TNONE )
11281133
return true;
1134+
1135+
// Output warning here (there's no better way to integrate it without huge code changes
1136+
if ( !m_bError && !m_strCustomWarning.empty () )
1137+
{
1138+
#ifdef MTA_CLIENT
1139+
CLuaFunctionDefs::m_pScriptDebugging->LogWarning ( m_luaVM, m_strCustomWarning );
1140+
#else
1141+
g_pGame->GetScriptDebugging ()->LogWarning ( m_luaVM, m_strCustomWarning );
1142+
#endif
1143+
1144+
m_strCustomWarning.clear ();
1145+
}
1146+
11291147
return m_bError;
11301148
}
11311149

@@ -1216,6 +1234,14 @@ class CScriptArgReader
12161234
return SString ( "%s @ '%s' [%s]", *m_strErrorCategory, lua_tostring ( m_luaVM, lua_upvalueindex ( 1 ) ), *GetErrorMessage () );
12171235
}
12181236

1237+
//
1238+
// Set custom warning message
1239+
//
1240+
void SetCustomWarning ( const SString& message )
1241+
{
1242+
m_strCustomWarning = message;
1243+
}
1244+
12191245
//
12201246
// Skip n arguments
12211247
//
@@ -1237,5 +1263,6 @@ class CScriptArgReader
12371263
SString m_strErrorCategory;
12381264
bool m_bHasCustomMessage;
12391265
SString m_strCustomMessage;
1266+
SString m_strCustomWarning;
12401267

12411268
};

0 commit comments

Comments
 (0)