mirror of
https://github.com/love2d/love.git
synced 2026-08-16 16:20:42 +02:00
Automatically deduce the type in luax_checktype, luax_getmodule, luax_optmodule and luax_totype
--HG-- branch : dynamiccore2
This commit is contained in:
@@ -30,7 +30,7 @@ namespace opengl
|
||||
|
||||
Canvas *luax_checkcanvas(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<Canvas>(L, idx, Canvas::type);
|
||||
return luax_checktype<Canvas>(L, idx);
|
||||
}
|
||||
|
||||
int w_Canvas_renderTo(lua_State *L)
|
||||
@@ -68,7 +68,7 @@ int w_Canvas_renderTo(lua_State *L)
|
||||
int w_Canvas_newImageData(lua_State *L)
|
||||
{
|
||||
Canvas *canvas = luax_checkcanvas(L, 1);
|
||||
love::image::Image *image = luax_getmodule<love::image::Image>(L, love::image::Image::type);
|
||||
love::image::Image *image = luax_getmodule<love::image::Image>(L);
|
||||
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());
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace opengl
|
||||
|
||||
Font *luax_checkfont(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<Font>(L, idx, Font::type);
|
||||
return luax_checktype<Font>(L, idx);
|
||||
}
|
||||
|
||||
int w_Font_getHeight(lua_State *L)
|
||||
|
||||
@@ -442,7 +442,7 @@ int w_newFont(lua_State *L)
|
||||
luax_convobj(L, &idxs[0], (int) idxs.size(), "font", "newRasterizer");
|
||||
}
|
||||
|
||||
love::font::Rasterizer *rasterizer = luax_checktype<love::font::Rasterizer>(L, 1, love::font::Rasterizer::type);
|
||||
love::font::Rasterizer *rasterizer = luax_checktype<love::font::Rasterizer>(L, 1);
|
||||
|
||||
luax_catchexcept(L, [&]() {
|
||||
font = instance()->newFont(rasterizer, instance()->getDefaultFilter()); }
|
||||
@@ -464,7 +464,7 @@ int w_newImageFont(lua_State *L)
|
||||
// Convert to ImageData if necessary.
|
||||
if (luax_istype(L, 1, Image::type))
|
||||
{
|
||||
Image *i = luax_checktype<Image>(L, 1, Image::type);
|
||||
Image *i = luax_checktype<Image>(L, 1);
|
||||
filter = i->getFilter();
|
||||
const auto &idlevels = i->getImageData();
|
||||
if (idlevels.empty())
|
||||
@@ -485,7 +485,7 @@ int w_newImageFont(lua_State *L)
|
||||
luax_convobj(L, &idxs[0], (int) idxs.size(), "font", "newImageRasterizer");
|
||||
}
|
||||
|
||||
love::font::Rasterizer *rasterizer = luax_checktype<love::font::Rasterizer>(L, 1, love::font::Rasterizer::type);
|
||||
love::font::Rasterizer *rasterizer = luax_checktype<love::font::Rasterizer>(L, 1);
|
||||
|
||||
// Create the font.
|
||||
Font *font = instance()->newFont(rasterizer, filter);
|
||||
@@ -806,7 +806,7 @@ static Mesh *newCustomMesh(lua_State *L)
|
||||
else if (luax_istype(L, 2, Data::type))
|
||||
{
|
||||
// Vertex data comes directly from a Data object.
|
||||
Data *data = luax_checktype<Data>(L, 2, Data::type);
|
||||
Data *data = luax_checktype<Data>(L, 2);
|
||||
luax_catchexcept(L, [&](){ t = instance()->newMesh(vertexformat, data->getData(), data->getSize(), drawmode, usage); });
|
||||
}
|
||||
else
|
||||
@@ -920,7 +920,7 @@ int w_newVideo(lua_State *L)
|
||||
if (!luax_istype(L, 1, love::video::VideoStream::type))
|
||||
luax_convobj(L, 1, "video", "newVideoStream");
|
||||
|
||||
auto stream = luax_checktype<love::video::VideoStream>(L, 1, love::video::VideoStream::type);
|
||||
auto stream = luax_checktype<love::video::VideoStream>(L, 1);
|
||||
Video *video = nullptr;
|
||||
|
||||
luax_catchexcept(L, [&]() { video = instance()->newVideo(stream); });
|
||||
@@ -1004,14 +1004,14 @@ int w_getBackgroundColor(lua_State *L)
|
||||
int w_setNewFont(lua_State *L)
|
||||
{
|
||||
int ret = w_newFont(L);
|
||||
Font *font = luax_checktype<Font>(L, -1, Font::type);
|
||||
Font *font = luax_checktype<Font>(L, -1);
|
||||
instance()->setFont(font);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int w_setFont(lua_State *L)
|
||||
{
|
||||
Font *font = luax_checktype<Font>(L, 1, Font::type);
|
||||
Font *font = luax_checktype<Font>(L, 1);
|
||||
instance()->setFont(font);
|
||||
return 0;
|
||||
}
|
||||
@@ -1248,7 +1248,7 @@ int w_isWireframe(lua_State *L)
|
||||
|
||||
int w_newScreenshot(lua_State *L)
|
||||
{
|
||||
love::image::Image *image = luax_getmodule<love::image::Image>(L, love::image::Image::type);
|
||||
love::image::Image *image = luax_getmodule<love::image::Image>(L);
|
||||
bool copyAlpha = luax_optboolean(L, 1, false);
|
||||
love::image::ImageData *i = 0;
|
||||
|
||||
@@ -1528,7 +1528,7 @@ int w_draw(lua_State *L)
|
||||
if (luax_istype(L, 2, Quad::type))
|
||||
{
|
||||
texture = luax_checktexture(L, 1);
|
||||
quad = luax_totype<Quad>(L, 2, Quad::type);
|
||||
quad = luax_totype<Quad>(L, 2);
|
||||
startidx = 3;
|
||||
}
|
||||
else if (lua_isnil(L, 2) && !lua_isnoneornil(L, 3))
|
||||
@@ -1537,7 +1537,7 @@ int w_draw(lua_State *L)
|
||||
}
|
||||
else
|
||||
{
|
||||
drawable = luax_checktype<Drawable>(L, 1, Drawable::type);
|
||||
drawable = luax_checktype<Drawable>(L, 1);
|
||||
startidx = 2;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace opengl
|
||||
|
||||
Image *luax_checkimage(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<Image>(L, idx, Image::type);
|
||||
return luax_checktype<Image>(L, idx);
|
||||
}
|
||||
|
||||
int w_Image_setMipmapFilter(lua_State *L)
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace opengl
|
||||
|
||||
Mesh *luax_checkmesh(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<Mesh>(L, idx, Mesh::type);
|
||||
return luax_checktype<Mesh>(L, idx);
|
||||
}
|
||||
|
||||
static inline size_t writeByteData(lua_State *L, int startidx, int components, char *data)
|
||||
@@ -119,7 +119,7 @@ int w_Mesh_setVertices(lua_State *L)
|
||||
|
||||
if (luax_istype(L, 2, Data::type))
|
||||
{
|
||||
Data *d = luax_checktype<Data>(L, 2, Data::type);
|
||||
Data *d = luax_checktype<Data>(L, 2);
|
||||
|
||||
size_t datasize = std::min(d->getSize(), (t->getVertexCount() - vertoffset) * stride);
|
||||
char *bytedata = (char *) t->mapVertexData() + byteoffset;
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace opengl
|
||||
|
||||
ParticleSystem *luax_checkparticlesystem(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<ParticleSystem>(L, idx, ParticleSystem::type);
|
||||
return luax_checktype<ParticleSystem>(L, idx);
|
||||
}
|
||||
|
||||
int w_ParticleSystem_clone(lua_State *L)
|
||||
@@ -584,7 +584,7 @@ int w_ParticleSystem_setQuads(lua_State *L)
|
||||
{
|
||||
lua_rawgeti(L, 2, i);
|
||||
|
||||
Quad *q = luax_checktype<Quad>(L, -1, Quad::type);
|
||||
Quad *q = luax_checktype<Quad>(L, -1);
|
||||
quads.push_back(q);
|
||||
|
||||
lua_pop(L, 1);
|
||||
@@ -594,7 +594,7 @@ int w_ParticleSystem_setQuads(lua_State *L)
|
||||
{
|
||||
for (int i = 2; i <= lua_gettop(L); i++)
|
||||
{
|
||||
Quad *q = luax_checktype<Quad>(L, i, Quad::type);
|
||||
Quad *q = luax_checktype<Quad>(L, i);
|
||||
quads.push_back(q);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace opengl
|
||||
|
||||
Shader *luax_checkshader(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<Shader>(L, idx, Shader::type);
|
||||
return luax_checktype<Shader>(L, idx);
|
||||
}
|
||||
|
||||
int w_Shader_getWarnings(lua_State *L)
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace opengl
|
||||
|
||||
SpriteBatch *luax_checkspritebatch(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<SpriteBatch>(L, idx, SpriteBatch::type);
|
||||
return luax_checktype<SpriteBatch>(L, idx);
|
||||
}
|
||||
|
||||
static inline int w_SpriteBatch_add_or_set(lua_State *L, SpriteBatch *t, int startidx, int index)
|
||||
@@ -45,7 +45,7 @@ static inline int w_SpriteBatch_add_or_set(lua_State *L, SpriteBatch *t, int sta
|
||||
|
||||
if (luax_istype(L, startidx, Quad::type))
|
||||
{
|
||||
quad = luax_totype<Quad>(L, startidx, Quad::type);
|
||||
quad = luax_totype<Quad>(L, startidx);
|
||||
startidx++;
|
||||
}
|
||||
else if (lua_isnil(L, startidx) && !lua_isnoneornil(L, startidx + 1))
|
||||
@@ -201,7 +201,7 @@ int w_SpriteBatch_attachAttribute(lua_State *L)
|
||||
{
|
||||
SpriteBatch *t = luax_checkspritebatch(L, 1);
|
||||
const char *name = luaL_checkstring(L, 2);
|
||||
Mesh *m = luax_checktype<Mesh>(L, 3, Mesh::type);
|
||||
Mesh *m = luax_checktype<Mesh>(L, 3);
|
||||
|
||||
luax_catchexcept(L, [&](){ t->attachAttribute(name, m); });
|
||||
return 0;
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace opengl
|
||||
|
||||
Text *luax_checktext(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<Text>(L, idx, Text::type);
|
||||
return luax_checktype<Text>(L, idx);
|
||||
}
|
||||
|
||||
void luax_checkcoloredstring(lua_State *L, int idx, std::vector<Font::ColoredString> &strings)
|
||||
@@ -190,7 +190,7 @@ int w_Text_clear(lua_State *L)
|
||||
int w_Text_setFont(lua_State *L)
|
||||
{
|
||||
Text *t = luax_checktext(L, 1);
|
||||
Font *f = luax_checktype<Font>(L, 2, Font::type);
|
||||
Font *f = luax_checktype<Font>(L, 2);
|
||||
luax_catchexcept(L, [&](){ t->setFont(f); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace opengl
|
||||
|
||||
Video *luax_checkvideo(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<Video>(L, idx, Video::type);
|
||||
return luax_checktype<Video>(L, idx);
|
||||
}
|
||||
|
||||
int w_Video_getStream(lua_State *L)
|
||||
@@ -62,7 +62,7 @@ int w_Video_setSource(lua_State *L)
|
||||
video->setSource(nullptr);
|
||||
else
|
||||
{
|
||||
auto source = luax_checktype<love::audio::Source>(L, 2, love::audio::Source::type);
|
||||
auto source = luax_checktype<love::audio::Source>(L, 2);
|
||||
video->setSource(source);
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace graphics
|
||||
|
||||
Quad *luax_checkquad(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<Quad>(L, idx, Quad::type);
|
||||
return luax_checktype<Quad>(L, idx);
|
||||
}
|
||||
|
||||
int w_Quad_setViewport(lua_State *L)
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace graphics
|
||||
|
||||
Texture *luax_checktexture(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<Texture>(L, idx, Texture::type);
|
||||
return luax_checktype<Texture>(L, idx);
|
||||
}
|
||||
|
||||
int w_Texture_getWidth(lua_State *L)
|
||||
|
||||
Reference in New Issue
Block a user