mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Replaced luax_newtype with luax_pushtype (and added luax_rawnewtype for the old functionality of luax_newtype.)
luax_pushtype keeps the object in a weak table and checks the table before creating a new userdata, so it re-uses the object's existing wrapper userdata if it can, whenever the object is pushed to Lua. This fixes some subtle issues with love objects, where using them as keys in tables would not always work as expected (https://love2d.org/forums/viewtopic.php?f=4&t=39398&p=112388#p112415). It also decreases the amount of new Lua objects created, saving the garbage collector some work.
This commit is contained in:
@@ -65,7 +65,7 @@ int w_newSource(lua_State *L)
|
||||
|
||||
if (t)
|
||||
{
|
||||
luax_newtype(L, "Source", AUDIO_SOURCE_T, (void *)t);
|
||||
luax_pushtype(L, "Source", AUDIO_SOURCE_T, t);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
@@ -227,7 +227,7 @@ int w_getRecordedData(lua_State *L)
|
||||
if (!sd)
|
||||
lua_pushnil(L);
|
||||
else
|
||||
luax_newtype(L, "SoundData", SOUND_SOUND_DATA_T, (void *)sd);
|
||||
luax_pushtype(L, "SoundData", SOUND_SOUND_DATA_T, sd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ int w_stopRecording(lua_State *L)
|
||||
{
|
||||
love::sound::SoundData *sd = instance->stopRecording(true);
|
||||
if (!sd) lua_pushnil(L);
|
||||
else luax_newtype(L, "SoundData", SOUND_SOUND_DATA_T, (void *)sd);
|
||||
else luax_pushtype(L, "SoundData", SOUND_SOUND_DATA_T, sd);
|
||||
return 1;
|
||||
}
|
||||
instance->stopRecording(false);
|
||||
|
||||
@@ -170,7 +170,7 @@ int w_newFile(lua_State *L)
|
||||
}
|
||||
}
|
||||
|
||||
luax_newtype(L, "File", FILESYSTEM_FILE_T, (void *)t);
|
||||
luax_pushtype(L, "File", FILESYSTEM_FILE_T, t);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ int w_newFileData(lua_State *L)
|
||||
{
|
||||
return ioError(L, "%s", e.what());
|
||||
}
|
||||
luax_newtype(L, "FileData", FILESYSTEM_FILE_DATA_T, (void *) data);
|
||||
luax_pushtype(L, "FileData", FILESYSTEM_FILE_DATA_T, data);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
@@ -227,7 +227,7 @@ int w_newFileData(lua_State *L)
|
||||
return luaL_error(L, "Invalid FileData decoder: %s", decstr);
|
||||
}
|
||||
|
||||
luax_newtype(L, "FileData", FILESYSTEM_FILE_DATA_T, (void *)t);
|
||||
luax_pushtype(L, "FileData", FILESYSTEM_FILE_DATA_T, t);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -395,7 +395,7 @@ int w_lines(lua_State *L)
|
||||
{
|
||||
return luaL_error(L, "%s", e.what());
|
||||
}
|
||||
luax_newtype(L, "File", FILESYSTEM_FILE_T, file);
|
||||
luax_pushtype(L, "File", FILESYSTEM_FILE_T, file);
|
||||
}
|
||||
else
|
||||
return luaL_error(L, "Expected filename.");
|
||||
|
||||
@@ -64,7 +64,7 @@ int w_newRasterizer(lua_State *L)
|
||||
return luaL_error(L, "%s", e.what());
|
||||
}
|
||||
|
||||
luax_newtype(L, "Rasterizer", FONT_RASTERIZER_T, t);
|
||||
luax_pushtype(L, "Rasterizer", FONT_RASTERIZER_T, t);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ int w_newGlyphData(lua_State *L)
|
||||
t = instance->newGlyphData(r, g);
|
||||
}
|
||||
|
||||
luax_newtype(L, "GlyphData", FONT_GLYPH_DATA_T, t);
|
||||
luax_pushtype(L, "GlyphData", FONT_GLYPH_DATA_T, t);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ int w_Rasterizer_getGlyphData(lua_State *L)
|
||||
return luaL_error(L, "%s", e.what());
|
||||
}
|
||||
|
||||
luax_newtype(L, "GlyphData", FONT_GLYPH_DATA_T, (void *) g);
|
||||
luax_pushtype(L, "GlyphData", FONT_GLYPH_DATA_T, g);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ int w_Canvas_getImageData(lua_State *L)
|
||||
Canvas *canvas = luax_checkcanvas(L, 1);
|
||||
love::image::Image *image = luax_getmodule<love::image::Image>(L, "image", MODULE_IMAGE_T);
|
||||
love::image::ImageData *img = canvas->getImageData(image);
|
||||
luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void *)img);
|
||||
luax_pushtype(L, "ImageData", IMAGE_IMAGE_DATA_T, img);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -195,7 +195,7 @@ int w_newImage(lua_State *L)
|
||||
|
||||
|
||||
// Push the type.
|
||||
luax_newtype(L, "Image", GRAPHICS_IMAGE_T, (void *)image);
|
||||
luax_pushtype(L, "Image", GRAPHICS_IMAGE_T, image);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -335,7 +335,9 @@ int w_newGeometry(lua_State *L)
|
||||
|
||||
geom->setVertexColors(hasvertexcolors);
|
||||
|
||||
luax_newtype(L, "Geometry", GRAPHICS_GEOMETRY_T, (void *) geom);
|
||||
// Note: This should be changed to luax_pushtype if the new Geometry is ever
|
||||
// expected to be pushed to Lua from another C++ function!
|
||||
luax_rawnewtype(L, "Geometry", GRAPHICS_GEOMETRY_T, geom);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -350,7 +352,9 @@ int w_newQuad(lua_State *L)
|
||||
|
||||
Geometry *quad = instance->newQuad(x, y, w, h, sw, sh);
|
||||
|
||||
luax_newtype(L, "Geometry", GRAPHICS_GEOMETRY_T, (void *)quad);
|
||||
// Note: This should be changed to luax_pushtype if the new Geometry is ever
|
||||
// expected to be pushed to Lua from another C++ function!
|
||||
luax_rawnewtype(L, "Geometry", GRAPHICS_GEOMETRY_T, quad);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -384,7 +388,7 @@ int w_newFont(lua_State *L)
|
||||
return luaL_error(L, "Could not load font.");
|
||||
|
||||
// Push the type.
|
||||
luax_newtype(L, "Font", GRAPHICS_FONT_T, (void *)font);
|
||||
luax_pushtype(L, "Font", GRAPHICS_FONT_T, font);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -404,7 +408,7 @@ int w_newImageFont(lua_State *L)
|
||||
love::image::ImageData *id = i->getImageData();
|
||||
if (!id)
|
||||
return luaL_argerror(L, 1, "Image cannot be compressed.");
|
||||
luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void *)id, false);
|
||||
luax_pushtype(L, "ImageData", IMAGE_IMAGE_DATA_T, id, false);
|
||||
lua_replace(L, 1);
|
||||
}
|
||||
|
||||
@@ -424,7 +428,7 @@ int w_newImageFont(lua_State *L)
|
||||
return luaL_error(L, "Could not load font.");
|
||||
|
||||
// Push the type.
|
||||
luax_newtype(L, "Font", GRAPHICS_FONT_T, (void *)font);
|
||||
luax_pushtype(L, "Font", GRAPHICS_FONT_T, font);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -449,7 +453,7 @@ int w_newSpriteBatch(lua_State *L)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
luax_newtype(L, "SpriteBatch", GRAPHICS_SPRITE_BATCH_T, (void *)t);
|
||||
luax_pushtype(L, "SpriteBatch", GRAPHICS_SPRITE_BATCH_T, t);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -468,7 +472,7 @@ int w_newParticleSystem(lua_State *L)
|
||||
{
|
||||
return luaL_error(L, "%s", e.what());
|
||||
}
|
||||
luax_newtype(L, "ParticleSystem", GRAPHICS_PARTICLE_SYSTEM_T, (void *) t);
|
||||
luax_pushtype(L, "ParticleSystem", GRAPHICS_PARTICLE_SYSTEM_T, t);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -496,7 +500,7 @@ int w_newCanvas(lua_State *L)
|
||||
if (NULL == canvas)
|
||||
return luaL_error(L, "Canvas not created, but no error thrown. I don't even...");
|
||||
|
||||
luax_newtype(L, "Canvas", GRAPHICS_CANVAS_T, (void *)canvas);
|
||||
luax_pushtype(L, "Canvas", GRAPHICS_CANVAS_T, canvas);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -581,7 +585,7 @@ int w_newShader(lua_State *L)
|
||||
try
|
||||
{
|
||||
Shader *shader = instance->newShader(sources);
|
||||
luax_newtype(L, "Shader", GRAPHICS_SHADER_T, (void *)shader);
|
||||
luax_pushtype(L, "Shader", GRAPHICS_SHADER_T, shader);
|
||||
}
|
||||
catch (const love::Exception &e)
|
||||
{
|
||||
@@ -683,7 +687,7 @@ int w_getFont(lua_State *L)
|
||||
return 0;
|
||||
|
||||
f->retain();
|
||||
luax_newtype(L, "Font", GRAPHICS_FONT_T, (void *)f);
|
||||
luax_pushtype(L, "Font", GRAPHICS_FONT_T, f);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -937,7 +941,7 @@ int w_newScreenshot(lua_State *L)
|
||||
{
|
||||
return luaL_error(L, "%s", e.what());
|
||||
}
|
||||
luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void *)i);
|
||||
luax_pushtype(L, "ImageData", IMAGE_IMAGE_DATA_T, i);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1002,13 +1006,13 @@ int w_getCanvas(lua_State *L)
|
||||
if (canvas)
|
||||
{
|
||||
canvas->retain();
|
||||
luax_newtype(L, "Canvas", GRAPHICS_CANVAS_T, (void *) canvas);
|
||||
luax_pushtype(L, "Canvas", GRAPHICS_CANVAS_T, canvas);
|
||||
|
||||
const std::vector<Canvas *> &attachments = canvas->getAttachedCanvases();
|
||||
for (size_t i = 0; i < attachments.size(); i++)
|
||||
{
|
||||
attachments[i]->retain();
|
||||
luax_newtype(L, "Canvas", GRAPHICS_CANVAS_T, (void *) attachments[i]);
|
||||
luax_pushtype(L, "Canvas", GRAPHICS_CANVAS_T, attachments[i]);
|
||||
n++;
|
||||
}
|
||||
}
|
||||
@@ -1037,7 +1041,7 @@ int w_getShader(lua_State *L)
|
||||
if (shader)
|
||||
{
|
||||
shader->retain();
|
||||
luax_newtype(L, "Shader", GRAPHICS_SHADER_T, (void *) shader);
|
||||
luax_pushtype(L, "Shader", GRAPHICS_SHADER_T, shader);
|
||||
}
|
||||
else
|
||||
lua_pushnil(L);
|
||||
|
||||
@@ -206,7 +206,7 @@ int w_Image_getData(lua_State *L)
|
||||
if (t)
|
||||
{
|
||||
t->retain();
|
||||
luax_newtype(L, "CompressedData", IMAGE_COMPRESSED_DATA_T, (void *) t);
|
||||
luax_pushtype(L, "CompressedData", IMAGE_COMPRESSED_DATA_T, t);
|
||||
}
|
||||
else
|
||||
lua_pushnil(L);
|
||||
@@ -217,7 +217,7 @@ int w_Image_getData(lua_State *L)
|
||||
if (t)
|
||||
{
|
||||
t->retain();
|
||||
luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void *) t);
|
||||
luax_pushtype(L, "ImageData", IMAGE_IMAGE_DATA_T, t);
|
||||
}
|
||||
else
|
||||
lua_pushnil(L);
|
||||
|
||||
@@ -49,7 +49,7 @@ int w_ParticleSystem_getImage(lua_State *L)
|
||||
ParticleSystem *t = luax_checkparticlesystem(L, 1);
|
||||
Image *i = t->getImage();
|
||||
i->retain();
|
||||
luax_newtype(L, "Image", GRAPHICS_IMAGE_T, (void *) i);
|
||||
luax_pushtype(L, "Image", GRAPHICS_IMAGE_T, i);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -152,7 +152,7 @@ int w_SpriteBatch_getImage(lua_State *L)
|
||||
SpriteBatch *t = luax_checkspritebatch(L, 1);
|
||||
Image *image = t->getImage();
|
||||
image->retain();
|
||||
luax_newtype(L, "Image", GRAPHICS_IMAGE_T, (void *)image);
|
||||
luax_pushtype(L, "Image", GRAPHICS_IMAGE_T, image);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ int w_newImageData(lua_State *L)
|
||||
{
|
||||
return luaL_error(L, "%s", e.what());
|
||||
}
|
||||
luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void *)t);
|
||||
luax_pushtype(L, "ImageData", IMAGE_IMAGE_DATA_T, t);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ int w_newImageData(lua_State *L)
|
||||
return luaL_error(L, "%s", e.what());
|
||||
}
|
||||
|
||||
luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void *) t);
|
||||
luax_pushtype(L, "ImageData", IMAGE_IMAGE_DATA_T, t);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -96,7 +96,7 @@ int w_newCompressedData(lua_State *L)
|
||||
return luaL_error(L, "%s", e.what());
|
||||
}
|
||||
|
||||
luax_newtype(L, "CompressedData", IMAGE_COMPRESSED_DATA_T, (void *) t);
|
||||
luax_pushtype(L, "CompressedData", IMAGE_COMPRESSED_DATA_T, t);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ int w_getJoysticks(lua_State *L)
|
||||
{
|
||||
love::joystick::Joystick *stick = instance->getJoystick(i);
|
||||
stick->retain();
|
||||
luax_newtype(L, "Joystick", JOYSTICK_JOYSTICK_T, (void *) stick);
|
||||
luax_pushtype(L, "Joystick", JOYSTICK_JOYSTICK_T, stick);
|
||||
lua_rawseti(L, -2, i + 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ int w_BezierCurve_getDerivative(lua_State *L)
|
||||
{
|
||||
BezierCurve *curve = luax_checkbeziercurve(L, 1);
|
||||
BezierCurve *deriv = new BezierCurve(curve->getDerivative());
|
||||
luax_newtype(L, "BezierCurve", MATH_BEZIER_CURVE_T, (void *)deriv);
|
||||
luax_pushtype(L, "BezierCurve", MATH_BEZIER_CURVE_T, deriv);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ int w_newRandomGenerator(lua_State *L)
|
||||
}
|
||||
}
|
||||
|
||||
luax_newtype(L, "RandomGenerator", MATH_RANDOM_GENERATOR_T, (void *) t);
|
||||
luax_pushtype(L, "RandomGenerator", MATH_RANDOM_GENERATOR_T, t);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ int w_newBezierCurve(lua_State *L)
|
||||
}
|
||||
|
||||
BezierCurve *curve = Math::instance.newBezierCurve(points);
|
||||
luax_newtype(L, "BezierCurve", MATH_BEZIER_CURVE_T, (void *)curve);
|
||||
luax_pushtype(L, "BezierCurve", MATH_BEZIER_CURVE_T, curve);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ int w_newCursor(lua_State *L)
|
||||
}
|
||||
}
|
||||
|
||||
luax_newtype(L, "Cursor", MOUSE_CURSOR_T, (void *) cursor);
|
||||
luax_pushtype(L, "Cursor", MOUSE_CURSOR_T, cursor);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ int w_getCursor(lua_State *L)
|
||||
if (cursor)
|
||||
{
|
||||
cursor->retain();
|
||||
luax_newtype(L, "Cursor", MOUSE_CURSOR_T, (void *) cursor);
|
||||
luax_pushtype(L, "Cursor", MOUSE_CURSOR_T, cursor);
|
||||
}
|
||||
else
|
||||
lua_pushnil(L);
|
||||
|
||||
@@ -428,7 +428,7 @@ int Body::getFixtureList(lua_State *L) const
|
||||
if (!fixture)
|
||||
throw love::Exception("A fixture has escaped Memoizer!");
|
||||
fixture->retain();
|
||||
luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void *)fixture);
|
||||
luax_pushtype(L, "Fixture", PHYSICS_FIXTURE_T, fixture);
|
||||
lua_rawseti(L, -2, i);
|
||||
i++;
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ int Physics::newPolygonShape(lua_State *L)
|
||||
s->Set(vecs, vcount);
|
||||
PolygonShape *p = new PolygonShape(s);
|
||||
|
||||
luax_newtype(L, "PolygonShape", PHYSICS_POLYGON_SHAPE_T, (void *)p);
|
||||
luax_pushtype(L, "PolygonShape", PHYSICS_POLYGON_SHAPE_T, p);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ int Physics::newChainShape(lua_State *L)
|
||||
ChainShape *c = new ChainShape(s);
|
||||
delete[] vecs;
|
||||
|
||||
luax_newtype(L, "ChainShape", PHYSICS_CHAIN_SHAPE_T, (void *)c);
|
||||
luax_pushtype(L, "ChainShape", PHYSICS_CHAIN_SHAPE_T, c);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ void World::ContactCallback::process(b2Contact *contact, const b2ContactImpulse
|
||||
if (a != 0)
|
||||
{
|
||||
a->retain();
|
||||
luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void *)a);
|
||||
luax_pushtype(L, "Fixture", PHYSICS_FIXTURE_T, a);
|
||||
}
|
||||
else
|
||||
throw love::Exception("A fixture has escaped Memoizer!");
|
||||
@@ -71,7 +71,7 @@ void World::ContactCallback::process(b2Contact *contact, const b2ContactImpulse
|
||||
if (b != 0)
|
||||
{
|
||||
b->retain();
|
||||
luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void *)b);
|
||||
luax_pushtype(L, "Fixture", PHYSICS_FIXTURE_T, b);
|
||||
}
|
||||
else
|
||||
throw love::Exception("A fixture has escaped Memoizer!");
|
||||
@@ -83,7 +83,7 @@ void World::ContactCallback::process(b2Contact *contact, const b2ContactImpulse
|
||||
else
|
||||
cobj->retain();
|
||||
|
||||
luax_newtype(L, "Contact", (PHYSICS_CONTACT_T), (void *)cobj);
|
||||
luax_pushtype(L, "Contact", (PHYSICS_CONTACT_T), cobj);
|
||||
|
||||
int args = 3;
|
||||
if (impulse)
|
||||
@@ -133,8 +133,8 @@ bool World::ContactFilter::process(Fixture *a, Fixture *b)
|
||||
{
|
||||
lua_State *L = ref->getL();
|
||||
ref->push();
|
||||
luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void *)a);
|
||||
luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void *)b);
|
||||
luax_pushtype(L, "Fixture", PHYSICS_FIXTURE_T, a);
|
||||
luax_pushtype(L, "Fixture", PHYSICS_FIXTURE_T, b);
|
||||
lua_call(L, 2, 1);
|
||||
return luax_toboolean(L, -1);
|
||||
}
|
||||
@@ -162,7 +162,7 @@ bool World::QueryCallback::ReportFixture(b2Fixture *fixture)
|
||||
if (!f)
|
||||
throw love::Exception("A fixture has escaped Memoizer!");
|
||||
f->retain();
|
||||
luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void *)f);
|
||||
luax_pushtype(L, "Fixture", PHYSICS_FIXTURE_T, f);
|
||||
lua_call(L, 1, 1);
|
||||
return luax_toboolean(L, -1);
|
||||
}
|
||||
@@ -190,7 +190,7 @@ float32 World::RayCastCallback::ReportFixture(b2Fixture *fixture, const b2Vec2 &
|
||||
if (!f)
|
||||
throw love::Exception("A fixture has escaped Memoizer!");
|
||||
f->retain();
|
||||
luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void *)f);
|
||||
luax_pushtype(L, "Fixture", PHYSICS_FIXTURE_T, f);
|
||||
b2Vec2 scaledPoint = Physics::scaleUp(point);
|
||||
lua_pushnumber(L, scaledPoint.x);
|
||||
lua_pushnumber(L, scaledPoint.y);
|
||||
@@ -441,7 +441,7 @@ int World::getBodyList(lua_State *L) const
|
||||
if (!body)
|
||||
throw love::Exception("A body has escaped Memoizer!");
|
||||
body->retain();
|
||||
luax_newtype(L, "Body", PHYSICS_BODY_T, (void *)body);
|
||||
luax_pushtype(L, "Body", PHYSICS_BODY_T, body);
|
||||
lua_rawseti(L, -2, i);
|
||||
i++;
|
||||
}
|
||||
@@ -460,7 +460,7 @@ int World::getJointList(lua_State *L) const
|
||||
Joint *joint = (Joint *)Memoizer::find(j);
|
||||
if (!joint) throw love::Exception("A joint has escaped Memoizer!");
|
||||
joint->retain();
|
||||
luax_newtype(L, "Joint", PHYSICS_JOINT_T, (void *)joint);
|
||||
luax_pushtype(L, "Joint", PHYSICS_JOINT_T, joint);
|
||||
lua_rawseti(L, -2, i);
|
||||
i++;
|
||||
}
|
||||
@@ -481,7 +481,7 @@ int World::getContactList(lua_State *L) const
|
||||
contact = new Contact(c);
|
||||
else
|
||||
contact->retain();
|
||||
luax_newtype(L, "Contact", PHYSICS_CONTACT_T, (void *)contact);
|
||||
luax_pushtype(L, "Contact", PHYSICS_CONTACT_T, contact);
|
||||
lua_rawseti(L, -2, i);
|
||||
i++;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ int w_ChainShape_getChildEdge(lua_State *L)
|
||||
int index = luaL_checkint(L, 2) - 1; // Convert from 1-based index
|
||||
EdgeShape *e = 0;
|
||||
ASSERT_GUARD(e = c->getChildEdge(index);)
|
||||
luax_newtype(L, "EdgeShape", PHYSICS_EDGE_SHAPE_T, e);
|
||||
luax_pushtype(L, "EdgeShape", PHYSICS_EDGE_SHAPE_T, e);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ int w_Fixture_getBody(lua_State *L)
|
||||
if (body == 0)
|
||||
return 0;
|
||||
body->retain();
|
||||
luax_newtype(L, "Body", PHYSICS_BODY_T, (void *)body);
|
||||
luax_pushtype(L, "Body", PHYSICS_BODY_T, body);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -125,19 +125,19 @@ int w_Fixture_getShape(lua_State *L)
|
||||
switch (shape->getType())
|
||||
{
|
||||
case Shape::SHAPE_EDGE:
|
||||
luax_newtype(L, "EdgeShape", PHYSICS_EDGE_SHAPE_T, (void *)shape);
|
||||
luax_pushtype(L, "EdgeShape", PHYSICS_EDGE_SHAPE_T, shape);
|
||||
break;
|
||||
case Shape::SHAPE_CHAIN:
|
||||
luax_newtype(L, "ChainShape", PHYSICS_CHAIN_SHAPE_T, (void *)shape);
|
||||
luax_pushtype(L, "ChainShape", PHYSICS_CHAIN_SHAPE_T, shape);
|
||||
break;
|
||||
case Shape::SHAPE_CIRCLE:
|
||||
luax_newtype(L, "CircleShape", PHYSICS_CIRCLE_SHAPE_T, (void *)shape);
|
||||
luax_pushtype(L, "CircleShape", PHYSICS_CIRCLE_SHAPE_T, shape);
|
||||
break;
|
||||
case Shape::SHAPE_POLYGON:
|
||||
luax_newtype(L, "PolygonShape", PHYSICS_POLYGON_SHAPE_T, (void *)shape);
|
||||
luax_pushtype(L, "PolygonShape", PHYSICS_POLYGON_SHAPE_T, shape);
|
||||
break;
|
||||
default:
|
||||
luax_newtype(L, "Shape", PHYSICS_SHAPE_T, (void *)shape);
|
||||
luax_pushtype(L, "Shape", PHYSICS_SHAPE_T, shape);
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
|
||||
@@ -58,7 +58,7 @@ int w_newWorld(lua_State *L)
|
||||
|
||||
World *w;
|
||||
ASSERT_GUARD(w = instance->newWorld(gx, gy, sleep);)
|
||||
luax_newtype(L, "World", PHYSICS_WORLD_T, (void *)w);
|
||||
luax_pushtype(L, "World", PHYSICS_WORLD_T, w);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -76,7 +76,7 @@ int w_newBody(lua_State *L)
|
||||
|
||||
Body *body;
|
||||
ASSERT_GUARD(body = instance->newBody(world, x, y, btype);)
|
||||
luax_newtype(L, "Body", PHYSICS_BODY_T, (void *)body);
|
||||
luax_pushtype(L, "Body", PHYSICS_BODY_T, body);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ int w_newFixture(lua_State *L)
|
||||
float density = (float)luaL_optnumber(L, 3, 1.0f);
|
||||
Fixture *fixture;
|
||||
ASSERT_GUARD(fixture = instance->newFixture(body, shape, density);)
|
||||
luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void *)fixture);
|
||||
luax_pushtype(L, "Fixture", PHYSICS_FIXTURE_T, fixture);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ int w_newCircleShape(lua_State *L)
|
||||
float radius = (float)luaL_checknumber(L, 1);
|
||||
CircleShape *shape;
|
||||
ASSERT_GUARD(shape = instance->newCircleShape(radius);)
|
||||
luax_newtype(L, "CircleShape", PHYSICS_CIRCLE_SHAPE_T, (void *)shape);
|
||||
luax_pushtype(L, "CircleShape", PHYSICS_CIRCLE_SHAPE_T, shape);
|
||||
return 1;
|
||||
}
|
||||
else if (top == 3)
|
||||
@@ -110,7 +110,7 @@ int w_newCircleShape(lua_State *L)
|
||||
float radius = (float)luaL_checknumber(L, 3);
|
||||
CircleShape *shape;
|
||||
ASSERT_GUARD(shape = instance->newCircleShape(x, y, radius);)
|
||||
luax_newtype(L, "CircleShape", PHYSICS_CIRCLE_SHAPE_T, (void *)shape);
|
||||
luax_pushtype(L, "CircleShape", PHYSICS_CIRCLE_SHAPE_T, shape);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
@@ -127,7 +127,7 @@ int w_newRectangleShape(lua_State *L)
|
||||
float h = (float)luaL_checknumber(L, 2);
|
||||
PolygonShape *shape;
|
||||
ASSERT_GUARD(shape = instance->newRectangleShape(w, h);)
|
||||
luax_newtype(L, "PolygonShape", PHYSICS_POLYGON_SHAPE_T, (void *)shape);
|
||||
luax_pushtype(L, "PolygonShape", PHYSICS_POLYGON_SHAPE_T, shape);
|
||||
return 1;
|
||||
}
|
||||
else if (top == 4 || top == 5)
|
||||
@@ -139,7 +139,7 @@ int w_newRectangleShape(lua_State *L)
|
||||
float angle = (float)luaL_optnumber(L, 5, 0);
|
||||
PolygonShape *shape;
|
||||
ASSERT_GUARD(shape = instance->newRectangleShape(x, y, w, h, angle);)
|
||||
luax_newtype(L, "PolygonShape", PHYSICS_POLYGON_SHAPE_T, (void *)shape);
|
||||
luax_pushtype(L, "PolygonShape", PHYSICS_POLYGON_SHAPE_T, shape);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
@@ -154,7 +154,7 @@ int w_newEdgeShape(lua_State *L)
|
||||
float y2 = (float)luaL_checknumber(L, 4);
|
||||
EdgeShape *shape;
|
||||
ASSERT_GUARD(shape = instance->newEdgeShape(x1, y1, x2, y2);)
|
||||
luax_newtype(L, "EdgeShape", PHYSICS_EDGE_SHAPE_T, (void *)shape);
|
||||
luax_pushtype(L, "EdgeShape", PHYSICS_EDGE_SHAPE_T, shape);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ int w_newDistanceJoint(lua_State *L)
|
||||
bool collideConnected = luax_optboolean(L, 7, false);
|
||||
DistanceJoint *j;
|
||||
ASSERT_GUARD(j = instance->newDistanceJoint(body1, body2, x1, y1, x2, y2, collideConnected);)
|
||||
luax_newtype(L, "DistanceJoint", PHYSICS_DISTANCE_JOINT_T, (void *)j);
|
||||
luax_pushtype(L, "DistanceJoint", PHYSICS_DISTANCE_JOINT_T, j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ int w_newMouseJoint(lua_State *L)
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
MouseJoint *j;
|
||||
ASSERT_GUARD(j = instance->newMouseJoint(body, x, y);)
|
||||
luax_newtype(L, "MouseJoint", PHYSICS_MOUSE_JOINT_T, (void *)j);
|
||||
luax_pushtype(L, "MouseJoint", PHYSICS_MOUSE_JOINT_T, j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ int w_newRevoluteJoint(lua_State *L)
|
||||
bool collideConnected = luax_optboolean(L, 5, false);
|
||||
RevoluteJoint *j;
|
||||
ASSERT_GUARD(j = instance->newRevoluteJoint(body1, body2, x, y, collideConnected);)
|
||||
luax_newtype(L, "RevoluteJoint", PHYSICS_REVOLUTE_JOINT_T, (void *)j);
|
||||
luax_pushtype(L, "RevoluteJoint", PHYSICS_REVOLUTE_JOINT_T, j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -233,7 +233,7 @@ int w_newPrismaticJoint(lua_State *L)
|
||||
}
|
||||
PrismaticJoint *j;
|
||||
ASSERT_GUARD(j = instance->newPrismaticJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected);)
|
||||
luax_newtype(L, "PrismaticJoint", PHYSICS_PRISMATIC_JOINT_T, (void *)j);
|
||||
luax_pushtype(L, "PrismaticJoint", PHYSICS_PRISMATIC_JOINT_T, j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -254,7 +254,7 @@ int w_newPulleyJoint(lua_State *L)
|
||||
|
||||
PulleyJoint *j;
|
||||
ASSERT_GUARD(j = instance->newPulleyJoint(body1, body2, b2Vec2(gx1,gy1), b2Vec2(gx2,gy2), b2Vec2(x1,y1), b2Vec2(x2,y2), ratio, collideConnected);)
|
||||
luax_newtype(L, "PulleyJoint", PHYSICS_PULLEY_JOINT_T, (void *)j);
|
||||
luax_pushtype(L, "PulleyJoint", PHYSICS_PULLEY_JOINT_T, j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -267,7 +267,7 @@ int w_newGearJoint(lua_State *L)
|
||||
|
||||
GearJoint *j;
|
||||
ASSERT_GUARD(j = instance->newGearJoint(joint1, joint2, ratio, collideConnected);)
|
||||
luax_newtype(L, "GearJoint", PHYSICS_GEAR_JOINT_T, (void *)j);
|
||||
luax_pushtype(L, "GearJoint", PHYSICS_GEAR_JOINT_T, j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ int w_newFrictionJoint(lua_State *L)
|
||||
}
|
||||
FrictionJoint *j;
|
||||
ASSERT_GUARD(j = instance->newFrictionJoint(body1, body2, xA, yA, xB, yB, collideConnected);)
|
||||
luax_newtype(L, "FrictionJoint", PHYSICS_FRICTION_JOINT_T, (void *)j);
|
||||
luax_pushtype(L, "FrictionJoint", PHYSICS_FRICTION_JOINT_T, j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -319,7 +319,7 @@ int w_newWeldJoint(lua_State *L)
|
||||
}
|
||||
WeldJoint *j;
|
||||
ASSERT_GUARD(j = instance->newWeldJoint(body1, body2, xA, yA, xB, yB, collideConnected);)
|
||||
luax_newtype(L, "WeldJoint", PHYSICS_WELD_JOINT_T, (void *)j);
|
||||
luax_pushtype(L, "WeldJoint", PHYSICS_WELD_JOINT_T, j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -350,7 +350,7 @@ int w_newWheelJoint(lua_State *L)
|
||||
|
||||
WheelJoint *j;
|
||||
ASSERT_GUARD(j = instance->newWheelJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected);)
|
||||
luax_newtype(L, "WheelJoint", PHYSICS_WHEEL_JOINT_T, (void *)j);
|
||||
luax_pushtype(L, "WheelJoint", PHYSICS_WHEEL_JOINT_T, j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -366,7 +366,7 @@ int w_newRopeJoint(lua_State *L)
|
||||
bool collideConnected = luax_optboolean(L, 8, false);
|
||||
RopeJoint *j;
|
||||
ASSERT_GUARD(j = instance->newRopeJoint(body1, body2, x1, y1, x2, y2, maxLength, collideConnected);)
|
||||
luax_newtype(L, "RopeJoint", PHYSICS_ROPE_JOINT_T, (void *)j);
|
||||
luax_pushtype(L, "RopeJoint", PHYSICS_ROPE_JOINT_T, j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -72,8 +72,7 @@ int w_newSoundData(lua_State *L)
|
||||
}
|
||||
}
|
||||
|
||||
luax_newtype(L, "SoundData", SOUND_SOUND_DATA_T, (void *)t);
|
||||
|
||||
luax_pushtype(L, "SoundData", SOUND_SOUND_DATA_T, t);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -92,7 +91,7 @@ int w_newDecoder(lua_State *L)
|
||||
Decoder *t = instance->newDecoder(data, bufferSize);
|
||||
if (t == 0)
|
||||
return luaL_error(L, "Extension \"%s\" not supported.", data->getExtension().c_str());
|
||||
luax_newtype(L, "Decoder", SOUND_DECODER_T, (void *)t);
|
||||
luax_pushtype(L, "Decoder", SOUND_DECODER_T, t);
|
||||
}
|
||||
catch(love::Exception &e)
|
||||
{
|
||||
|
||||
@@ -54,14 +54,14 @@ int w_newThread(lua_State *L)
|
||||
}
|
||||
|
||||
LuaThread *t = instance->newThread(name, data);
|
||||
luax_newtype(L, "Thread", THREAD_THREAD_T, (void *)t);
|
||||
luax_pushtype(L, "Thread", THREAD_THREAD_T, t);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newChannel(lua_State *L)
|
||||
{
|
||||
Channel *c = instance->newChannel();
|
||||
luax_newtype(L, "Channel", THREAD_CHANNEL_T, (void *)c);
|
||||
luax_pushtype(L, "Channel", THREAD_CHANNEL_T, c);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ int w_getChannel(lua_State *L)
|
||||
{
|
||||
std::string name = luax_checkstring(L, 1);
|
||||
Channel *c = instance->getChannel(name);
|
||||
luax_newtype(L, "Channel", THREAD_CHANNEL_T, (void *)c);
|
||||
luax_pushtype(L, "Channel", THREAD_CHANNEL_T, c);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -275,7 +275,7 @@ int w_getIcon(lua_State *L)
|
||||
if (i)
|
||||
{
|
||||
i->retain();
|
||||
luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void*) i);
|
||||
luax_pushtype(L, "ImageData", IMAGE_IMAGE_DATA_T, i);
|
||||
}
|
||||
else
|
||||
lua_pushnil(L);
|
||||
|
||||
Reference in New Issue
Block a user