mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-16 10:20:50 +00:00
lua: Add tostring support for Point/Size/Rectangle
This commit is contained in:
parent
047dbbca67
commit
c945996fd6
@ -1,4 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2019 Igara Studio S.A.
|
||||
// Copyright (C) 2017-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -9,6 +10,7 @@
|
||||
#endif
|
||||
|
||||
#include "app/script/luacpp.h"
|
||||
#include "fmt/format.h"
|
||||
#include "gfx/point.h"
|
||||
|
||||
namespace app {
|
||||
@ -58,6 +60,14 @@ int Point_eq(lua_State* L)
|
||||
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)
|
||||
{
|
||||
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[] = {
|
||||
{ "__gc", Point_gc },
|
||||
{ "__eq", Point_eq },
|
||||
{ "__tostring", Point_tostring },
|
||||
{ nullptr, nullptr }
|
||||
};
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2019 Igara Studio S.A.
|
||||
// Copyright (C) 2017-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -9,6 +10,7 @@
|
||||
#endif
|
||||
|
||||
#include "app/script/luacpp.h"
|
||||
#include "fmt/format.h"
|
||||
#include "gfx/point.h"
|
||||
#include "gfx/rect.h"
|
||||
|
||||
@ -65,6 +67,14 @@ int Rectangle_eq(lua_State* L)
|
||||
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)
|
||||
{
|
||||
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[] = {
|
||||
{ "__gc", Rectangle_gc },
|
||||
{ "__eq", Rectangle_eq },
|
||||
{ "__tostring", Rectangle_tostring },
|
||||
{ "contains", Rectangle_contains },
|
||||
{ "intersects", Rectangle_intersects },
|
||||
{ "union", Rectangle_union },
|
||||
|
@ -1,4 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2019 Igara Studio S.A.
|
||||
// Copyright (C) 2017-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -9,6 +10,7 @@
|
||||
#endif
|
||||
|
||||
#include "app/script/luacpp.h"
|
||||
#include "fmt/format.h"
|
||||
#include "gfx/size.h"
|
||||
|
||||
namespace app {
|
||||
@ -58,6 +60,14 @@ int Size_eq(lua_State* L)
|
||||
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)
|
||||
{
|
||||
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[] = {
|
||||
{ "__gc", Size_gc },
|
||||
{ "__eq", Size_eq },
|
||||
{ "__tostring", Size_tostring },
|
||||
{ nullptr, nullptr }
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user