mirror of
https://github.com/love2d/love.git
synced 2026-08-19 12:14:20 +02:00
Avoid luaL_checkint and luaL_optint, they're not available in Lua 5.4.
Fixes #2102.
This commit is contained in:
@@ -202,6 +202,21 @@ inline float luax_checkfloat(lua_State *L, int idx)
|
|||||||
return static_cast<float>(luaL_checknumber(L, idx));
|
return static_cast<float>(luaL_checknumber(L, idx));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline int luax_toint(lua_State *L, int idx)
|
||||||
|
{
|
||||||
|
return (int)lua_tointeger(L, idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int luax_checkint(lua_State *L, int idx)
|
||||||
|
{
|
||||||
|
return (int)luaL_checkinteger(L, idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int luax_optint(lua_State *L, int idx, int def)
|
||||||
|
{
|
||||||
|
return (int)luaL_optinteger(L, idx, (lua_Integer)def);
|
||||||
|
}
|
||||||
|
|
||||||
inline lua_Number luax_checknumberclamped(lua_State *L, int idx, double minv, double maxv)
|
inline lua_Number luax_checknumberclamped(lua_State *L, int idx, double minv, double maxv)
|
||||||
{
|
{
|
||||||
return std::min(std::max(luaL_checknumber(L, idx), minv), maxv);
|
return std::min(std::max(luaL_checknumber(L, idx), minv), maxv);
|
||||||
|
|||||||
@@ -1301,22 +1301,22 @@ int w_newTextureView(lua_State *L)
|
|||||||
|
|
||||||
lua_getfield(L, 2, "mipmapstart");
|
lua_getfield(L, 2, "mipmapstart");
|
||||||
if (!lua_isnoneornil(L, -1))
|
if (!lua_isnoneornil(L, -1))
|
||||||
settings.mipmapStart.set(luaL_checkint(L, -1) - 1);
|
settings.mipmapStart.set(luax_checkint(L, -1) - 1);
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
lua_getfield(L, 2, "mipmapcount");
|
lua_getfield(L, 2, "mipmapcount");
|
||||||
if (!lua_isnoneornil(L, -1))
|
if (!lua_isnoneornil(L, -1))
|
||||||
settings.mipmapCount.set(luaL_checkint(L, -1));
|
settings.mipmapCount.set(luax_checkint(L, -1));
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
lua_getfield(L, 2, "layerstart");
|
lua_getfield(L, 2, "layerstart");
|
||||||
if (!lua_isnoneornil(L, -1))
|
if (!lua_isnoneornil(L, -1))
|
||||||
settings.layerStart.set(luaL_checkint(L, -1) - 1);
|
settings.layerStart.set(luax_checkint(L, -1) - 1);
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
lua_getfield(L, 2, "layers");
|
lua_getfield(L, 2, "layers");
|
||||||
if (!lua_isnoneornil(L, -1))
|
if (!lua_isnoneornil(L, -1))
|
||||||
settings.layerCount.set(luaL_checkint(L, -1));
|
settings.layerCount.set(luax_checkint(L, -1));
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
lua_getfield(L, 2, "debugname");
|
lua_getfield(L, 2, "debugname");
|
||||||
@@ -1771,7 +1771,7 @@ static Buffer::DataDeclaration luax_checkdatadeclaration(lua_State* L, int forma
|
|||||||
luaL_argerror(L, formattableidx, str.c_str());
|
luaL_argerror(L, formattableidx, str.c_str());
|
||||||
}
|
}
|
||||||
else if (!lua_isnoneornil(L, -1))
|
else if (!lua_isnoneornil(L, -1))
|
||||||
decl.bindingLocation = luaL_checkint(L, -1);
|
decl.bindingLocation = luax_checkint(L, -1);
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
return decl;
|
return decl;
|
||||||
@@ -2215,7 +2215,7 @@ static Mesh::BufferAttribute luax_checkbufferattributetable(lua_State *L, int id
|
|||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
lua_getfield(L, idx, "location");
|
lua_getfield(L, idx, "location");
|
||||||
attrib.bindingLocation = luaL_checkint(L, -1);
|
attrib.bindingLocation = luax_checkint(L, -1);
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
lua_getfield(L, idx, "name");
|
lua_getfield(L, idx, "name");
|
||||||
@@ -2234,7 +2234,7 @@ static Mesh::BufferAttribute luax_checkbufferattributetable(lua_State *L, int id
|
|||||||
|
|
||||||
lua_getfield(L, idx, "locationinbuffer");
|
lua_getfield(L, idx, "locationinbuffer");
|
||||||
if (!lua_isnoneornil(L, -1))
|
if (!lua_isnoneornil(L, -1))
|
||||||
attrib.bindingLocationInBuffer = luaL_checkint(L, -1);
|
attrib.bindingLocationInBuffer = luax_checkint(L, -1);
|
||||||
else
|
else
|
||||||
attrib.bindingLocationInBuffer = attrib.bindingLocation;
|
attrib.bindingLocationInBuffer = attrib.bindingLocation;
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|||||||
@@ -291,7 +291,7 @@ int w_Mesh_setAttributeEnabled(lua_State *L)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int location = luaL_checkint(L, 2);
|
int location = luax_checkint(L, 2);
|
||||||
luax_catchexcept(L, [&](){ t->setAttributeEnabled(location, enable); });
|
luax_catchexcept(L, [&](){ t->setAttributeEnabled(location, enable); });
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -308,7 +308,7 @@ int w_Mesh_isAttributeEnabled(lua_State *L)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int location = luaL_checkint(L, 2);
|
int location = luax_checkint(L, 2);
|
||||||
luax_catchexcept(L, [&](){ enabled = t->isAttributeEnabled(location); });
|
luax_catchexcept(L, [&](){ enabled = t->isAttributeEnabled(location); });
|
||||||
}
|
}
|
||||||
lua_pushboolean(L, enabled);
|
lua_pushboolean(L, enabled);
|
||||||
@@ -324,7 +324,7 @@ int w_Mesh_attachAttribute(lua_State *L)
|
|||||||
if (lua_type(L, 2) == LUA_TSTRING)
|
if (lua_type(L, 2) == LUA_TSTRING)
|
||||||
name = luaL_checkstring(L, 2);
|
name = luaL_checkstring(L, 2);
|
||||||
else
|
else
|
||||||
location = luaL_checkint(L, 2);
|
location = luax_checkint(L, 2);
|
||||||
|
|
||||||
Buffer *buffer = nullptr;
|
Buffer *buffer = nullptr;
|
||||||
Mesh *mesh = nullptr;
|
Mesh *mesh = nullptr;
|
||||||
@@ -350,7 +350,7 @@ int w_Mesh_attachAttribute(lua_State *L)
|
|||||||
if (name != nullptr)
|
if (name != nullptr)
|
||||||
attachname = luaL_optstring(L, 5, name);
|
attachname = luaL_optstring(L, 5, name);
|
||||||
else
|
else
|
||||||
attachlocation = luaL_optint(L, 5, location);
|
attachlocation = luax_optint(L, 5, location);
|
||||||
|
|
||||||
int startindex = (int) luaL_optinteger(L, 6, 1) - 1;
|
int startindex = (int) luaL_optinteger(L, 6, 1) - 1;
|
||||||
|
|
||||||
|
|||||||
@@ -163,10 +163,10 @@ int w_ImageData_mapPixel(lua_State *L)
|
|||||||
ImageData *t = luax_checkimagedata(L, 1);
|
ImageData *t = luax_checkimagedata(L, 1);
|
||||||
luaL_checktype(L, 2, LUA_TFUNCTION);
|
luaL_checktype(L, 2, LUA_TFUNCTION);
|
||||||
|
|
||||||
int sx = luaL_optint(L, 3, 0);
|
int sx = luax_optint(L, 3, 0);
|
||||||
int sy = luaL_optint(L, 4, 0);
|
int sy = luax_optint(L, 4, 0);
|
||||||
int w = luaL_optint(L, 5, t->getWidth());
|
int w = luax_optint(L, 5, t->getWidth());
|
||||||
int h = luaL_optint(L, 6, t->getHeight());
|
int h = luax_optint(L, 6, t->getHeight());
|
||||||
|
|
||||||
if (!(t->inside(sx, sy) && t->inside(sx+w-1, sy+h-1)))
|
if (!(t->inside(sx, sy) && t->inside(sx+w-1, sy+h-1)))
|
||||||
return luaL_error(L, "Invalid rectangle dimensions.");
|
return luaL_error(L, "Invalid rectangle dimensions.");
|
||||||
|
|||||||
Reference in New Issue
Block a user