@@ -42,21 +42,27 @@ class CScriptArgReader
42
42
//
43
43
// Read next number
44
44
//
45
- template < class T >
45
+ template < typename T >
46
46
void ReadNumber ( T& outValue )
47
47
{
48
48
int iArgument = lua_type ( m_luaVM, m_iIndex );
49
49
if ( iArgument == LUA_TNUMBER || iArgument == LUA_TSTRING )
50
50
{
51
- lua_Number number = lua_tonumber (m_luaVM, m_iIndex++);
51
+ lua_Number number = lua_tonumber ( m_luaVM, m_iIndex++ );
52
+
53
+ if ( std::isnan ( number ) )
54
+ {
55
+ SetCustomError ( " Expected number, got NaN" , " Bad argument" );
56
+ return ;
57
+ }
52
58
53
- if (std::isnan (number) )
59
+ if ( std::is_unsigned < T > () && number < 0.0 )
54
60
{
55
- SetCustomError ( " Expected number , got NaN " , " Bad argument" );
61
+ SetCustomError ( " Expected positive value , got negative " , " Bad argument" );
56
62
return ;
57
63
}
58
64
59
- outValue = static_cast < T > (number);
65
+ outValue = static_cast < T > ( number );
60
66
return ;
61
67
}
62
68
@@ -68,17 +74,23 @@ class CScriptArgReader
68
74
//
69
75
// Read next number, using default if needed
70
76
//
71
- template < class T , class U >
77
+ template < typename T, typename U >
72
78
void ReadNumber ( T& outValue, const U& defaultValue )
73
79
{
74
80
int iArgument = lua_type ( m_luaVM, m_iIndex );
75
81
if ( iArgument == LUA_TNUMBER || iArgument == LUA_TSTRING )
76
82
{
77
- lua_Number number = lua_tonumber (m_luaVM, m_iIndex++);
83
+ lua_Number number = lua_tonumber ( m_luaVM, m_iIndex++ );
84
+
85
+ if ( std::isnan ( number ) )
86
+ {
87
+ SetCustomError ( " Expected number, got NaN" , " Bad argument" );
88
+ return ;
89
+ }
78
90
79
- if (std::isnan (number) )
91
+ if ( std::is_unsigned < T > () && number < 0.0 )
80
92
{
81
- SetCustomError ( " Expected number , got NaN " , " Bad argument" );
93
+ SetCustomError ( " Expected positive value , got negative " , " Bad argument" );
82
94
return ;
83
95
}
84
96
0 commit comments