From: Pasi Kallinen Date: Sat, 22 Feb 2020 13:23:30 +0000 (+0200) Subject: Make lua selection rect and fillrect create a new selection X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b3f337bdf6d134b3f80c8b57a9c4ba9c12948d8a;p=nethack Make lua selection rect and fillrect create a new selection --- diff --git a/src/nhlsel.c b/src/nhlsel.c index ed84ac532..a41e7ed5c 100644 --- a/src/nhlsel.c +++ b/src/nhlsel.c @@ -419,11 +419,13 @@ lua_State *L; get_location_coord(&x2, &y2, ANY_LOC, g.coder ? g.coder->croom : NULL, SP_COORD_PACK(x2, y2)); + lua_settop(L, 1); + (void) l_selection_clone(L); + sel = l_selection_check(L, 1); selection_do_line(x1, y1, x2, y1, sel); selection_do_line(x1, y1, x1, y2, sel); selection_do_line(x2, y1, x2, y2, sel); selection_do_line(x1, y2, x2, y2, sel); - lua_settop(L, 1); return 1; } @@ -451,6 +453,9 @@ lua_State *L; get_location_coord(&x2, &y2, ANY_LOC, g.coder ? g.coder->croom : NULL, SP_COORD_PACK(x2, y2)); + lua_settop(L, 1); + (void) l_selection_clone(L); + sel = l_selection_check(L, 1); if (x1 == x2) { for (y = y1; y <= y2; y++) selection_setpoint(x1, y, sel, 1); @@ -458,7 +463,6 @@ lua_State *L; for (y = y1; y <= y2; y++) selection_do_line(x1, y, x2, y, sel); } - lua_settop(L, 1); return 1; } diff --git a/test/test_sel.lua b/test/test_sel.lua index c35ae96a4..509731fe6 100644 --- a/test/test_sel.lua +++ b/test/test_sel.lua @@ -244,6 +244,40 @@ function test_sel_line() end -- test_sel_line +function test_sel_rect() + local __func__ = "test_sel_rect"; + local sela = selection.new(); + local sela_clone = sela:clone(); + + local selb = sela:rect(1,1, 3,3); + sel_are_equal(sela, sela_clone, __func__); + sel_has_n_points(selb, 8, __func__); + + for x = 1,3 do + for y = 1,3 do + local v = 1; + if (x == 2 and y == 2) then v = 0; end; + sel_pt_ne(selb, x,y, v, __func__); + end + end +end -- test_sel_rect + +function test_sel_fillrect() + local __func__ = "test_sel_fillrect"; + local sela = selection.new(); + local sela_clone = sela:clone(); + + local selb = sela:fillrect(1,1, 3,3); + sel_are_equal(sela, sela_clone, __func__); + sel_has_n_points(selb, 9, __func__); + + for x = 1,3 do + for y = 1,3 do + sel_pt_ne(selb, x,y, 1, __func__); + end + end +end -- test_sel_fillrect + test_selection_params(); test_sel_negate(); test_sel_logical_and(); @@ -251,3 +285,5 @@ test_sel_logical_or(); test_sel_logical_xor(); test_sel_filter_percent(); test_sel_line(); +test_sel_rect(); +test_sel_fillrect();