Skip to content

Commit

Permalink
Fix Lua error when WML assigns a real number to an integer attribute
Browse files Browse the repository at this point in the history
This regressed in the Lua 5.3 upgrade. LuaL_checkinteger() started to give
an error when the variable isn't an integer. In Lua 5.2 it truncated the
variable instead.

Fortunately we have a macro for modifying attributes, and thus I can fix
all the errors at once.

Maybe a version of the macro that gives an error when the attribute isn't
an integer would be useful as well.
  • Loading branch information
jyrkive committed Oct 29, 2016
1 parent ff813af commit e3c249f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/scripting/lua_common.hpp
Expand Up @@ -262,14 +262,14 @@ int luaW_type_error (lua_State *L, int narg, const char *tname);

#define modify_int_attrib(name, accessor) \
if (strcmp(m, name) == 0) { \
int value = luaL_checkinteger(L, 3); \
int value = static_cast<int>(luaL_checknumber(L, 3)); \
accessor; \
return 0; \
}

#define modify_int_attrib_check_range(name, accessor, allowed_min, allowed_max) \
if (strcmp(m, name) == 0) { \
int value = luaL_checkinteger(L, 3); \
int value = static_cast<int>(luaL_checknumber(L, 3)); \
if (value < allowed_min || allowed_max < value) return luaL_argerror(L, 3, "out of bounds"); \
accessor; \
return 0; \
Expand Down

0 comments on commit e3c249f

Please sign in to comment.