]> granicus.if.org Git - nethack/commitdiff
Make lua selection rect and fillrect create a new selection
authorPasi Kallinen <paxed@alt.org>
Sat, 22 Feb 2020 13:23:30 +0000 (15:23 +0200)
committerPasi Kallinen <paxed@alt.org>
Sat, 22 Feb 2020 13:23:30 +0000 (15:23 +0200)
src/nhlsel.c
test/test_sel.lua

index ed84ac5322cc2cbd3501014ab05027f550d4d676..a41e7ed5c3834620beb9fa2205b409d2d898c698 100644 (file)
@@ -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;
 }
 
index c35ae96a4ef99b495d1ee3507234bffc098f0d10..509731fe683d53a9d607cbc7d2e88dee510c1428 100644 (file)
@@ -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();