lua: Add tostring support for Point/Size/Rectangle

This commit is contained in:
David Capello 2019-03-29 15:54:20 -03:00
parent 047dbbca67
commit c945996fd6
3 changed files with 33 additions and 0 deletions

View File

@ -1,4 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2017-2018 David Capello // Copyright (C) 2017-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -9,6 +10,7 @@
#endif #endif
#include "app/script/luacpp.h" #include "app/script/luacpp.h"
#include "fmt/format.h"
#include "gfx/point.h" #include "gfx/point.h"
namespace app { namespace app {
@ -58,6 +60,14 @@ int Point_eq(lua_State* L)
return 1; return 1;
} }
int Point_tostring(lua_State* L)
{
const auto pt = get_obj<gfx::Point>(L, 1);
lua_pushstring(L, fmt::format("Point{{ x={}, y={} }}",
pt->x, pt->y).c_str());
return 1;
}
int Point_get_x(lua_State* L) int Point_get_x(lua_State* L)
{ {
const auto pt = get_obj<gfx::Point>(L, 1); const auto pt = get_obj<gfx::Point>(L, 1);
@ -89,6 +99,7 @@ int Point_set_y(lua_State* L)
const luaL_Reg Point_methods[] = { const luaL_Reg Point_methods[] = {
{ "__gc", Point_gc }, { "__gc", Point_gc },
{ "__eq", Point_eq }, { "__eq", Point_eq },
{ "__tostring", Point_tostring },
{ nullptr, nullptr } { nullptr, nullptr }
}; };

View File

@ -1,4 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2017-2018 David Capello // Copyright (C) 2017-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -9,6 +10,7 @@
#endif #endif
#include "app/script/luacpp.h" #include "app/script/luacpp.h"
#include "fmt/format.h"
#include "gfx/point.h" #include "gfx/point.h"
#include "gfx/rect.h" #include "gfx/rect.h"
@ -65,6 +67,14 @@ int Rectangle_eq(lua_State* L)
return 1; return 1;
} }
int Rectangle_tostring(lua_State* L)
{
const auto rc = get_obj<gfx::Rect>(L, 1);
lua_pushstring(L, fmt::format("Rectangle{{ x={}, y={}, width={}, height={} }}",
rc->x, rc->y, rc->w, rc->h).c_str());
return 1;
}
int Rectangle_contains(lua_State* L) int Rectangle_contains(lua_State* L)
{ {
const auto a = get_obj<gfx::Rect>(L, 1); const auto a = get_obj<gfx::Rect>(L, 1);
@ -163,6 +173,7 @@ int Rectangle_get_isEmpty(lua_State* L)
const luaL_Reg Rectangle_methods[] = { const luaL_Reg Rectangle_methods[] = {
{ "__gc", Rectangle_gc }, { "__gc", Rectangle_gc },
{ "__eq", Rectangle_eq }, { "__eq", Rectangle_eq },
{ "__tostring", Rectangle_tostring },
{ "contains", Rectangle_contains }, { "contains", Rectangle_contains },
{ "intersects", Rectangle_intersects }, { "intersects", Rectangle_intersects },
{ "union", Rectangle_union }, { "union", Rectangle_union },

View File

@ -1,4 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2017-2018 David Capello // Copyright (C) 2017-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -9,6 +10,7 @@
#endif #endif
#include "app/script/luacpp.h" #include "app/script/luacpp.h"
#include "fmt/format.h"
#include "gfx/size.h" #include "gfx/size.h"
namespace app { namespace app {
@ -58,6 +60,14 @@ int Size_eq(lua_State* L)
return 1; return 1;
} }
int Size_tostring(lua_State* L)
{
const auto sz = get_obj<gfx::Size>(L, 1);
lua_pushstring(L, fmt::format("Size{{ width={}, height={} }}",
sz->w, sz->h).c_str());
return 1;
}
int Size_get_width(lua_State* L) int Size_get_width(lua_State* L)
{ {
const auto sz = get_obj<gfx::Size>(L, 1); const auto sz = get_obj<gfx::Size>(L, 1);
@ -93,6 +103,7 @@ int Size_set_height(lua_State* L)
const luaL_Reg Size_methods[] = { const luaL_Reg Size_methods[] = {
{ "__gc", Size_gc }, { "__gc", Size_gc },
{ "__eq", Size_eq }, { "__eq", Size_eq },
{ "__tostring", Size_tostring },
{ nullptr, nullptr } { nullptr, nullptr }
}; };