lua: use push_new instead of push_obj with move ctor

This commit is contained in:
David Capello 2018-09-03 18:37:45 -03:00
parent a107dd29a4
commit 24b28ae064
3 changed files with 5 additions and 22 deletions

View File

@ -30,10 +30,6 @@ struct ImageObj {
: image(image)
, cel(cel) {
}
ImageObj(ImageObj&& that) {
std::swap(image, that.image);
std::swap(cel, that.cel);
}
ImageObj(const ImageObj&) = delete;
ImageObj& operator=(const ImageObj&) = delete;
};
@ -45,7 +41,7 @@ int Image_new(lua_State* L)
const int colorMode = (lua_isnone(L, 3) ? doc::IMAGE_RGB:
lua_tointeger(L, 3));
doc::ImageRef image(doc::Image::create((doc::PixelFormat)colorMode, w, h));
push_obj(L, ImageObj(image, nullptr));
push_new<ImageObj>(L, image, nullptr);
return 1;
}
@ -53,7 +49,7 @@ int Image_clone(lua_State* L)
{
auto obj = get_obj<ImageObj>(L, 1);
doc::ImageRef cloned(doc::Image::createCopy(obj->image.get()));
push_obj(L, ImageObj(cloned, nullptr));
push_new<ImageObj>(L, cloned, nullptr);
return 1;
}
@ -169,7 +165,7 @@ void register_image_class(lua_State* L)
void push_cel_image(lua_State* L, doc::Cel* cel)
{
push_obj(L, ImageObj(cel->imageRef(), cel));
push_new<ImageObj>(L, cel->imageRef(), cel);
}
} // namespace script

View File

@ -43,13 +43,6 @@ template <typename T> void push_obj(lua_State* L, const T& obj) {
lua_setmetatable(L, -2);
}
template <typename T> void push_obj(lua_State* L, T&& obj) {
using RRT = typename std::remove_reference<T>::type;
new (lua_newuserdata(L, sizeof(RRT))) RRT(std::move(obj));
luaL_getmetatable(L, get_mtname<RRT>());
lua_setmetatable(L, -2);
}
template <typename T> T* push_ptr(lua_State* L, T* ptr) {
*(T**)lua_newuserdata(L, sizeof(T*)) = ptr;
luaL_getmetatable(L, get_mtname<T>());

View File

@ -31,12 +31,6 @@ struct SelectionObj {
: mask(mask)
, sprite(sprite) {
}
SelectionObj(SelectionObj&& that)
: mask(that.mask)
, sprite(that.sprite) {
that.mask = nullptr;
that.sprite = nullptr;
}
~SelectionObj() {
if (!sprite && mask)
delete mask;
@ -47,7 +41,7 @@ struct SelectionObj {
int Selection_new(lua_State* L)
{
push_obj(L, SelectionObj(new Mask, nullptr));
push_new<SelectionObj>(L, new Mask, nullptr);
return 1;
}
@ -182,7 +176,7 @@ void register_selection_class(lua_State* L)
void push_sprite_selection(lua_State* L, Sprite* sprite)
{
push_obj(L, SelectionObj(nullptr, sprite));
push_new<SelectionObj>(L, nullptr, sprite);
}
} // namespace script