Add basic lua 5.3 support

This commit is contained in:
Bart van Strien
2015-06-16 10:25:41 +02:00
parent df1bd42dec
commit 3cb777e2b7
39 changed files with 252 additions and 187 deletions
+4 -4
View File
@@ -72,7 +72,7 @@ int w_newTrueTypeRasterizer(lua_State *L)
if (lua_type(L, 1) == LUA_TNUMBER || lua_isnone(L, 1))
{
// First argument is a number: use the default TrueType font.
int size = luaL_optint(L, 1, 12);
int size = (int) luaL_optnumber(L, 1, 12);
const char *hintstr = lua_isnoneornil(L, 2) ? nullptr : luaL_checkstring(L, 2);
if (hintstr && !TrueTypeRasterizer::getConstant(hintstr, hinting))
@@ -89,7 +89,7 @@ int w_newTrueTypeRasterizer(lua_State *L)
else
d = filesystem::luax_getfiledata(L, 1);
int size = luaL_optint(L, 2, 12);
int size = (int) luaL_optnumber(L, 2, 12);
const char *hintstr = lua_isnoneornil(L, 3) ? nullptr : luaL_checkstring(L, 3);
if (hintstr && !TrueTypeRasterizer::getConstant(hintstr, hinting))
@@ -121,7 +121,7 @@ int w_newBMFontRasterizer(lua_State *L)
if (lua_istable(L, 2))
{
for (int i = 1; i <= (int) lua_objlen(L, 2); i++)
for (int i = 1; i <= (int) luax_objlen(L, 2); i++)
{
lua_rawgeti(L, 2, i);
@@ -162,7 +162,7 @@ int w_newImageRasterizer(lua_State *L)
image::ImageData *d = luax_checktype<image::ImageData>(L, 1, IMAGE_IMAGE_DATA_ID);
std::string glyphs = luax_checkstring(L, 2);
int extraspacing = luaL_optint(L, 3, 0);
int extraspacing = (int) luaL_optnumber(L, 3, 0);
luax_catchexcept(L, [&](){ t = instance()->newImageRasterizer(d, glyphs, extraspacing); });
+4 -4
View File
@@ -66,10 +66,10 @@ int w_Canvas_newImageData(lua_State *L)
{
Canvas *canvas = luax_checkcanvas(L, 1);
love::image::Image *image = luax_getmodule<love::image::Image>(L, MODULE_IMAGE_ID);
int x = luaL_optint(L, 2, 0);
int y = luaL_optint(L, 3, 0);
int w = luaL_optint(L, 4, canvas->getWidth());
int h = luaL_optint(L, 5, canvas->getHeight());
int x = (int) luaL_optnumber(L, 2, 0);
int y = (int) luaL_optnumber(L, 3, 0);
int w = (int) luaL_optnumber(L, 4, canvas->getWidth());
int h = (int) luaL_optnumber(L, 5, canvas->getHeight());
love::image::ImageData *img = nullptr;
luax_catchexcept(L, [&](){ img = canvas->newImageData(image, x, y, w, h); });
+40 -40
View File
@@ -94,7 +94,7 @@ int w_discard(lua_State *L)
if (lua_istable(L, 1))
{
for (size_t i = 1; i <= lua_objlen(L, 1); i++)
for (size_t i = 1; i <= luax_objlen(L, 1); i++)
{
lua_rawgeti(L, 1, i);
colorbuffers.push_back(luax_optboolean(L, -1, true));
@@ -161,10 +161,10 @@ int w_setScissor(lua_State *L)
return 0;
}
int x = luaL_checkint(L, 1);
int y = luaL_checkint(L, 2);
int w = luaL_checkint(L, 3);
int h = luaL_checkint(L, 4);
int x = (int) luaL_checknumber(L, 1);
int y = (int) luaL_checknumber(L, 2);
int w = (int) luaL_checknumber(L, 3);
int h = (int) luaL_checknumber(L, 4);
if (w < 0 || h < 0)
return luaL_error(L, "Can't set scissor with negative width and/or height.");
@@ -392,7 +392,7 @@ int w_newImageFont(lua_State *L)
int w_newSpriteBatch(lua_State *L)
{
Texture *texture = luax_checktexture(L, 1);
int size = luaL_optint(L, 2, 1000);
int size = (int) luaL_optnumber(L, 2, 1000);
Mesh::Usage usage = Mesh::USAGE_DYNAMIC;
if (lua_gettop(L) > 2)
{
@@ -431,10 +431,10 @@ int w_newParticleSystem(lua_State *L)
int w_newCanvas(lua_State *L)
{
// check if width and height are given. else default to screen dimensions.
int width = luaL_optint(L, 1, instance()->getWidth());
int height = luaL_optint(L, 2, instance()->getHeight());
int width = (int) luaL_optnumber(L, 1, instance()->getWidth());
int height = (int) luaL_optnumber(L, 2, instance()->getHeight());
const char *str = luaL_optstring(L, 3, "normal");
int msaa = luaL_optint(L, 4, 0);
int msaa = (int) luaL_optnumber(L, 4, 0);
Canvas::Format format;
if (!Canvas::getConstant(str, format))
@@ -600,7 +600,7 @@ static Mesh *newStandardMesh(lua_State *L)
// standard vertices.
if (lua_istable(L, 1))
{
size_t vertexcount = lua_objlen(L, 1);
size_t vertexcount = luax_objlen(L, 1);
std::vector<Vertex> vertices;
vertices.reserve(vertexcount);
@@ -637,7 +637,7 @@ static Mesh *newStandardMesh(lua_State *L)
}
else
{
int count = luaL_checkint(L, 1);
int count = (int) luaL_checknumber(L, 1);
luax_catchexcept(L, [&](){ t = instance()->newMesh(count, drawmode, usage); });
}
@@ -664,7 +664,7 @@ static Mesh *newCustomMesh(lua_State *L)
lua_pop(L, 1);
// Per-vertex attribute formats.
for (int i = 1; i <= (int) lua_objlen(L, 1); i++)
for (int i = 1; i <= (int) luax_objlen(L, 1); i++)
{
lua_rawgeti(L, 1, i);
@@ -682,7 +682,7 @@ static Mesh *newCustomMesh(lua_State *L)
return nullptr;
}
format.components = luaL_checkint(L, -1);
format.components = (int) luaL_checknumber(L, -1);
if (format.components <= 0 || format.components > 4)
{
luaL_error(L, "Number of vertex attribute components must be between 1 and 4 (got %d)", format.components);
@@ -695,7 +695,7 @@ static Mesh *newCustomMesh(lua_State *L)
if (lua_isnumber(L, 2))
{
int vertexcount = luaL_checkint(L, 2);
int vertexcount = (int) luaL_checknumber(L, 2);
luax_catchexcept(L, [&](){ t = instance()->newMesh(vertexformat, vertexcount, drawmode, usage); });
}
else if (luax_istype(L, 2, DATA_ID))
@@ -719,7 +719,7 @@ static Mesh *newCustomMesh(lua_State *L)
for (const Mesh::AttribFormat &format : vertexformat)
vertexcomponents += format.components;
size_t numvertices = lua_objlen(L, 2);
size_t numvertices = luax_objlen(L, 2);
luax_catchexcept(L, [&](){ t = instance()->newMesh(vertexformat, numvertices, drawmode, usage); });
@@ -732,11 +732,11 @@ static Mesh *newCustomMesh(lua_State *L)
lua_rawgeti(L, 2, vertindex + 1);
luaL_checktype(L, -1, LUA_TTABLE);
if ((int) lua_objlen(L, -1) < vertexcomponents)
if ((int) luax_objlen(L, -1) < vertexcomponents)
{
t->release();
const char *err = "Invalid number of components in vertex #%d (expected %d components, got %d)";
luaL_error(L, err, vertindex+1, vertexcomponents, lua_objlen(L, -1));
luaL_error(L, err, vertindex+1, vertexcomponents, luax_objlen(L, -1));
return nullptr;
}
@@ -827,19 +827,19 @@ int w_setColor(lua_State *L)
for (int i = 1; i <= 4; i++)
lua_rawgeti(L, 1, i);
c.r = (unsigned char)luaL_checkint(L, -4);
c.g = (unsigned char)luaL_checkint(L, -3);
c.b = (unsigned char)luaL_checkint(L, -2);
c.a = (unsigned char)luaL_optint(L, -1, 255);
c.r = (unsigned char) luaL_checknumber(L, -4);
c.g = (unsigned char) luaL_checknumber(L, -3);
c.b = (unsigned char) luaL_checknumber(L, -2);
c.a = (unsigned char) luaL_optnumber(L, -1, 255);
lua_pop(L, 4);
}
else
{
c.r = (unsigned char)luaL_checkint(L, 1);
c.g = (unsigned char)luaL_checkint(L, 2);
c.b = (unsigned char)luaL_checkint(L, 3);
c.a = (unsigned char)luaL_optint(L, 4, 255);
c.r = (unsigned char) luaL_checknumber(L, 1);
c.g = (unsigned char) luaL_checknumber(L, 2);
c.b = (unsigned char) luaL_checknumber(L, 3);
c.a = (unsigned char) luaL_optnumber(L, 4, 255);
}
instance()->setColor(c);
return 0;
@@ -863,19 +863,19 @@ int w_setBackgroundColor(lua_State *L)
for (int i = 1; i <= 4; i++)
lua_rawgeti(L, 1, i);
c.r = (unsigned char)luaL_checkint(L, -4);
c.g = (unsigned char)luaL_checkint(L, -3);
c.b = (unsigned char)luaL_checkint(L, -2);
c.a = (unsigned char)luaL_optint(L, -1, 255);
c.r = (unsigned char) luaL_checknumber(L, -4);
c.g = (unsigned char) luaL_checknumber(L, -3);
c.b = (unsigned char) luaL_checknumber(L, -2);
c.a = (unsigned char) luaL_optnumber(L, -1, 255);
lua_pop(L, 4);
}
else
{
c.r = (unsigned char)luaL_checkint(L, 1);
c.g = (unsigned char)luaL_checkint(L, 2);
c.b = (unsigned char)luaL_checkint(L, 3);
c.a = (unsigned char)luaL_optint(L, 4, 255);
c.r = (unsigned char) luaL_checknumber(L, 1);
c.g = (unsigned char) luaL_checknumber(L, 2);
c.b = (unsigned char) luaL_checknumber(L, 3);
c.a = (unsigned char) luaL_optnumber(L, 4, 255);
}
instance()->setBackgroundColor(c);
return 0;
@@ -1153,7 +1153,7 @@ int w_setCanvas(lua_State *L)
if (is_table)
{
for (int i = 1; i <= (int) lua_objlen(L, 1); i++)
for (int i = 1; i <= (int) luax_objlen(L, 1); i++)
{
lua_rawgeti(L, 1, i);
canvases.push_back(luax_checkcanvas(L, -1));
@@ -1490,7 +1490,7 @@ int w_line(lua_State *L)
bool is_table = false;
if (args == 1 && lua_istable(L, 1))
{
args = (int) lua_objlen(L, 1);
args = (int) luax_objlen(L, 1);
is_table = true;
}
@@ -1551,7 +1551,7 @@ int w_rectangle(lua_State *L)
if (lua_isnoneornil(L, 8))
points = std::max(rx, ry) > 20.0 ? (int)(std::max(rx, ry) / 2) : 10;
else
points = luaL_checkint(L, 8);
points = (int) luaL_checknumber(L, 8);
instance()->rectangle(mode, x, y, w, h, rx, ry, points);
return 0;
@@ -1571,7 +1571,7 @@ int w_circle(lua_State *L)
if (lua_isnoneornil(L, 5))
points = radius > 10 ? (int)(radius) : 10;
else
points = luaL_checkint(L, 5);
points = (int) luaL_checknumber(L, 5);
instance()->circle(mode, x, y, radius, points);
return 0;
@@ -1593,7 +1593,7 @@ int w_ellipse(lua_State *L)
if (lua_isnoneornil(L, 6))
points = a + b > 30 ? (int)((a + b) / 2) : 15;
else
points = luaL_checkint(L, 6);
points = (int) luaL_checknumber(L, 6);
instance()->ellipse(mode, x, y, a, b, points);
return 0;
@@ -1615,7 +1615,7 @@ int w_arc(lua_State *L)
if (lua_isnoneornil(L, 7))
points = radius > 10 ? (int)(radius) : 10;
else
points = luaL_checkint(L, 7);
points = (int) luaL_checknumber(L, 7);
instance()->arc(mode, x, y, radius, angle1, angle2, points);
return 0;
@@ -1634,7 +1634,7 @@ int w_polygon(lua_State *L)
float *coords;
if (args == 1 && lua_istable(L, 2))
{
args = (int) lua_objlen(L, 2);
args = (int) luax_objlen(L, 2);
is_table = true;
}
+4 -4
View File
@@ -80,10 +80,10 @@ int w_Image_refresh(lua_State *L)
{
Image *i = luax_checkimage(L, 1);
int xoffset = luaL_optint(L, 2, 0);
int yoffset = luaL_optint(L, 3, 0);
int w = luaL_optint(L, 4, i->getWidth());
int h = luaL_optint(L, 5, i->getHeight());
int xoffset = (int) luaL_optnumber(L, 2, 0);
int yoffset = (int) luaL_optnumber(L, 3, 0);
int w = (int) luaL_optnumber(L, 4, i->getWidth());
int h = (int) luaL_optnumber(L, 5, i->getHeight());
luax_catchexcept(L, [&](){ i->refresh(xoffset, yoffset, w, h); });
return 0;
+4 -4
View File
@@ -90,7 +90,7 @@ int w_Mesh_setVertices(lua_State *L)
Mesh *t = luax_checkmesh(L, 1);
luaL_checktype(L, 2, LUA_TTABLE);
size_t nvertices = lua_objlen(L, 2);
size_t nvertices = luax_objlen(L, 2);
if (nvertices != t->getVertexCount())
return luaL_error(L, "Invalid number of vertices (expected %d, got %d)", (int) t->getVertexCount(), (int) nvertices);
@@ -312,7 +312,7 @@ int w_Mesh_setVertexMap(lua_State *L)
Mesh *t = luax_checkmesh(L, 1);
bool is_table = lua_istable(L, 2);
int nargs = is_table ? (int) lua_objlen(L, 2) : lua_gettop(L) - 1;
int nargs = is_table ? (int) luax_objlen(L, 2) : lua_gettop(L) - 1;
std::vector<uint32> vertexmap;
vertexmap.reserve(nargs);
@@ -424,8 +424,8 @@ int w_Mesh_setDrawRange(lua_State *L)
t->setDrawRange();
else
{
int rangemin = luaL_checkint(L, 2) - 1;
int rangemax = luaL_checkint(L, 3) - 1;
int rangemin = (int) luaL_checknumber(L, 2) - 1;
int rangemax = (int) luaL_checknumber(L, 3) - 1;
luax_catchexcept(L, [&](){ t->setDrawRange(rangemin, rangemax); });
}
@@ -505,7 +505,7 @@ int w_ParticleSystem_setColors(lua_State *L)
{
luaL_checktype(L, i + 2, LUA_TTABLE);
if (lua_objlen(L, i + 2) < 3)
if (luax_objlen(L, i + 2) < 3)
return luaL_argerror(L, i + 2, "expected 4 color components");
for (int j = 0; j < 4; j++)
@@ -592,7 +592,7 @@ int w_ParticleSystem_setQuads(lua_State *L)
if (lua_istable(L, 2))
{
for (int i = 1; i <= (int) lua_objlen(L, 2); i++)
for (int i = 1; i <= (int) luax_objlen(L, 2); i++)
{
lua_rawgeti(L, 2, i);
@@ -683,7 +683,7 @@ int w_ParticleSystem_reset(lua_State *L)
int w_ParticleSystem_emit(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
int num = luaL_checkint(L, 2);
int num = (int) luaL_checknumber(L, 2);
t->emit(num);
return 0;
}
+6 -6
View File
@@ -68,7 +68,7 @@ static T *_getScalars(lua_State *L, int count, size_t &dimension)
template <typename T>
static T *_getVectors(lua_State *L, int count, size_t &dimension)
{
dimension = lua_objlen(L, 3);
dimension = luax_objlen(L, 3);
T *values = new T[count * dimension];
for (int i = 0; i < count; ++i)
@@ -79,11 +79,11 @@ static T *_getVectors(lua_State *L, int count, size_t &dimension)
luax_typerror(L, 3 + i, "table");
return 0;
}
if (lua_objlen(L, 3 + i) != dimension)
if (luax_objlen(L, 3 + i) != dimension)
{
delete[] values;
luaL_error(L, "Error in argument %d: Expected table size %d, got %d.",
3+i, dimension, lua_objlen(L, 3+i));
3+i, dimension, luax_objlen(L, 3+i));
return 0;
}
@@ -258,19 +258,19 @@ static void w_convertMatrices(lua_State *L, int idx)
for (int matrix = idx; matrix < idx + matrixcount; matrix++)
{
luaL_checktype(L, matrix, LUA_TTABLE);
int dimension = (int) lua_objlen(L, matrix);
int dimension = (int) luax_objlen(L, matrix);
int newi = 1;
lua_createtable(L, dimension * dimension, 0);
// Collapse {{a,b,c}, {d,e,f}, ...} to {a,b,c, d,e,f, ...}
for (int i = 1; i <= (int) lua_objlen(L, matrix); i++)
for (int i = 1; i <= (int) luax_objlen(L, matrix); i++)
{
// Push args[matrix][i] onto the stack.
lua_rawgeti(L, matrix, i);
luaL_checktype(L, -1, LUA_TTABLE);
for (int j = 1; j <= (int) lua_objlen(L, -1); j++)
for (int j = 1; j <= (int) luax_objlen(L, -1); j++)
{
// Push args[matrix[i][j] onto the stack.
lua_rawgeti(L, -1, j);
@@ -78,7 +78,7 @@ int w_SpriteBatch_add(lua_State *L)
int w_SpriteBatch_set(lua_State *L)
{
SpriteBatch *t = luax_checkspritebatch(L, 1);
int id = luaL_checkint(L, 2);
int id = (int) luaL_checknumber(L, 2);
Quad *quad = nullptr;
int startidx = 3;
@@ -211,7 +211,7 @@ int w_SpriteBatch_getCount(lua_State *L)
int w_SpriteBatch_setBufferSize(lua_State *L)
{
SpriteBatch *t = luax_checkspritebatch(L, 1);
int size = luaL_checkint(L, 2);
int size = (int) luaL_checknumber(L, 2);
luax_catchexcept(L, [&]() {t->setBufferSize(size); });
return 0;
}
@@ -34,7 +34,7 @@ CompressedImageData *luax_checkcompressedimagedata(lua_State *L, int idx)
int w_CompressedImageData_getWidth(lua_State *L)
{
CompressedImageData *t = luax_checkcompressedimagedata(L, 1);
int miplevel = luaL_optint(L, 2, 1);
int miplevel = (int) luaL_optnumber(L, 2, 1);
int width = 0;
luax_catchexcept(L, [&](){ width = t->getWidth(miplevel - 1); });
@@ -46,7 +46,7 @@ int w_CompressedImageData_getWidth(lua_State *L)
int w_CompressedImageData_getHeight(lua_State *L)
{
CompressedImageData *t = luax_checkcompressedimagedata(L, 1);
int miplevel = luaL_optint(L, 2, 1);
int miplevel = (int) luaL_optnumber(L, 2, 1);
int height = 0;
luax_catchexcept(L, [&](){ height = t->getHeight(miplevel - 1); });
@@ -58,7 +58,7 @@ int w_CompressedImageData_getHeight(lua_State *L)
int w_CompressedImageData_getDimensions(lua_State *L)
{
CompressedImageData *t = luax_checkcompressedimagedata(L, 1);
int miplevel = luaL_optint(L, 2, 1);
int miplevel = (int) luaL_optnumber(L, 2, 1);
int width = 0, height = 0;
luax_catchexcept(L, [&]()
+2 -2
View File
@@ -39,8 +39,8 @@ int w_newImageData(lua_State *L)
// Case 1: Integers.
if (lua_isnumber(L, 1))
{
int w = luaL_checkint(L, 1);
int h = luaL_checkint(L, 2);
int w = (int) luaL_checknumber(L, 1);
int h = (int) luaL_checknumber(L, 2);
if (w <= 0 || h <= 0)
return luaL_error(L, "Invalid image size.");
+10 -10
View File
@@ -68,8 +68,8 @@ int w_ImageData_getDimensions(lua_State *L)
int w_ImageData_getPixel(lua_State *L)
{
ImageData *t = luax_checkimagedata(L, 1);
int x = luaL_checkint(L, 2);
int y = luaL_checkint(L, 3);
int x = (int) luaL_checknumber(L, 2);
int y = (int) luaL_checknumber(L, 3);
pixel c;
luax_catchexcept(L, [&](){ c = t->getPixel(x, y); });
@@ -84,8 +84,8 @@ int w_ImageData_getPixel(lua_State *L)
int w_ImageData_setPixel(lua_State *L)
{
ImageData *t = luax_checkimagedata(L, 1);
int x = luaL_checkint(L, 2);
int y = luaL_checkint(L, 3);
int x = (int) luaL_checknumber(L, 2);
int y = (int) luaL_checknumber(L, 3);
pixel c;
if (lua_istable(L, 4))
@@ -205,12 +205,12 @@ int w_ImageData_paste(lua_State *L)
{
ImageData *t = luax_checkimagedata(L, 1);
ImageData *src = luax_checkimagedata(L, 2);
int dx = luaL_checkint(L, 3);
int dy = luaL_checkint(L, 4);
int sx = luaL_optint(L, 5, 0);
int sy = luaL_optint(L, 6, 0);
int sw = luaL_optint(L, 7, src->getWidth());
int sh = luaL_optint(L, 8, src->getHeight());
int dx = (int) luaL_checknumber(L, 3);
int dy = (int) luaL_checknumber(L, 4);
int sx = (int) luaL_optnumber(L, 5, 0);
int sy = (int) luaL_optnumber(L, 6, 0);
int sw = (int) luaL_optnumber(L, 7, src->getWidth());
int sh = (int) luaL_optnumber(L, 8, src->getHeight());
t->paste((love::image::ImageData *)src, dx, dy, sx, sy, sw, sh);
return 0;
}
+3 -3
View File
@@ -95,7 +95,7 @@ int w_Joystick_getHatCount(lua_State *L)
int w_Joystick_getAxis(lua_State *L)
{
Joystick *j = luax_checkjoystick(L, 1);
int axisindex = luaL_checkint(L, 2) - 1;
int axisindex = (int) luaL_checknumber(L, 2) - 1;
lua_pushnumber(L, j->getAxis(axisindex));
return 1;
}
@@ -114,7 +114,7 @@ int w_Joystick_getAxes(lua_State *L)
int w_Joystick_getHat(lua_State *L)
{
Joystick *j = luax_checkjoystick(L, 1);
int hatindex = luaL_checkint(L, 2) - 1;
int hatindex = (int) luaL_checknumber(L, 2) - 1;
Joystick::Hat h = j->getHat(hatindex);
@@ -133,7 +133,7 @@ int w_Joystick_isDown(lua_State *L)
std::vector<int> buttons;
for (int i = 2; i <= lua_gettop(L); i++)
buttons.push_back(luaL_checkint(L, i) - 1);
buttons.push_back((int) luaL_checknumber(L, i) - 1);
luax_pushboolean(L, j->isDown(buttons));
return 1;
+3 -3
View File
@@ -91,14 +91,14 @@ int w_setGamepadMapping(lua_State *L)
switch (jinput.type)
{
case Joystick::INPUT_TYPE_AXIS:
jinput.axis = luaL_checkint(L, 4) - 1;
jinput.axis = (int) luaL_checknumber(L, 4) - 1;
break;
case Joystick::INPUT_TYPE_BUTTON:
jinput.button = luaL_checkint(L, 4) - 1;
jinput.button = (int) luaL_checknumber(L, 4) - 1;
break;
case Joystick::INPUT_TYPE_HAT:
// Hats need both a hat index and a hat value.
jinput.hat.index = luaL_checkint(L, 4) - 1;
jinput.hat.index = (int) luaL_checknumber(L, 4) - 1;
hatstr = luaL_checkstring(L, 5);
if (!Joystick::getConstant(hatstr, jinput.hat.value))
return luaL_error(L, "Invalid joystick hat: %s", hatstr);
+3 -3
View File
@@ -213,9 +213,9 @@ static int w_love_isVersionCompatible(lua_State *L)
version = luaL_checkstring(L, 1);
else
{
int major = luaL_checkint(L, 1);
int minor = luaL_checkint(L, 2);
int rev = luaL_checkint(L, 3);
int major = (int) luaL_checknumber(L, 1);
int minor = (int) luaL_checknumber(L, 2);
int rev = (int) luaL_checknumber(L, 3);
// Convert the numbers to a string, since VERSION_COMPATIBILITY is an
// array of version strings.
+5 -5
View File
@@ -52,7 +52,7 @@ int w_BezierCurve_getDerivative(lua_State *L)
int w_BezierCurve_getControlPoint(lua_State *L)
{
BezierCurve *curve = luax_checkbeziercurve(L, 1);
int idx = luaL_checkint(L, 2);
int idx = (int) luaL_checknumber(L, 2);
if (idx > 0) // 1-indexing
idx--;
@@ -69,7 +69,7 @@ int w_BezierCurve_getControlPoint(lua_State *L)
int w_BezierCurve_setControlPoint(lua_State *L)
{
BezierCurve *curve = luax_checkbeziercurve(L, 1);
int idx = luaL_checkint(L, 2);
int idx = (int) luaL_checknumber(L, 2);
float vx = (float) luaL_checknumber(L, 3);
float vy = (float) luaL_checknumber(L, 4);
@@ -85,7 +85,7 @@ int w_BezierCurve_insertControlPoint(lua_State *L)
BezierCurve *curve = luax_checkbeziercurve(L, 1);
float vx = (float) luaL_checknumber(L, 2);
float vy = (float) luaL_checknumber(L, 3);
int idx = luaL_optint(L, 4, -1);
int idx = (int) luaL_optnumber(L, 4, -1);
if (idx > 0) // 1-indexing
idx--;
@@ -97,7 +97,7 @@ int w_BezierCurve_insertControlPoint(lua_State *L)
int w_BezierCurve_removeControlPoint(lua_State *L)
{
BezierCurve *curve = luax_checkbeziercurve(L, 1);
int idx = luaL_checkint(L, 2);
int idx = (int) luaL_checknumber(L, 2);
if (idx > 0) // 1-indexing
idx--;
@@ -174,7 +174,7 @@ int w_BezierCurve_getSegment(lua_State *L)
int w_BezierCurve_render(lua_State *L)
{
BezierCurve *curve = luax_checkbeziercurve(L, 1);
int accuracy = luaL_optint(L, 2, 5);
int accuracy = (int) luaL_optnumber(L, 2, 5);
std::vector<Vector> points;
luax_catchexcept(L, [&](){ points = curve->render(accuracy); });
+5 -5
View File
@@ -111,7 +111,7 @@ int w_newBezierCurve(lua_State *L)
std::vector<Vector> points;
if (lua_istable(L, 1))
{
int top = (int) lua_objlen(L, 1);
int top = (int) luax_objlen(L, 1);
points.reserve(top / 2);
for (int i = 1; i <= top; i += 2)
{
@@ -150,7 +150,7 @@ int w_triangulate(lua_State *L)
std::vector<Vertex> vertices;
if (lua_istable(L, 1))
{
int top = (int) lua_objlen(L, 1);
int top = (int) luax_objlen(L, 1);
vertices.reserve(top / 2);
for (int i = 1; i <= top; i += 2)
{
@@ -220,7 +220,7 @@ int w_isConvex(lua_State *L)
std::vector<Vertex> vertices;
if (lua_istable(L, 1))
{
int top = (int) lua_objlen(L, 1);
int top = (int) luax_objlen(L, 1);
vertices.reserve(top / 2);
for (int i = 1; i <= top; i += 2)
{
@@ -258,7 +258,7 @@ static int getGammaArgs(lua_State *L, float color[4])
if (lua_istable(L, 1))
{
int n = (int) lua_objlen(L, 1);
int n = (int) luax_objlen(L, 1);
for (int i = 1; i <= n && i <= 4; i++)
{
lua_rawgeti(L, 1, i);
@@ -360,7 +360,7 @@ int w_compress(lua_State *L)
if (fstr && !Compressor::getConstant(fstr, format))
return luaL_error(L, "Invalid compressed format: %s", fstr);
int level = luaL_optint(L, 3, -1);
int level = (int) luaL_optnumber(L, 3, -1);
CompressedData *cdata = nullptr;
if (lua_isstring(L, 1))
+3 -3
View File
@@ -66,13 +66,13 @@ int luax_getrandom(lua_State *L, int startidx, double r)
lua_pushnumber(L, r);
break;
case 1:
u = luaL_checkint(L, startidx);
u = (int) luaL_checknumber(L, startidx);
luaL_argcheck(L, 1 <= u, startidx, "interval is empty");
lua_pushnumber(L, floor(r * u) + 1);
break;
case 2:
l = luaL_checkint(L, startidx);
u = luaL_checkint(L, startidx + 1);
l = (int) luaL_checknumber(L, startidx);
u = (int) luaL_checknumber(L, startidx + 1);
luaL_argcheck(L, l <= u, startidx + 1, "interval is empty");
lua_pushnumber(L, floor(r * (u - l + 1)) + l);
break;
+3 -3
View File
@@ -40,8 +40,8 @@ int w_newCursor(lua_State *L)
luax_convobj(L, 1, "image", "newImageData");
love::image::ImageData *data = luax_checktype<love::image::ImageData>(L, 1, IMAGE_IMAGE_DATA_ID);
int hotx = luaL_optint(L, 2, 0);
int hoty = luaL_optint(L, 3, 0);
int hotx = (int) luaL_optnumber(L, 2, 0);
int hoty = (int) luaL_optnumber(L, 3, 0);
luax_catchexcept(L, [&](){ cursor = instance()->newCursor(data, hotx, hoty); });
@@ -147,7 +147,7 @@ int w_isDown(lua_State *L)
buttons.reserve(num);
for (int i = 0; i < num; i++)
buttons.push_back(luaL_checkint(L, i + 1));
buttons.push_back((int) luaL_checknumber(L, i + 1));
luax_pushboolean(L, instance()->isDown(buttons));
return 1;
+2 -2
View File
@@ -263,7 +263,7 @@ int Fixture::rayCast(lua_State *L) const
float p2x = Physics::scaleDown((float)luaL_checknumber(L, 3));
float p2y = Physics::scaleDown((float)luaL_checknumber(L, 4));
float maxFraction = (float)luaL_checknumber(L, 5);
int childIndex = (int)luaL_optint(L, 6, 1) - 1; // Convert from 1-based index
int childIndex = (int) luaL_optnumber(L, 6, 1) - 1; // Convert from 1-based index
b2RayCastInput input;
input.p1.Set(p1x, p1y);
input.p2.Set(p2x, p2y);
@@ -279,7 +279,7 @@ int Fixture::rayCast(lua_State *L) const
int Fixture::getBoundingBox(lua_State *L) const
{
int childIndex = (int)luaL_optint(L, 1, 1) - 1; // Convert from 1-based index
int childIndex = (int) luaL_optnumber(L, 1, 1) - 1; // Convert from 1-based index
b2AABB box = fixture->GetAABB(childIndex);
box = Physics::scaleUp(box);
lua_pushnumber(L, box.lowerBound.x);
+2 -2
View File
@@ -97,7 +97,7 @@ int Physics::newPolygonShape(lua_State *L)
bool istable = lua_istable(L, 1);
if (istable)
argc = (int) lua_objlen(L, 1);
argc = (int) luax_objlen(L, 1);
if (argc % 2 != 0)
return luaL_error(L, "Number of vertex components must be a multiple of two.");
@@ -158,7 +158,7 @@ int Physics::newChainShape(lua_State *L)
bool istable = lua_istable(L, 2);
if (istable)
argc = (int) lua_objlen(L, 2);
argc = (int) luax_objlen(L, 2);
if (argc % 2 != 0)
return luaL_error(L, "Number of vertex components must be a multiple of two.");
+2 -2
View File
@@ -105,7 +105,7 @@ int Shape::rayCast(lua_State *L) const
float x = Physics::scaleDown((float)luaL_checknumber(L, 6));
float y = Physics::scaleDown((float)luaL_checknumber(L, 7));
float r = (float)luaL_checknumber(L, 8);
int childIndex = (int)luaL_optint(L, 9, 1) - 1; // Convert from 1-based index
int childIndex = (int) luaL_optnumber(L, 9, 1) - 1; // Convert from 1-based index
b2RayCastInput input;
input.p1.Set(p1x, p1y);
input.p2.Set(p2x, p2y);
@@ -125,7 +125,7 @@ int Shape::computeAABB(lua_State *L) const
float x = Physics::scaleDown((float)luaL_checknumber(L, 1));
float y = Physics::scaleDown((float)luaL_checknumber(L, 2));
float r = (float)luaL_checknumber(L, 3);
int childIndex = (int)luaL_optint(L, 4, 1) - 1; // Convert from 1-based index
int childIndex = (int) luaL_optnumber(L, 4, 1) - 1; // Convert from 1-based index
b2Transform transform(b2Vec2(x, y), b2Rot(r));
b2AABB box;
shape->ComputeAABB(&box, transform, childIndex);
@@ -55,7 +55,7 @@ int w_ChainShape_setPreviousVertex(lua_State *L)
int w_ChainShape_getChildEdge(lua_State *L)
{
ChainShape *c = luax_checkchainshape(L, 1);
int index = luaL_checkint(L, 2) - 1; // Convert from 1-based index
int index = (int) luaL_checknumber(L, 2) - 1; // Convert from 1-based index
EdgeShape *e = 0;
luax_catchexcept(L, [&](){ e = c->getChildEdge(index); });
luax_pushtype(L, PHYSICS_EDGE_SHAPE_ID, e);
@@ -74,7 +74,7 @@ int w_ChainShape_getVertexCount(lua_State *L)
int w_ChainShape_getPoint(lua_State *L)
{
ChainShape *c = luax_checkchainshape(L, 1);
int index = luaL_checkint(L, 2) - 1; // Convert from 1-based index
int index = (int) luaL_checknumber(L, 2) - 1; // Convert from 1-based index
b2Vec2 v;
luax_catchexcept(L, [&](){ v = c->getPoint(index); });
lua_pushnumber(L, v.x);
+4 -4
View File
@@ -165,9 +165,9 @@ int w_Fixture_setFilterData(lua_State *L)
{
Fixture *t = luax_checkfixture(L, 1);
int v[3];
v[0] = luaL_checkint(L, 2);
v[1] = luaL_checkint(L, 3);
v[2] = luaL_checkint(L, 4);
v[0] = (int) luaL_checknumber(L, 2);
v[1] = (int) luaL_checknumber(L, 3);
v[2] = (int) luaL_checknumber(L, 4);
t->setFilterData(v);
return 0;
}
@@ -250,7 +250,7 @@ int w_Fixture_getGroupIndex(lua_State *L)
int w_Fixture_setGroupIndex(lua_State *L)
{
Fixture *t = luax_checkfixture(L, 1);
int i = luaL_checkint(L, 2);
int i = (int) luaL_checknumber(L, 2);
t->setGroupIndex(i);
return 0;
}
+1 -1
View File
@@ -439,7 +439,7 @@ int w_getDistance(lua_State *L)
int w_setMeter(lua_State *L)
{
int arg1 = luaL_checkint(L, 1);
int arg1 = (int) luaL_checknumber(L, 1);
luax_catchexcept(L, [&](){ Physics::setMeter(arg1); });
return 0;
+5 -5
View File
@@ -38,10 +38,10 @@ int w_newSoundData(lua_State *L)
if (lua_isnumber(L, 1))
{
int samples = luaL_checkint(L, 1);
int sampleRate = luaL_optint(L, 2, Decoder::DEFAULT_SAMPLE_RATE);
int bitDepth = luaL_optint(L, 3, Decoder::DEFAULT_BIT_DEPTH);
int channels = luaL_optint(L, 4, Decoder::DEFAULT_CHANNELS);
int samples = (int) luaL_checknumber(L, 1);
int sampleRate = (int) luaL_optnumber(L, 2, Decoder::DEFAULT_SAMPLE_RATE);
int bitDepth = (int) luaL_optnumber(L, 3, Decoder::DEFAULT_BIT_DEPTH);
int channels = (int) luaL_optnumber(L, 4, Decoder::DEFAULT_CHANNELS);
luax_catchexcept(L, [&](){ t = instance()->newSoundData(samples, sampleRate, bitDepth, channels); });
}
@@ -66,7 +66,7 @@ int w_newSoundData(lua_State *L)
int w_newDecoder(lua_State *L)
{
love::filesystem::FileData *data = love::filesystem::luax_getfiledata(L, 1);
int bufferSize = luaL_optint(L, 2, Decoder::DEFAULT_BUFFER_SIZE);
int bufferSize = (int) luaL_optnumber(L, 2, Decoder::DEFAULT_BUFFER_SIZE);
Decoder *t = nullptr;
luax_catchexcept(L,
+13 -13
View File
@@ -36,7 +36,7 @@ int w_getDisplayCount(lua_State *L)
int w_getDisplayName(lua_State *L)
{
int index = luaL_checkint(L, 1) - 1;
int index = (int) luaL_checknumber(L, 1) - 1;
const char *name = nullptr;
luax_catchexcept(L, [&](){ name = instance()->getDisplayName(index); });
@@ -54,8 +54,8 @@ static const char *settingName(Window::Setting setting)
int w_setMode(lua_State *L)
{
int w = luaL_checkint(L, 1);
int h = luaL_checkint(L, 2);
int w = (int) luaL_checknumber(L, 1);
int h = (int) luaL_checknumber(L, 2);
if (lua_isnoneornil(L, 3))
{
@@ -114,8 +114,8 @@ int w_setMode(lua_State *L)
settings.useposition = !(lua_isnoneornil(L, -2) && lua_isnoneornil(L, -1));
if (settings.useposition)
{
settings.x = luaL_optint(L, -2, 0);
settings.y = luaL_optint(L, -1, 0);
settings.x = (int) luaL_optnumber(L, -2, 0);
settings.y = (int) luaL_optnumber(L, -1, 0);
}
lua_pop(L, 2);
@@ -194,7 +194,7 @@ int w_getFullscreenModes(lua_State *L)
{
int displayindex = 0;
if (!lua_isnoneornil(L, 1))
displayindex = luaL_checkint(L, 1);
displayindex = (int) luaL_checknumber(L, 1);
else
{
int x, y;
@@ -271,7 +271,7 @@ int w_getDesktopDimensions(lua_State *L)
int width = 0, height = 0;
int displayindex = 0;
if (!lua_isnoneornil(L, 1))
displayindex = luaL_checkint(L, 1);
displayindex = (int) luaL_checknumber(L, 1);
else
{
int x, y;
@@ -285,12 +285,12 @@ int w_getDesktopDimensions(lua_State *L)
int w_setPosition(lua_State *L)
{
int x = luaL_checkint(L, 1);
int y = luaL_checkint(L, 2);
int x = (int) luaL_checknumber(L, 1);
int y = (int) luaL_checknumber(L, 2);
int displayindex = 0;
if (!lua_isnoneornil(L, 3))
displayindex = luaL_checkint(L, 3);
displayindex = (int) luaL_checknumber(L, 3);
else
{
int x_unused, y_unused;
@@ -430,7 +430,7 @@ int w_showMessageBox(lua_State *L)
// means we should use the more complex message box API.
if (lua_istable(L, 3))
{
size_t numbuttons = lua_objlen(L, 3);
size_t numbuttons = luax_objlen(L, 3);
if (numbuttons == 0)
return luaL_error(L, "Must have at least one messagebox button.");
@@ -445,7 +445,7 @@ int w_showMessageBox(lua_State *L)
// Optional table entry specifying the button to use when enter is pressed.
lua_getfield(L, 3, "enterbutton");
if (!lua_isnoneornil(L, -1))
data.enterButtonIndex = luaL_checkint(L, -1) - 1;
data.enterButtonIndex = (int) luaL_checknumber(L, -1) - 1;
else
data.enterButtonIndex = 0;
lua_pop(L, 1);
@@ -453,7 +453,7 @@ int w_showMessageBox(lua_State *L)
// Optional table entry specifying the button to use when esc is pressed.
lua_getfield(L, 3, "escapebutton");
if (!lua_isnoneornil(L, -1))
data.escapeButtonIndex = luaL_checkint(L, -1) - 1;
data.escapeButtonIndex = (int) luaL_checknumber(L, -1) - 1;
else
data.escapeButtonIndex = (int) data.buttons.size() - 1;
lua_pop(L, 1);