Make lua selection negate return a new selection
... instead of modifying the one given as a parameter. Also add tests for it.
This commit is contained in:
+12
-5
@@ -113,6 +113,7 @@ lua_State *L;
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Replace the topmost selection in the stack with a clone of it. */
|
||||||
/* local sel = selection.clone(sel); */
|
/* local sel = selection.clone(sel); */
|
||||||
static int
|
static int
|
||||||
l_selection_clone(L)
|
l_selection_clone(L)
|
||||||
@@ -120,7 +121,6 @@ lua_State *L;
|
|||||||
{
|
{
|
||||||
struct selectionvar *sel = l_selection_check(L, 1);
|
struct selectionvar *sel = l_selection_check(L, 1);
|
||||||
struct selectionvar *tmp;
|
struct selectionvar *tmp;
|
||||||
/* int x,y; */ /* REVIEW: unreferenced */
|
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
(void) l_selection_new(L);
|
(void) l_selection_new(L);
|
||||||
tmp = l_selection_check(L, 1);
|
tmp = l_selection_check(L, 1);
|
||||||
@@ -207,17 +207,24 @@ lua_State *L;
|
|||||||
|
|
||||||
/* local s = selection.negate(sel); */
|
/* local s = selection.negate(sel); */
|
||||||
/* local s = selection.negate(); */
|
/* local s = selection.negate(); */
|
||||||
|
/* local s = sel:negate(); */
|
||||||
static int
|
static int
|
||||||
l_selection_not(L)
|
l_selection_not(L)
|
||||||
lua_State *L;
|
lua_State *L;
|
||||||
{
|
{
|
||||||
int argc = lua_gettop(L);
|
int argc = lua_gettop(L);
|
||||||
struct selectionvar *sel;
|
struct selectionvar *sel, *sel2;
|
||||||
|
|
||||||
if (argc == 0)
|
if (argc == 0) {
|
||||||
(void) l_selection_new(L);
|
(void) l_selection_new(L);
|
||||||
sel = l_selection_check(L, 1);
|
sel = l_selection_check(L, 1);
|
||||||
selection_not(sel);
|
selection_not(sel);
|
||||||
|
} else {
|
||||||
|
sel = l_selection_check(L, 1);
|
||||||
|
(void) l_selection_clone(L);
|
||||||
|
sel2 = l_selection_check(L, 1);
|
||||||
|
selection_not(sel2);
|
||||||
|
}
|
||||||
lua_settop(L, 1);
|
lua_settop(L, 1);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
+25
-4
@@ -1,8 +1,8 @@
|
|||||||
|
|
||||||
|
|
||||||
-- Test the selection
|
-- Test the selection
|
||||||
|
|
||||||
function test_selection()
|
-- test selection parameters
|
||||||
|
function test_selection_params()
|
||||||
local sel = selection.new();
|
local sel = selection.new();
|
||||||
|
|
||||||
-- test set & get
|
-- test set & get
|
||||||
@@ -79,7 +79,28 @@ function test_selection()
|
|||||||
|
|
||||||
local sel2 = selection.clone(sel);
|
local sel2 = selection.clone(sel);
|
||||||
local sel3 = sel2:clone();
|
local sel3 = sel2:clone();
|
||||||
end -- selection_tests()
|
|
||||||
|
end -- test_selection_params
|
||||||
|
|
||||||
|
-- test negation
|
||||||
|
function test_sel_negate()
|
||||||
|
local sela = selection.negate();
|
||||||
|
local selb = sela:negate();
|
||||||
|
|
||||||
|
for x = 0,nhc.COLNO - 2 do
|
||||||
|
for y = 0,nhc.ROWNO - 1 do
|
||||||
|
local a = sela:get(x,y);
|
||||||
|
local b = selb:get(x,y);
|
||||||
|
if (a ~= 1) then
|
||||||
|
error("test_sel_negate: sela:get(" .. x .. "," .. y .. ")==" .. a);
|
||||||
|
end
|
||||||
|
if (b ~= 0) then
|
||||||
|
error("test_sel_negate: selb:get(" .. x .. "," .. y .. ")==" .. b);
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end -- test_sel_negate
|
||||||
|
|
||||||
|
|
||||||
test_selection();
|
test_selection_params();
|
||||||
|
test_sel_negate();
|
||||||
|
|||||||
Reference in New Issue
Block a user