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)) { | ||||
|     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); | ||||
|  |  | |||
|  | @ -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); | ||||
|  |  | |||
|  | @ -25,13 +25,24 @@ gfx::Size Size_new(lua_State* L, int index) | |||
|   if (auto sz2 = may_get_obj<gfx::Size>(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); | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue