mirror of
https://github.com/love2d/love.git
synced 2026-08-20 20:49:54 +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));
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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");
|
||||
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_getfield(L, 2, "mipmapcount");
|
||||
if (!lua_isnoneornil(L, -1))
|
||||
settings.mipmapCount.set(luaL_checkint(L, -1));
|
||||
settings.mipmapCount.set(luax_checkint(L, -1));
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_getfield(L, 2, "layerstart");
|
||||
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_getfield(L, 2, "layers");
|
||||
if (!lua_isnoneornil(L, -1))
|
||||
settings.layerCount.set(luaL_checkint(L, -1));
|
||||
settings.layerCount.set(luax_checkint(L, -1));
|
||||
lua_pop(L, 1);
|
||||
|
||||
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());
|
||||
}
|
||||
else if (!lua_isnoneornil(L, -1))
|
||||
decl.bindingLocation = luaL_checkint(L, -1);
|
||||
decl.bindingLocation = luax_checkint(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
return decl;
|
||||
@@ -2215,7 +2215,7 @@ static Mesh::BufferAttribute luax_checkbufferattributetable(lua_State *L, int id
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_getfield(L, idx, "location");
|
||||
attrib.bindingLocation = luaL_checkint(L, -1);
|
||||
attrib.bindingLocation = luax_checkint(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_getfield(L, idx, "name");
|
||||
@@ -2234,7 +2234,7 @@ static Mesh::BufferAttribute luax_checkbufferattributetable(lua_State *L, int id
|
||||
|
||||
lua_getfield(L, idx, "locationinbuffer");
|
||||
if (!lua_isnoneornil(L, -1))
|
||||
attrib.bindingLocationInBuffer = luaL_checkint(L, -1);
|
||||
attrib.bindingLocationInBuffer = luax_checkint(L, -1);
|
||||
else
|
||||
attrib.bindingLocationInBuffer = attrib.bindingLocation;
|
||||
lua_pop(L, 1);
|
||||
|
||||
@@ -291,7 +291,7 @@ int w_Mesh_setAttributeEnabled(lua_State *L)
|
||||
}
|
||||
else
|
||||
{
|
||||
int location = luaL_checkint(L, 2);
|
||||
int location = luax_checkint(L, 2);
|
||||
luax_catchexcept(L, [&](){ t->setAttributeEnabled(location, enable); });
|
||||
}
|
||||
return 0;
|
||||
@@ -308,7 +308,7 @@ int w_Mesh_isAttributeEnabled(lua_State *L)
|
||||
}
|
||||
else
|
||||
{
|
||||
int location = luaL_checkint(L, 2);
|
||||
int location = luax_checkint(L, 2);
|
||||
luax_catchexcept(L, [&](){ enabled = t->isAttributeEnabled(location); });
|
||||
}
|
||||
lua_pushboolean(L, enabled);
|
||||
@@ -324,7 +324,7 @@ int w_Mesh_attachAttribute(lua_State *L)
|
||||
if (lua_type(L, 2) == LUA_TSTRING)
|
||||
name = luaL_checkstring(L, 2);
|
||||
else
|
||||
location = luaL_checkint(L, 2);
|
||||
location = luax_checkint(L, 2);
|
||||
|
||||
Buffer *buffer = nullptr;
|
||||
Mesh *mesh = nullptr;
|
||||
@@ -350,7 +350,7 @@ int w_Mesh_attachAttribute(lua_State *L)
|
||||
if (name != nullptr)
|
||||
attachname = luaL_optstring(L, 5, name);
|
||||
else
|
||||
attachlocation = luaL_optint(L, 5, location);
|
||||
attachlocation = luax_optint(L, 5, location);
|
||||
|
||||
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);
|
||||
luaL_checktype(L, 2, LUA_TFUNCTION);
|
||||
|
||||
int sx = luaL_optint(L, 3, 0);
|
||||
int sy = luaL_optint(L, 4, 0);
|
||||
int w = luaL_optint(L, 5, t->getWidth());
|
||||
int h = luaL_optint(L, 6, t->getHeight());
|
||||
int sx = luax_optint(L, 3, 0);
|
||||
int sy = luax_optint(L, 4, 0);
|
||||
int w = luax_optint(L, 5, t->getWidth());
|
||||
int h = luax_optint(L, 6, t->getHeight());
|
||||
|
||||
if (!(t->inside(sx, sy) && t->inside(sx+w-1, sy+h-1)))
|
||||
return luaL_error(L, "Invalid rectangle dimensions.");
|
||||
|
||||
Reference in New Issue
Block a user