Skip to content

Commit

Permalink
Use static cast
Browse files Browse the repository at this point in the history
The lua_toint macro was deprecated for Lua 5.3.3; originally, Wesnoth changed the macro to use a static_cast<int>.

After upgrading to the lua_tointeger function, add the static_cast<int> at each call site to suppress warnings about possible loss of precision due to defining LUA_INTEGER as long long.
  • Loading branch information
GregoryLundberg committed Oct 17, 2016
1 parent f97436b commit ecdfb81
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/ai/lua/lua_object.hpp
Expand Up @@ -102,7 +102,7 @@ inline std::shared_ptr<bool> lua_object<bool>::to_type(lua_State *L, int n)
template <>
inline std::shared_ptr<int> lua_object<int>::to_type(lua_State *L, int n)
{
return std::shared_ptr<int>(new int(lua_tointeger(L, n)));
return std::shared_ptr<int>(new int(static_cast<int>(lua_tointeger(L, n))));
}

template <>
Expand Down Expand Up @@ -159,20 +159,20 @@ inline std::shared_ptr<std::vector<target> > lua_object< std::vector<target> >::

lua_pushstring(L, "x"); // st n + 3
lua_rawget(L, -2); // st n + 3
int x = lua_tointeger(L, -1); // st n + 3
int x = static_cast<int>(lua_tointeger(L, -1)); // st n + 3
lua_pop(L, 1); // st n + 2

lua_pushstring(L, "y"); // st n + 3
lua_rawget(L, -2); // st n + 3
int y = lua_tointeger(L, -1); // st n + 3
int y = static_cast<int>(lua_tointeger(L, -1)); // st n + 3

lua_pop(L, 2); // st n + 1

lua_pushstring(L, "type"); // st n + 2
lua_rawget(L, -2); // st n + 2
target::TYPE type = target::TYPE::EXPLICIT;
if(lua_isnumber(L, -1)) {
type = target::TYPE::from_int(lua_tointeger(L, -1)); // st n + 2
type = target::TYPE::from_int(static_cast<int>(lua_tointeger(L, -1))); // st n + 2
} else if(lua_isstring(L, -1)) {
type = target::TYPE::string_to_enum(lua_tostring(L, -1)); // st n + 2
}
Expand All @@ -181,7 +181,7 @@ inline std::shared_ptr<std::vector<target> > lua_object< std::vector<target> >::

lua_pushstring(L, "value");
lua_rawget(L, -2);
int value = lua_tointeger(L, -1);
int value = static_cast<int>(lua_tointeger(L, -1));

map_location ml(x, y, wml_loc());

Expand Down

0 comments on commit ecdfb81

Please sign in to comment.