From 34ebe18f14d31d0fe7935de6a78fdafbb6189e0b Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sun, 16 Jul 2017 12:17:50 -0300 Subject: [PATCH] Use luaL_check/optinteger instead of luaL_check/optnumber when getting integer arguments to functions. Resolves issue #1251. --HG-- branch : minor --- src/modules/audio/wrap_Audio.cpp | 2 +- src/modules/font/wrap_Font.cpp | 6 +-- src/modules/graphics/opengl/Mesh.cpp | 2 +- src/modules/graphics/wrap_Canvas.cpp | 2 +- src/modules/graphics/wrap_Graphics.cpp | 50 +++++++++---------- src/modules/graphics/wrap_Image.cpp | 6 +-- src/modules/graphics/wrap_Mesh.cpp | 6 +-- src/modules/graphics/wrap_ParticleSystem.cpp | 2 +- src/modules/graphics/wrap_Quad.cpp | 2 +- src/modules/graphics/wrap_SpriteBatch.cpp | 10 ++-- src/modules/graphics/wrap_Text.cpp | 6 +-- .../image/wrap_CompressedImageData.cpp | 6 +-- src/modules/image/wrap_Image.cpp | 4 +- src/modules/image/wrap_ImageData.cpp | 20 ++++---- src/modules/joystick/wrap_Joystick.cpp | 8 +-- src/modules/joystick/wrap_JoystickModule.cpp | 6 +-- src/modules/love/love.cpp | 6 +-- src/modules/math/wrap_BezierCurve.cpp | 12 ++--- src/modules/math/wrap_Math.cpp | 2 +- src/modules/mouse/wrap_Mouse.cpp | 8 +-- src/modules/physics/box2d/Fixture.cpp | 4 +- src/modules/physics/box2d/Physics.cpp | 18 +++---- src/modules/physics/box2d/Physics.h | 6 +-- src/modules/physics/box2d/Shape.cpp | 4 +- src/modules/physics/box2d/wrap_ChainShape.cpp | 4 +- src/modules/physics/box2d/wrap_Fixture.cpp | 8 +-- src/modules/physics/box2d/wrap_Physics.cpp | 2 +- src/modules/physics/box2d/wrap_World.cpp | 4 +- src/modules/sound/wrap_Sound.cpp | 10 ++-- src/modules/window/wrap_Window.cpp | 28 +++++------ 30 files changed, 127 insertions(+), 127 deletions(-) diff --git a/src/modules/audio/wrap_Audio.cpp b/src/modules/audio/wrap_Audio.cpp index 434079753..d3c985b50 100644 --- a/src/modules/audio/wrap_Audio.cpp +++ b/src/modules/audio/wrap_Audio.cpp @@ -84,7 +84,7 @@ int w_newQueueableSource(lua_State *L) Source *t = nullptr; luax_catchexcept(L, [&]() { - t = instance()->newSource((int)luaL_checknumber(L, 1), (int)luaL_checknumber(L, 2), (int)luaL_checknumber(L, 3), (int)luaL_optnumber(L, 4, 0)); + t = instance()->newSource((int)luaL_checkinteger(L, 1), (int)luaL_checkinteger(L, 2), (int)luaL_checkinteger(L, 3), (int)luaL_optinteger(L, 4, 0)); }); if (t != nullptr) diff --git a/src/modules/font/wrap_Font.cpp b/src/modules/font/wrap_Font.cpp index d11a7511d..7972f8a5b 100644 --- a/src/modules/font/wrap_Font.cpp +++ b/src/modules/font/wrap_Font.cpp @@ -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 = (int) luaL_optnumber(L, 1, 12); + int size = (int) luaL_optinteger(L, 1, 12); const char *hintstr = lua_isnoneornil(L, 2) ? nullptr : luaL_checkstring(L, 2); if (hintstr && !TrueTypeRasterizer::getConstant(hintstr, hinting)) @@ -98,7 +98,7 @@ int w_newTrueTypeRasterizer(lua_State *L) else d = filesystem::luax_getfiledata(L, 1); - int size = (int) luaL_optnumber(L, 2, 12); + int size = (int) luaL_optinteger(L, 2, 12); const char *hintstr = lua_isnoneornil(L, 3) ? nullptr : luaL_checkstring(L, 3); if (hintstr && !TrueTypeRasterizer::getConstant(hintstr, hinting)) @@ -180,7 +180,7 @@ int w_newImageRasterizer(lua_State *L) image::ImageData *d = luax_checktype(L, 1); std::string glyphs = luax_checkstring(L, 2); - int extraspacing = (int) luaL_optnumber(L, 3, 0); + int extraspacing = (int) luaL_optinteger(L, 3, 0); float pixeldensity = (float) luaL_optnumber(L, 4, 1.0); luax_catchexcept(L, [&](){ t = instance()->newImageRasterizer(d, glyphs, extraspacing, pixeldensity); }); diff --git a/src/modules/graphics/opengl/Mesh.cpp b/src/modules/graphics/opengl/Mesh.cpp index f84a779b8..d9b0207f6 100644 --- a/src/modules/graphics/opengl/Mesh.cpp +++ b/src/modules/graphics/opengl/Mesh.cpp @@ -96,7 +96,7 @@ void Mesh::drawInstanced(love::graphics::Graphics *gfx, const love::Matrix4 &m, if (vertexCount <= 0 || instancecount <= 0) return; - if (instancecount > 1 && !gl.isInstancingSupported()) + if (instancecount > 1 && !gfx->getCapabilities().features[Graphics::FEATURE_INSTANCING]) throw love::Exception("Instancing is not supported on this system."); gfx->flushStreamDraws(); diff --git a/src/modules/graphics/wrap_Canvas.cpp b/src/modules/graphics/wrap_Canvas.cpp index 808f361ae..178c94d4b 100644 --- a/src/modules/graphics/wrap_Canvas.cpp +++ b/src/modules/graphics/wrap_Canvas.cpp @@ -46,7 +46,7 @@ int w_Canvas_renderTo(lua_State *L) if (rt.canvas->getTextureType() != TEXTURE_2D) { - rt.slice = (int) luaL_checknumber(L, 2) - 1; + rt.slice = (int) luaL_checkinteger(L, 2) - 1; startidx++; } diff --git a/src/modules/graphics/wrap_Graphics.cpp b/src/modules/graphics/wrap_Graphics.cpp index c6b4ce142..e6e870813 100644 --- a/src/modules/graphics/wrap_Graphics.cpp +++ b/src/modules/graphics/wrap_Graphics.cpp @@ -321,7 +321,7 @@ int w_setCanvas(lua_State *L) if (i == 1 && type != TEXTURE_2D) { - target.slice = (int) luaL_checknumber(L, i + 1) - 1; + target.slice = (int) luaL_checkinteger(L, i + 1) - 1; target.mipmap = (int) luaL_optinteger(L, i + 2, 1) - 1; targets.colors.push_back(target); break; @@ -470,10 +470,10 @@ int w_setScissor(lua_State *L) } Rect rect; - rect.x = (int) luaL_checknumber(L, 1); - rect.y = (int) luaL_checknumber(L, 2); - rect.w = (int) luaL_checknumber(L, 3); - rect.h = (int) luaL_checknumber(L, 4); + rect.x = (int) luaL_checkinteger(L, 1); + rect.y = (int) luaL_checkinteger(L, 2); + rect.w = (int) luaL_checkinteger(L, 3); + rect.h = (int) luaL_checkinteger(L, 4); if (rect.w < 0 || rect.h < 0) return luaL_error(L, "Can't set scissor with negative width and/or height."); @@ -485,10 +485,10 @@ int w_setScissor(lua_State *L) int w_intersectScissor(lua_State *L) { Rect rect; - rect.x = (int) luaL_checknumber(L, 1); - rect.y = (int) luaL_checknumber(L, 2); - rect.w = (int) luaL_checknumber(L, 3); - rect.h = (int) luaL_checknumber(L, 4); + rect.x = (int) luaL_checkinteger(L, 1); + rect.y = (int) luaL_checkinteger(L, 2); + rect.w = (int) luaL_checkinteger(L, 3); + rect.h = (int) luaL_checkinteger(L, 4); if (rect.w < 0 || rect.h < 0) return luaL_error(L, "Can't set scissor with negative width and/or height."); @@ -524,7 +524,7 @@ int w_stencil(lua_State *L) return luaL_error(L, "Invalid stencil draw action: %s", actionstr); } - int stencilvalue = (int) luaL_optnumber(L, 3, 1); + int stencilvalue = (int) luaL_optinteger(L, 3, 1); // Fourth argument: whether to keep the contents of the stencil buffer. OptionalInt stencilclear; @@ -561,7 +561,7 @@ int w_setStencilTest(lua_State *L) if (!getConstant(comparestr, compare)) return luaL_error(L, "Invalid compare mode: %s", comparestr); - comparevalue = (int) luaL_checknumber(L, 2); + comparevalue = (int) luaL_checkinteger(L, 2); } luax_catchexcept(L, [&](){ instance()->setStencilTest(compare, comparevalue); }); @@ -942,14 +942,14 @@ int w_newQuad(lua_State *L) } else if (luax_istype(L, 6, Texture::type)) { - layer = (int) luaL_checknumber(L, 5) - 1; + layer = (int) luaL_checkinteger(L, 5) - 1; Texture *texture = luax_checktexture(L, 6); sw = texture->getWidth(); sh = texture->getHeight(); } else if (!lua_isnoneornil(L, 7)) { - layer = (int) luaL_checknumber(L, 5) - 1; + layer = (int) luaL_checkinteger(L, 5) - 1; sw = luaL_checknumber(L, 6); sh = luaL_checknumber(L, 7); } @@ -1030,7 +1030,7 @@ int w_newSpriteBatch(lua_State *L) luax_checkgraphicscreated(L); Texture *texture = luax_checktexture(L, 1); - int size = (int) luaL_optnumber(L, 2, 1000); + int size = (int) luaL_optinteger(L, 2, 1000); vertex::Usage usage = vertex::USAGE_DYNAMIC; if (lua_gettop(L) > 2) { @@ -1075,8 +1075,8 @@ int w_newCanvas(lua_State *L) Canvas::Settings settings; // check if width and height are given. else default to screen dimensions. - settings.width = (int) luaL_optnumber(L, 1, instance()->getWidth()); - settings.height = (int) luaL_optnumber(L, 2, instance()->getHeight()); + settings.width = (int) luaL_optinteger(L, 1, instance()->getWidth()); + settings.height = (int) luaL_optinteger(L, 2, instance()->getHeight()); // Default to the screen's current pixel density scale. settings.pixeldensity = instance()->getScreenPixelDensity(); @@ -1085,7 +1085,7 @@ int w_newCanvas(lua_State *L) if (lua_isnumber(L, 3)) { - settings.layers = (int) luaL_checknumber(L, 3); + settings.layers = (int) luaL_checkinteger(L, 3); settings.type = TEXTURE_2D_ARRAY; startidx = 4; } @@ -1352,7 +1352,7 @@ static Mesh *newStandardMesh(lua_State *L) } else { - int count = (int) luaL_checknumber(L, 1); + int count = (int) luaL_checkinteger(L, 1); luax_catchexcept(L, [&](){ t = instance()->newMesh(count, drawmode, usage); }); } @@ -1397,7 +1397,7 @@ static Mesh *newCustomMesh(lua_State *L) return nullptr; } - format.components = (int) luaL_checknumber(L, -1); + format.components = (int) luaL_checkinteger(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); @@ -1410,7 +1410,7 @@ static Mesh *newCustomMesh(lua_State *L) if (lua_isnumber(L, 2)) { - int vertexcount = (int) luaL_checknumber(L, 2); + int vertexcount = (int) luaL_checkinteger(L, 2); luax_catchexcept(L, [&](){ t = instance()->newMesh(vertexformat, vertexcount, drawmode, usage); }); } else if (luax_istype(L, 2, Data::type)) @@ -2135,7 +2135,7 @@ int w_drawLayer(lua_State *L) { Texture *texture = luax_checktexture(L, 1); Quad *quad = nullptr; - int layer = (int) luaL_checknumber(L, 2) - 1; + int layer = (int) luaL_checkinteger(L, 2) - 1; int startidx = 3; if (luax_istype(L, startidx, Quad::type)) @@ -2403,7 +2403,7 @@ int w_rectangle(lua_State *L) luax_catchexcept(L, [&](){ instance()->rectangle(mode, x, y, w, h, rx, ry); }); else { - int points = (int) luaL_checknumber(L, 8); + int points = (int) luaL_checkinteger(L, 8); luax_catchexcept(L, [&](){ instance()->rectangle(mode, x, y, w, h, rx, ry, points); }); } @@ -2425,7 +2425,7 @@ int w_circle(lua_State *L) luax_catchexcept(L, [&](){ instance()->circle(mode, x, y, radius); }); else { - int points = (int) luaL_checknumber(L, 5); + int points = (int) luaL_checkinteger(L, 5); luax_catchexcept(L, [&](){ instance()->circle(mode, x, y, radius, points); }); } @@ -2448,7 +2448,7 @@ int w_ellipse(lua_State *L) luax_catchexcept(L, [&](){ instance()->ellipse(mode, x, y, a, b); }); else { - int points = (int) luaL_checknumber(L, 6); + int points = (int) luaL_checkinteger(L, 6); luax_catchexcept(L, [&](){ instance()->ellipse(mode, x, y, a, b, points); }); } @@ -2485,7 +2485,7 @@ int w_arc(lua_State *L) luax_catchexcept(L, [&](){ instance()->arc(drawmode, arcmode, x, y, radius, angle1, angle2); }); else { - int points = (int) luaL_checknumber(L, startidx + 5); + int points = (int) luaL_checkinteger(L, startidx + 5); luax_catchexcept(L, [&](){ instance()->arc(drawmode, arcmode, x, y, radius, angle1, angle2, points); }); } diff --git a/src/modules/graphics/wrap_Image.cpp b/src/modules/graphics/wrap_Image.cpp index b25f7b2ff..5a8b3a4b5 100644 --- a/src/modules/graphics/wrap_Image.cpp +++ b/src/modules/graphics/wrap_Image.cpp @@ -56,12 +56,12 @@ int w_Image_replacePixels(lua_State *L) if (i->getTextureType() != TEXTURE_2D) { - slice = (int) luaL_checknumber(L, 3) - 1; + slice = (int) luaL_checkinteger(L, 3) - 1; if (!reloadmipmaps) - mipmap = (int) luaL_optnumber(L, 4, 1) - 1; + mipmap = (int) luaL_optinteger(L, 4, 1) - 1; } else if (!reloadmipmaps) - mipmap = (int) luaL_optnumber(L, 3, 1) - 1; + mipmap = (int) luaL_optinteger(L, 3, 1) - 1; luax_catchexcept(L, [&](){ i->replacePixels(id, slice, mipmap, reloadmipmaps); }); return 0; diff --git a/src/modules/graphics/wrap_Mesh.cpp b/src/modules/graphics/wrap_Mesh.cpp index a5326c24e..6f6b37f14 100644 --- a/src/modules/graphics/wrap_Mesh.cpp +++ b/src/modules/graphics/wrap_Mesh.cpp @@ -386,7 +386,7 @@ int w_Mesh_setVertexMap(lua_State *L) size_t datatypesize = vertex::getIndexDataSize(indextype); - int indexcount = (int) luaL_optnumber(L, 4, d->getSize() / datatypesize); + int indexcount = (int) luaL_optinteger(L, 4, d->getSize() / datatypesize); if (indexcount < 1 || indexcount * datatypesize > d->getSize()) return luaL_error(L, "Invalid index count: %d", indexcount); @@ -515,8 +515,8 @@ int w_Mesh_setDrawRange(lua_State *L) t->setDrawRange(); else { - int start = (int) luaL_checknumber(L, 2) - 1; - int count = (int) luaL_checknumber(L, 3); + int start = (int) luaL_checkinteger(L, 2) - 1; + int count = (int) luaL_checkinteger(L, 3); luax_catchexcept(L, [&](){ t->setDrawRange(start, count); }); } diff --git a/src/modules/graphics/wrap_ParticleSystem.cpp b/src/modules/graphics/wrap_ParticleSystem.cpp index 4958063c3..0f0e7642e 100644 --- a/src/modules/graphics/wrap_ParticleSystem.cpp +++ b/src/modules/graphics/wrap_ParticleSystem.cpp @@ -699,7 +699,7 @@ int w_ParticleSystem_reset(lua_State *L) int w_ParticleSystem_emit(lua_State *L) { ParticleSystem *t = luax_checkparticlesystem(L, 1); - int num = (int) luaL_checknumber(L, 2); + int num = (int) luaL_checkinteger(L, 2); t->emit(num); return 0; } diff --git a/src/modules/graphics/wrap_Quad.cpp b/src/modules/graphics/wrap_Quad.cpp index db2584ba3..00b728368 100644 --- a/src/modules/graphics/wrap_Quad.cpp +++ b/src/modules/graphics/wrap_Quad.cpp @@ -77,7 +77,7 @@ int w_Quad_getTextureDimensions(lua_State *L) int w_Quad_setLayer(lua_State *L) { Quad *quad = luax_checkquad(L, 1); - int layer = (int) luaL_checknumber(L, 2) - 1; + int layer = (int) luaL_checkinteger(L, 2) - 1; quad->setLayer(layer); return 0; } diff --git a/src/modules/graphics/wrap_SpriteBatch.cpp b/src/modules/graphics/wrap_SpriteBatch.cpp index 544d2c936..e7040bdf5 100644 --- a/src/modules/graphics/wrap_SpriteBatch.cpp +++ b/src/modules/graphics/wrap_SpriteBatch.cpp @@ -63,7 +63,7 @@ static inline int w_SpriteBatch_add_or_set(lua_State *L, SpriteBatch *t, int sta static int w_SpriteBatch_addLayer_or_setLayer(lua_State *L, SpriteBatch *t, int startidx, int index) { Quad *quad = nullptr; - int layer = (int) luaL_checknumber(L, startidx) - 1; + int layer = (int) luaL_checkinteger(L, startidx) - 1; startidx++; if (luax_istype(L, startidx, Quad::type)) @@ -101,7 +101,7 @@ int w_SpriteBatch_add(lua_State *L) int w_SpriteBatch_set(lua_State *L) { SpriteBatch *t = luax_checkspritebatch(L, 1); - int index = (int) luaL_checknumber(L, 2) - 1; + int index = (int) luaL_checkinteger(L, 2) - 1; w_SpriteBatch_add_or_set(L, t, 3, index); @@ -121,7 +121,7 @@ int w_SpriteBatch_addLayer(lua_State *L) int w_SpriteBatch_setLayer(lua_State *L) { SpriteBatch *t = luax_checkspritebatch(L, 1); - int index = (int) luaL_checknumber(L, 2) - 1; + int index = (int) luaL_checkinteger(L, 2) - 1; w_SpriteBatch_addLayer_or_setLayer(L, t, 3, index); @@ -251,8 +251,8 @@ int w_SpriteBatch_setDrawRange(lua_State *L) t->setDrawRange(); else { - int start = (int) luaL_checknumber(L, 2) - 1; - int count = (int) luaL_checknumber(L, 3); + int start = (int) luaL_checkinteger(L, 2) - 1; + int count = (int) luaL_checkinteger(L, 3); luax_catchexcept(L, [&](){ t->setDrawRange(start, count); }); } diff --git a/src/modules/graphics/wrap_Text.cpp b/src/modules/graphics/wrap_Text.cpp index 499c845d9..f003778fc 100644 --- a/src/modules/graphics/wrap_Text.cpp +++ b/src/modules/graphics/wrap_Text.cpp @@ -183,7 +183,7 @@ int w_Text_getFont(lua_State *L) int w_Text_getWidth(lua_State *L) { Text *t = luax_checktext(L, 1); - int index = (int) luaL_optnumber(L, 2, 0) - 1; + int index = (int) luaL_optinteger(L, 2, 0) - 1; lua_pushnumber(L, t->getWidth(index)); return 1; } @@ -191,7 +191,7 @@ int w_Text_getWidth(lua_State *L) int w_Text_getHeight(lua_State *L) { Text *t = luax_checktext(L, 1); - int index = (int) luaL_optnumber(L, 2, 0) - 1; + int index = (int) luaL_optinteger(L, 2, 0) - 1; lua_pushnumber(L, t->getHeight(index)); return 1; } @@ -199,7 +199,7 @@ int w_Text_getHeight(lua_State *L) int w_Text_getDimensions(lua_State *L) { Text *t = luax_checktext(L, 1); - int index = (int) luaL_optnumber(L, 2, 0) - 1; + int index = (int) luaL_optinteger(L, 2, 0) - 1; lua_pushnumber(L, t->getWidth(index)); lua_pushnumber(L, t->getHeight(index)); return 2; diff --git a/src/modules/image/wrap_CompressedImageData.cpp b/src/modules/image/wrap_CompressedImageData.cpp index 191e44c82..490394a2c 100644 --- a/src/modules/image/wrap_CompressedImageData.cpp +++ b/src/modules/image/wrap_CompressedImageData.cpp @@ -43,7 +43,7 @@ int w_CompressedImageData_clone(lua_State *L) int w_CompressedImageData_getWidth(lua_State *L) { CompressedImageData *t = luax_checkcompressedimagedata(L, 1); - int miplevel = (int) luaL_optnumber(L, 2, 1); + int miplevel = (int) luaL_optinteger(L, 2, 1); int width = 0; luax_catchexcept(L, [&](){ width = t->getWidth(miplevel - 1); }); @@ -55,7 +55,7 @@ int w_CompressedImageData_getWidth(lua_State *L) int w_CompressedImageData_getHeight(lua_State *L) { CompressedImageData *t = luax_checkcompressedimagedata(L, 1); - int miplevel = (int) luaL_optnumber(L, 2, 1); + int miplevel = (int) luaL_optinteger(L, 2, 1); int height = 0; luax_catchexcept(L, [&](){ height = t->getHeight(miplevel - 1); }); @@ -67,7 +67,7 @@ int w_CompressedImageData_getHeight(lua_State *L) int w_CompressedImageData_getDimensions(lua_State *L) { CompressedImageData *t = luax_checkcompressedimagedata(L, 1); - int miplevel = (int) luaL_optnumber(L, 2, 1); + int miplevel = (int) luaL_optinteger(L, 2, 1); int width = 0, height = 0; luax_catchexcept(L, [&]() diff --git a/src/modules/image/wrap_Image.cpp b/src/modules/image/wrap_Image.cpp index ace0db780..3456fe76f 100644 --- a/src/modules/image/wrap_Image.cpp +++ b/src/modules/image/wrap_Image.cpp @@ -39,8 +39,8 @@ int w_newImageData(lua_State *L) // Case 1: width & height. if (lua_isnumber(L, 1)) { - int w = (int) luaL_checknumber(L, 1); - int h = (int) luaL_checknumber(L, 2); + int w = (int) luaL_checkinteger(L, 1); + int h = (int) luaL_checkinteger(L, 2); if (w <= 0 || h <= 0) return luaL_error(L, "Invalid image size."); diff --git a/src/modules/image/wrap_ImageData.cpp b/src/modules/image/wrap_ImageData.cpp index f65d960c9..3f411e2fe 100644 --- a/src/modules/image/wrap_ImageData.cpp +++ b/src/modules/image/wrap_ImageData.cpp @@ -158,8 +158,8 @@ static pushpixel pushFormats[PIXELFORMAT_MAX_ENUM] = {}; int w_ImageData_getPixel(lua_State *L) { ImageData *t = luax_checkimagedata(L, 1); - int x = (int) luaL_checknumber(L, 2); - int y = (int) luaL_checknumber(L, 3); + int x = (int) luaL_checkinteger(L, 2); + int y = (int) luaL_checkinteger(L, 3); PixelFormat format = t->getFormat(); @@ -172,8 +172,8 @@ int w_ImageData_getPixel(lua_State *L) int w_ImageData_setPixel(lua_State *L) { ImageData *t = luax_checkimagedata(L, 1); - int x = (int) luaL_checknumber(L, 2); - int y = (int) luaL_checknumber(L, 3); + int x = (int) luaL_checkinteger(L, 2); + int y = (int) luaL_checkinteger(L, 3); PixelFormat format = t->getFormat(); @@ -247,12 +247,12 @@ int w_ImageData_paste(lua_State *L) { ImageData *t = luax_checkimagedata(L, 1); ImageData *src = luax_checkimagedata(L, 2); - 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()); + int dx = (int) luaL_checkinteger(L, 3); + int dy = (int) luaL_checkinteger(L, 4); + int sx = (int) luaL_optinteger(L, 5, 0); + int sy = (int) luaL_optinteger(L, 6, 0); + int sw = (int) luaL_optinteger(L, 7, src->getWidth()); + int sh = (int) luaL_optinteger(L, 8, src->getHeight()); t->paste((love::image::ImageData *)src, dx, dy, sx, sy, sw, sh); return 0; } diff --git a/src/modules/joystick/wrap_Joystick.cpp b/src/modules/joystick/wrap_Joystick.cpp index 444601304..45ecc81bf 100644 --- a/src/modules/joystick/wrap_Joystick.cpp +++ b/src/modules/joystick/wrap_Joystick.cpp @@ -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 = (int) luaL_checknumber(L, 2) - 1; + int axisindex = (int) luaL_checkinteger(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 = (int) luaL_checknumber(L, 2) - 1; + int hatindex = (int) luaL_checkinteger(L, 2) - 1; Joystick::Hat h = j->getHat(hatindex); @@ -143,14 +143,14 @@ int w_Joystick_isDown(lua_State *L) for (int i = 0; i < num; i++) { lua_rawgeti(L, 2, i + 1); - buttons.push_back((int) luaL_checknumber(L, -1) - 1); + buttons.push_back((int) luaL_checkinteger(L, -1) - 1); lua_pop(L, 1); } } else { for (int i = 0; i < num; i++) - buttons.push_back((int) luaL_checknumber(L, i + 2) - 1); + buttons.push_back((int) luaL_checkinteger(L, i + 2) - 1); } luax_pushboolean(L, j->isDown(buttons)); diff --git a/src/modules/joystick/wrap_JoystickModule.cpp b/src/modules/joystick/wrap_JoystickModule.cpp index 16c34a9ed..d982297a5 100644 --- a/src/modules/joystick/wrap_JoystickModule.cpp +++ b/src/modules/joystick/wrap_JoystickModule.cpp @@ -91,14 +91,14 @@ int w_setGamepadMapping(lua_State *L) switch (jinput.type) { case Joystick::INPUT_TYPE_AXIS: - jinput.axis = (int) luaL_checknumber(L, 4) - 1; + jinput.axis = (int) luaL_checkinteger(L, 4) - 1; break; case Joystick::INPUT_TYPE_BUTTON: - jinput.button = (int) luaL_checknumber(L, 4) - 1; + jinput.button = (int) luaL_checkinteger(L, 4) - 1; break; case Joystick::INPUT_TYPE_HAT: // Hats need both a hat index and a hat value. - jinput.hat.index = (int) luaL_checknumber(L, 4) - 1; + jinput.hat.index = (int) luaL_checkinteger(L, 4) - 1; hatstr = luaL_checkstring(L, 5); if (!Joystick::getConstant(hatstr, jinput.hat.value)) return luaL_error(L, "Invalid joystick hat: %s", hatstr); diff --git a/src/modules/love/love.cpp b/src/modules/love/love.cpp index 1cecb42a9..2cd4f8007 100644 --- a/src/modules/love/love.cpp +++ b/src/modules/love/love.cpp @@ -225,9 +225,9 @@ static int w_love_isVersionCompatible(lua_State *L) version = luaL_checkstring(L, 1); else { - int major = (int) luaL_checknumber(L, 1); - int minor = (int) luaL_checknumber(L, 2); - int rev = (int) luaL_checknumber(L, 3); + int major = (int) luaL_checkinteger(L, 1); + int minor = (int) luaL_checkinteger(L, 2); + int rev = (int) luaL_checkinteger(L, 3); // Convert the numbers to a string, since VERSION_COMPATIBILITY is an // array of version strings. diff --git a/src/modules/math/wrap_BezierCurve.cpp b/src/modules/math/wrap_BezierCurve.cpp index 56953fb48..291d62988 100644 --- a/src/modules/math/wrap_BezierCurve.cpp +++ b/src/modules/math/wrap_BezierCurve.cpp @@ -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 = (int) luaL_checknumber(L, 2); + int idx = (int) luaL_checkinteger(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 = (int) luaL_checknumber(L, 2); + int idx = (int) luaL_checkinteger(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 = (int) luaL_optnumber(L, 4, -1); + int idx = (int) luaL_optinteger(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 = (int) luaL_checknumber(L, 2); + int idx = (int) luaL_checkinteger(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 = (int) luaL_optnumber(L, 2, 5); + int accuracy = (int) luaL_optinteger(L, 2, 5); std::vector points; luax_catchexcept(L, [&](){ points = curve->render(accuracy); }); @@ -196,7 +196,7 @@ int w_BezierCurve_renderSegment(lua_State *L) BezierCurve *curve = luax_checkbeziercurve(L, 1); double start = luaL_checknumber(L, 2); double end = luaL_checknumber(L, 3); - int accuracy = (int) luaL_optnumber(L, 4, 5); + int accuracy = (int) luaL_optinteger(L, 4, 5); std::vector points; luax_catchexcept(L, [&](){ points = curve->renderSegment(start, end, accuracy); }); diff --git a/src/modules/math/wrap_Math.cpp b/src/modules/math/wrap_Math.cpp index 5e7b8d337..6972e838e 100644 --- a/src/modules/math/wrap_Math.cpp +++ b/src/modules/math/wrap_Math.cpp @@ -354,7 +354,7 @@ int w_compress(lua_State *L) if (fstr && !Compressor::getConstant(fstr, format)) return luaL_error(L, "Invalid compressed data format: %s", fstr); - int level = (int) luaL_optnumber(L, 3, -1); + int level = (int) luaL_optinteger(L, 3, -1); CompressedData *cdata = nullptr; if (lua_isstring(L, 1)) diff --git a/src/modules/mouse/wrap_Mouse.cpp b/src/modules/mouse/wrap_Mouse.cpp index c76ee5266..c94fd2de5 100644 --- a/src/modules/mouse/wrap_Mouse.cpp +++ b/src/modules/mouse/wrap_Mouse.cpp @@ -41,8 +41,8 @@ int w_newCursor(lua_State *L) luax_convobj(L, 1, "image", "newImageData"); love::image::ImageData *data = luax_checktype(L, 1); - int hotx = (int) luaL_optnumber(L, 2, 0); - int hoty = (int) luaL_optnumber(L, 3, 0); + int hotx = (int) luaL_optinteger(L, 2, 0); + int hoty = (int) luaL_optinteger(L, 3, 0); luax_catchexcept(L, [&](){ cursor = instance()->newCursor(data, hotx, hoty); }); @@ -154,14 +154,14 @@ int w_isDown(lua_State *L) for (int i = 0; i < num; i++) { lua_rawgeti(L, 1, i + 1); - buttons.push_back((int) luaL_checknumber(L, -1)); + buttons.push_back((int) luaL_checkinteger(L, -1)); lua_pop(L, 1); } } else { for (int i = 0; i < num; i++) - buttons.push_back((int) luaL_checknumber(L, i + 1)); + buttons.push_back((int) luaL_checkinteger(L, i + 1)); } luax_pushboolean(L, instance()->isDown(buttons)); diff --git a/src/modules/physics/box2d/Fixture.cpp b/src/modules/physics/box2d/Fixture.cpp index 2fba43f25..343646b91 100644 --- a/src/modules/physics/box2d/Fixture.cpp +++ b/src/modules/physics/box2d/Fixture.cpp @@ -280,7 +280,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_optnumber(L, 6, 1) - 1; // Convert from 1-based index + int childIndex = (int) luaL_optinteger(L, 6, 1) - 1; // Convert from 1-based index b2RayCastInput input; input.p1.Set(p1x, p1y); input.p2.Set(p2x, p2y); @@ -296,7 +296,7 @@ int Fixture::rayCast(lua_State *L) const int Fixture::getBoundingBox(lua_State *L) const { - int childIndex = (int) luaL_optnumber(L, 1, 1) - 1; // Convert from 1-based index + int childIndex = (int) luaL_optinteger(L, 1, 1) - 1; // Convert from 1-based index b2AABB box; luax_catchexcept(L, [&]() { box = fixture->GetAABB(childIndex); }); box = Physics::scaleUp(box); diff --git a/src/modules/physics/box2d/Physics.cpp b/src/modules/physics/box2d/Physics.cpp index 91d09bbd7..cddfe2eb9 100644 --- a/src/modules/physics/box2d/Physics.cpp +++ b/src/modules/physics/box2d/Physics.cpp @@ -31,7 +31,7 @@ namespace physics namespace box2d { -int Physics::meter = Physics::DEFAULT_METER; +float Physics::meter = Physics::DEFAULT_METER; const char *Physics::getName() const { @@ -323,37 +323,37 @@ int Physics::getDistance(lua_State *L) return 5; } -void Physics::setMeter(int scale) +void Physics::setMeter(float scale) { if (scale < 1) throw love::Exception("Physics error: invalid meter"); Physics::meter = scale; } -int Physics::getMeter() +float Physics::getMeter() { return meter; } void Physics::scaleDown(float &x, float &y) { - x /= (float)meter; - y /= (float)meter; + x /= meter; + y /= meter; } void Physics::scaleUp(float &x, float &y) { - x *= (float)meter; - y *= (float)meter; + x *= meter; + y *= meter; } float Physics::scaleDown(float f) { - return f/(float)meter; + return f/meter; } float Physics::scaleUp(float f) { - return f*(float)meter; + return f*meter; } b2Vec2 Physics::scaleDown(const b2Vec2 &v) diff --git a/src/modules/physics/box2d/Physics.h b/src/modules/physics/box2d/Physics.h index 996a2d8e5..62e256031 100644 --- a/src/modules/physics/box2d/Physics.h +++ b/src/modules/physics/box2d/Physics.h @@ -292,13 +292,13 @@ public: * Sets the number of pixels in one meter. * @param scale The number of pixels in one meter. (1m ~= 3.3ft). **/ - static void setMeter(int scale); + static void setMeter(float scale); /** * Gets the number of pixels in one meter. * @return The number of pixels in one meter. (1m ~= 3.3ft). **/ - static int getMeter(); + static float getMeter(); /** * Scales a value down according to the current meter in pixels. @@ -359,7 +359,7 @@ public: private: // The length of one meter in pixels. - static int meter; + static float meter; }; // Physics } // box2d diff --git a/src/modules/physics/box2d/Shape.cpp b/src/modules/physics/box2d/Shape.cpp index da6ff272a..84d41e9b4 100644 --- a/src/modules/physics/box2d/Shape.cpp +++ b/src/modules/physics/box2d/Shape.cpp @@ -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_optnumber(L, 9, 1) - 1; // Convert from 1-based index + int childIndex = (int) luaL_optinteger(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_optnumber(L, 4, 1) - 1; // Convert from 1-based index + int childIndex = (int) luaL_optinteger(L, 4, 1) - 1; // Convert from 1-based index b2Transform transform(b2Vec2(x, y), b2Rot(r)); b2AABB box; shape->ComputeAABB(&box, transform, childIndex); diff --git a/src/modules/physics/box2d/wrap_ChainShape.cpp b/src/modules/physics/box2d/wrap_ChainShape.cpp index c4ec96497..0bfbfdba9 100644 --- a/src/modules/physics/box2d/wrap_ChainShape.cpp +++ b/src/modules/physics/box2d/wrap_ChainShape.cpp @@ -65,7 +65,7 @@ int w_ChainShape_setPreviousVertex(lua_State *L) int w_ChainShape_getChildEdge(lua_State *L) { ChainShape *c = luax_checkchainshape(L, 1); - int index = (int) luaL_checknumber(L, 2) - 1; // Convert from 1-based index + int index = (int) luaL_checkinteger(L, 2) - 1; // Convert from 1-based index EdgeShape *e = 0; luax_catchexcept(L, [&](){ e = c->getChildEdge(index); }); luax_pushtype(L, e); @@ -84,7 +84,7 @@ int w_ChainShape_getVertexCount(lua_State *L) int w_ChainShape_getPoint(lua_State *L) { ChainShape *c = luax_checkchainshape(L, 1); - int index = (int) luaL_checknumber(L, 2) - 1; // Convert from 1-based index + int index = (int) luaL_checkinteger(L, 2) - 1; // Convert from 1-based index b2Vec2 v; luax_catchexcept(L, [&](){ v = c->getPoint(index); }); lua_pushnumber(L, v.x); diff --git a/src/modules/physics/box2d/wrap_Fixture.cpp b/src/modules/physics/box2d/wrap_Fixture.cpp index 6107d36dc..bfa6efbae 100644 --- a/src/modules/physics/box2d/wrap_Fixture.cpp +++ b/src/modules/physics/box2d/wrap_Fixture.cpp @@ -164,9 +164,9 @@ int w_Fixture_setFilterData(lua_State *L) { Fixture *t = luax_checkfixture(L, 1); int v[3]; - v[0] = (int) luaL_checknumber(L, 2); - v[1] = (int) luaL_checknumber(L, 3); - v[2] = (int) luaL_checknumber(L, 4); + v[0] = (int) luaL_checkinteger(L, 2); + v[1] = (int) luaL_checkinteger(L, 3); + v[2] = (int) luaL_checkinteger(L, 4); t->setFilterData(v); return 0; } @@ -249,7 +249,7 @@ int w_Fixture_getGroupIndex(lua_State *L) int w_Fixture_setGroupIndex(lua_State *L) { Fixture *t = luax_checkfixture(L, 1); - int i = (int) luaL_checknumber(L, 2); + int i = (int) luaL_checkinteger(L, 2); t->setGroupIndex(i); return 0; } diff --git a/src/modules/physics/box2d/wrap_Physics.cpp b/src/modules/physics/box2d/wrap_Physics.cpp index 7408d1d97..0513d43fa 100644 --- a/src/modules/physics/box2d/wrap_Physics.cpp +++ b/src/modules/physics/box2d/wrap_Physics.cpp @@ -471,7 +471,7 @@ int w_getDistance(lua_State *L) int w_setMeter(lua_State *L) { - int arg1 = (int) luaL_checknumber(L, 1); + float arg1 = (float) luaL_checknumber(L, 1); luax_catchexcept(L, [&](){ Physics::setMeter(arg1); }); return 0; diff --git a/src/modules/physics/box2d/wrap_World.cpp b/src/modules/physics/box2d/wrap_World.cpp index ef0184387..ef29143a8 100644 --- a/src/modules/physics/box2d/wrap_World.cpp +++ b/src/modules/physics/box2d/wrap_World.cpp @@ -47,8 +47,8 @@ int w_World_update(lua_State *L) luax_catchexcept(L, [&](){ t->update(dt); }); else { - int velocityiterations = (int) luaL_checknumber(L, 3); - int positioniterations = (int) luaL_checknumber(L, 4); + int velocityiterations = (int) luaL_checkinteger(L, 3); + int positioniterations = (int) luaL_checkinteger(L, 4); luax_catchexcept(L, [&](){ t->update(dt, velocityiterations, positioniterations); }); } diff --git a/src/modules/sound/wrap_Sound.cpp b/src/modules/sound/wrap_Sound.cpp index 7d114f2a2..49a13e865 100644 --- a/src/modules/sound/wrap_Sound.cpp +++ b/src/modules/sound/wrap_Sound.cpp @@ -35,7 +35,7 @@ namespace sound int w_newDecoder(lua_State *L) { love::filesystem::FileData *data = love::filesystem::luax_getfiledata(L, 1); - int bufferSize = (int) luaL_optnumber(L, 2, Decoder::DEFAULT_BUFFER_SIZE); + int bufferSize = (int) luaL_optinteger(L, 2, Decoder::DEFAULT_BUFFER_SIZE); Decoder *t = nullptr; luax_catchexcept(L, @@ -57,10 +57,10 @@ int w_newSoundData(lua_State *L) if (lua_isnumber(L, 1)) { - 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); + int samples = (int) luaL_checkinteger(L, 1); + int sampleRate = (int) luaL_optinteger(L, 2, Decoder::DEFAULT_SAMPLE_RATE); + int bitDepth = (int) luaL_optinteger(L, 3, Decoder::DEFAULT_BIT_DEPTH); + int channels = (int) luaL_optinteger(L, 4, Decoder::DEFAULT_CHANNELS); luax_catchexcept(L, [&](){ t = instance()->newSoundData(samples, sampleRate, bitDepth, channels); }); } diff --git a/src/modules/window/wrap_Window.cpp b/src/modules/window/wrap_Window.cpp index 52d8c8165..843f512d5 100644 --- a/src/modules/window/wrap_Window.cpp +++ b/src/modules/window/wrap_Window.cpp @@ -36,7 +36,7 @@ int w_getDisplayCount(lua_State *L) int w_getDisplayName(lua_State *L) { - int index = (int) luaL_checknumber(L, 1) - 1; + int index = (int) luaL_checkinteger(L, 1) - 1; const char *name = nullptr; luax_catchexcept(L, [&](){ name = instance()->getDisplayName(index); }); @@ -105,8 +105,8 @@ static int readWindowSettings(lua_State *L, int idx, WindowSettings &settings) settings.useposition = !(lua_isnoneornil(L, -2) && lua_isnoneornil(L, -1)); if (settings.useposition) { - settings.x = (int) luaL_optnumber(L, -2, 0); - settings.y = (int) luaL_optnumber(L, -1, 0); + settings.x = (int) luaL_optinteger(L, -2, 0); + settings.y = (int) luaL_optinteger(L, -1, 0); } lua_pop(L, 2); @@ -116,8 +116,8 @@ static int readWindowSettings(lua_State *L, int idx, WindowSettings &settings) int w_setMode(lua_State *L) { - int w = (int) luaL_checknumber(L, 1); - int h = (int) luaL_checknumber(L, 2); + int w = (int) luaL_checkinteger(L, 1); + int h = (int) luaL_checkinteger(L, 2); if (lua_isnoneornil(L, 3)) { @@ -150,8 +150,8 @@ int w_updateMode(lua_State *L) if (lua_isnumber(L, 1)) { idx = 3; - w = (int) luaL_checknumber(L, 1); - h = (int) luaL_checknumber(L, 2); + w = (int) luaL_checkinteger(L, 1); + h = (int) luaL_checkinteger(L, 2); } if (!lua_isnoneornil(L, idx)) @@ -232,7 +232,7 @@ int w_getFullscreenModes(lua_State *L) { int displayindex = 0; if (!lua_isnoneornil(L, 1)) - displayindex = (int) luaL_checknumber(L, 1) - 1; + displayindex = (int) luaL_checkinteger(L, 1) - 1; else { int x, y; @@ -317,7 +317,7 @@ int w_getDesktopDimensions(lua_State *L) int width = 0, height = 0; int displayindex = 0; if (!lua_isnoneornil(L, 1)) - displayindex = (int) luaL_checknumber(L, 1) - 1; + displayindex = (int) luaL_checkinteger(L, 1) - 1; else { int x, y; @@ -331,12 +331,12 @@ int w_getDesktopDimensions(lua_State *L) int w_setPosition(lua_State *L) { - int x = (int) luaL_checknumber(L, 1); - int y = (int) luaL_checknumber(L, 2); + int x = (int) luaL_checkinteger(L, 1); + int y = (int) luaL_checkinteger(L, 2); int displayindex = 0; if (!lua_isnoneornil(L, 3)) - displayindex = (int) luaL_checknumber(L, 3) - 1; + displayindex = (int) luaL_checkinteger(L, 3) - 1; else { int x_unused, y_unused; @@ -509,7 +509,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 = (int) luaL_checknumber(L, -1) - 1; + data.enterButtonIndex = (int) luaL_checkinteger(L, -1) - 1; else data.enterButtonIndex = 0; lua_pop(L, 1); @@ -517,7 +517,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 = (int) luaL_checknumber(L, -1) - 1; + data.escapeButtonIndex = (int) luaL_checkinteger(L, -1) - 1; else data.escapeButtonIndex = (int) data.buttons.size() - 1; lua_pop(L, 1);