Skip to content

Commit 117b0b2

Browse files
authored
Add short and char support to the new parser (#1555)
1 parent 2e79024 commit 117b0b2

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

Shared/mods/deathmatch/logic/lua/CLuaFunctionParser.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,10 @@ struct CLuaFunctionParserBase
4646
{
4747
if constexpr (std::is_same_v<T, std::string> || std::is_same_v<T, std::string_view>)
4848
return "string";
49-
else if constexpr (std::is_same_v<T, int> || std::is_same_v<T, float> || std::is_same_v<T, double> || std::is_same_v<T, short> ||
50-
std::is_same_v<T, unsigned int> || std::is_same_v<T, unsigned short>)
51-
return "number";
5249
else if constexpr (std::is_same_v<T, bool>)
5350
return "boolean";
51+
else if constexpr (std::is_arithmetic_v<T>)
52+
return "number";
5453
else if constexpr (std::is_enum_v<T>)
5554
return "enum";
5655
else if constexpr (is_specialization<T, std::optional>::value)
@@ -188,11 +187,10 @@ struct CLuaFunctionParserBase
188187
// primitive types
189188
if constexpr (std::is_same_v<T, std::string> || std::is_same_v<T, std::string_view>)
190189
return (iArgument == LUA_TSTRING || iArgument == LUA_TNUMBER);
191-
if constexpr (std::is_same_v<T, int> || std::is_same_v<T, float> || std::is_same_v<T, double> || std::is_same_v<T, short> ||
192-
std::is_same_v<T, unsigned int> || std::is_same_v<T, unsigned short>)
193-
return lua_isnumber(L, index);
194190
if constexpr (std::is_same_v<T, bool>)
195191
return (iArgument == LUA_TBOOLEAN);
192+
if constexpr (std::is_arithmetic_v<T>)
193+
return lua_isnumber(L, index);
196194

197195
// Advanced types
198196
// Enums are represented as strings to Lua
@@ -336,8 +334,7 @@ struct CLuaFunctionParserBase
336334
if constexpr (std::is_same_v<T, dummy_type>)
337335
return dummy_type{};
338336
// primitive types are directly popped
339-
else if constexpr (std::is_same_v<T, std::string> || std::is_same_v<T, int> || std::is_same_v<T, short> || std::is_same_v<T, bool> ||
340-
std::is_same_v<T, unsigned int> || std::is_same_v<T, unsigned short> || std::is_same_v<T, std::string_view>)
337+
else if constexpr (std::is_same_v<T, std::string> || std::is_same_v<T, std::string_view> || std::is_integral_v<T>)
341338
return lua::PopPrimitive<T>(L, index);
342339
// floats/doubles may not be NaN
343340
else if constexpr (std::is_same_v<T, float> || std::is_same_v<T, double>)

Shared/mods/deathmatch/logic/lua/LuaBasic.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,30 @@ namespace lua
4141
return static_cast<unsigned int>(lua_tonumber(L, index++));
4242
}
4343

44+
template <>
45+
short PopPrimitive<short>(lua_State* L, std::size_t& index)
46+
{
47+
return static_cast<short>(lua_tonumber(L, index++));
48+
}
49+
50+
template <>
51+
unsigned short PopPrimitive<unsigned short>(lua_State* L, std::size_t& index)
52+
{
53+
return static_cast<unsigned short>(lua_tonumber(L, index++));
54+
}
55+
56+
template <>
57+
char PopPrimitive<char>(lua_State* L, std::size_t& index)
58+
{
59+
return static_cast<char>(lua_tonumber(L, index++));
60+
}
61+
62+
template <>
63+
unsigned char PopPrimitive<unsigned char>(lua_State* L, std::size_t& index)
64+
{
65+
return static_cast<unsigned char>(lua_tonumber(L, index++));
66+
}
67+
4468
template <>
4569
int64_t PopPrimitive<int64_t>(lua_State* L, std::size_t& index)
4670
{

0 commit comments

Comments
 (0)