mirror of https://github.com/aseprite/aseprite.git
lua: Add support to construct Point/Size/Rectangles from array of integers
This commit is contained in:
parent
1ef67cada4
commit
ccef22f187
|
|
@ -25,13 +25,24 @@ gfx::Point Point_new(lua_State* L, int index)
|
||||||
if (auto pt2 = may_get_obj<gfx::Point>(L, index)) {
|
if (auto pt2 = may_get_obj<gfx::Point>(L, index)) {
|
||||||
pt = *pt2;
|
pt = *pt2;
|
||||||
}
|
}
|
||||||
// Convert { x, y } into a Point
|
// Convert {x=int,y=int} or {int,int} into a Point
|
||||||
else if (lua_istable(L, index)) {
|
else if (lua_istable(L, index)) {
|
||||||
lua_getfield(L, index, "x");
|
const int type = lua_getfield(L, index, "x");
|
||||||
lua_getfield(L, index, "y");
|
if (type != LUA_TNONE &&
|
||||||
pt.x = lua_tointeger(L, -2);
|
type != LUA_TNIL) {
|
||||||
pt.y = lua_tointeger(L, -1);
|
lua_getfield(L, index, "y");
|
||||||
lua_pop(L, 2);
|
pt.x = lua_tointeger(L, -2);
|
||||||
|
pt.y = lua_tointeger(L, -1);
|
||||||
|
lua_pop(L, 2);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
lua_pop(L, 1);
|
||||||
|
lua_geti(L, index, 1);
|
||||||
|
lua_geti(L, index, 2);
|
||||||
|
pt.x = lua_tointeger(L, -2);
|
||||||
|
pt.y = lua_tointeger(L, -1);
|
||||||
|
lua_pop(L, 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
pt.x = lua_tointeger(L, index);
|
pt.x = lua_tointeger(L, index);
|
||||||
|
|
|
||||||
|
|
@ -28,15 +28,30 @@ gfx::Rect Rectangle_new(lua_State* L, int index)
|
||||||
}
|
}
|
||||||
// Convert { x, y, width, height } into a Rectangle
|
// Convert { x, y, width, height } into a Rectangle
|
||||||
else if (lua_istable(L, index)) {
|
else if (lua_istable(L, index)) {
|
||||||
lua_getfield(L, index, "x");
|
const int type = lua_getfield(L, index, "x");
|
||||||
lua_getfield(L, index, "y");
|
if (type != LUA_TNONE &&
|
||||||
lua_getfield(L, index, "width");
|
type != LUA_TNIL) {
|
||||||
lua_getfield(L, index, "height");
|
lua_getfield(L, index, "y");
|
||||||
rc.x = lua_tointeger(L, -4);
|
lua_getfield(L, index, "width");
|
||||||
rc.y = lua_tointeger(L, -3);
|
lua_getfield(L, index, "height");
|
||||||
rc.w = lua_tointeger(L, -2);
|
rc.x = lua_tointeger(L, -4);
|
||||||
rc.h = lua_tointeger(L, -1);
|
rc.y = lua_tointeger(L, -3);
|
||||||
lua_pop(L, 4);
|
rc.w = lua_tointeger(L, -2);
|
||||||
|
rc.h = lua_tointeger(L, -1);
|
||||||
|
lua_pop(L, 4);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
lua_pop(L, 1);
|
||||||
|
lua_geti(L, index, 1);
|
||||||
|
lua_geti(L, index, 2);
|
||||||
|
lua_geti(L, index, 3);
|
||||||
|
lua_geti(L, index, 4);
|
||||||
|
rc.x = lua_tointeger(L, -4);
|
||||||
|
rc.y = lua_tointeger(L, -3);
|
||||||
|
rc.w = lua_tointeger(L, -2);
|
||||||
|
rc.h = lua_tointeger(L, -1);
|
||||||
|
lua_pop(L, 4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rc.x = lua_tointeger(L, index);
|
rc.x = lua_tointeger(L, index);
|
||||||
|
|
|
||||||
|
|
@ -25,13 +25,24 @@ gfx::Size Size_new(lua_State* L, int index)
|
||||||
if (auto sz2 = may_get_obj<gfx::Size>(L, index)) {
|
if (auto sz2 = may_get_obj<gfx::Size>(L, index)) {
|
||||||
sz = *sz2;
|
sz = *sz2;
|
||||||
}
|
}
|
||||||
// Convert { width, height } into a Size
|
// Convert {x=int,y=int} or {int,int} into a Size
|
||||||
else if (lua_istable(L, index)) {
|
else if (lua_istable(L, index)) {
|
||||||
lua_getfield(L, index, "width");
|
const int type = lua_getfield(L, index, "width");
|
||||||
lua_getfield(L, index, "height");
|
if (type != LUA_TNONE &&
|
||||||
sz.w = lua_tointeger(L, -2);
|
type != LUA_TNIL) {
|
||||||
sz.h = lua_tointeger(L, -1);
|
lua_getfield(L, index, "height");
|
||||||
lua_pop(L, 2);
|
sz.w = lua_tointeger(L, -2);
|
||||||
|
sz.h = lua_tointeger(L, -1);
|
||||||
|
lua_pop(L, 2);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
lua_pop(L, 1);
|
||||||
|
lua_geti(L, index, 1);
|
||||||
|
lua_geti(L, index, 2);
|
||||||
|
sz.w = lua_tointeger(L, -2);
|
||||||
|
sz.h = lua_tointeger(L, -1);
|
||||||
|
lua_pop(L, 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sz.w = lua_tointeger(L, index);
|
sz.w = lua_tointeger(L, index);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue