diff --git a/src/app/script/point_class.cpp b/src/app/script/point_class.cpp index aaf6bfec0..fbe8b60c5 100644 --- a/src/app/script/point_class.cpp +++ b/src/app/script/point_class.cpp @@ -25,13 +25,24 @@ gfx::Point Point_new(lua_State* L, int index) if (auto pt2 = may_get_obj(L, index)) { 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)) { - lua_getfield(L, index, "x"); - lua_getfield(L, index, "y"); - pt.x = lua_tointeger(L, -2); - pt.y = lua_tointeger(L, -1); - lua_pop(L, 2); + const int type = lua_getfield(L, index, "x"); + if (type != LUA_TNONE && + type != LUA_TNIL) { + lua_getfield(L, index, "y"); + 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 { pt.x = lua_tointeger(L, index); diff --git a/src/app/script/rectangle_class.cpp b/src/app/script/rectangle_class.cpp index 70940b3cd..9b9b81768 100644 --- a/src/app/script/rectangle_class.cpp +++ b/src/app/script/rectangle_class.cpp @@ -28,15 +28,30 @@ gfx::Rect Rectangle_new(lua_State* L, int index) } // Convert { x, y, width, height } into a Rectangle else if (lua_istable(L, index)) { - lua_getfield(L, index, "x"); - lua_getfield(L, index, "y"); - lua_getfield(L, index, "width"); - lua_getfield(L, index, "height"); - 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); + const int type = lua_getfield(L, index, "x"); + if (type != LUA_TNONE && + type != LUA_TNIL) { + lua_getfield(L, index, "y"); + lua_getfield(L, index, "width"); + lua_getfield(L, index, "height"); + 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 { + 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 { rc.x = lua_tointeger(L, index); diff --git a/src/app/script/size_class.cpp b/src/app/script/size_class.cpp index 160bbc642..e674439a9 100644 --- a/src/app/script/size_class.cpp +++ b/src/app/script/size_class.cpp @@ -25,13 +25,24 @@ gfx::Size Size_new(lua_State* L, int index) if (auto sz2 = may_get_obj(L, index)) { 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)) { - lua_getfield(L, index, "width"); - lua_getfield(L, index, "height"); - sz.w = lua_tointeger(L, -2); - sz.h = lua_tointeger(L, -1); - lua_pop(L, 2); + const int type = lua_getfield(L, index, "width"); + if (type != LUA_TNONE && + type != LUA_TNIL) { + lua_getfield(L, index, "height"); + 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 { sz.w = lua_tointeger(L, index);