l_selection_filter_mapchar(L)
lua_State *L;
{
+ int argc = lua_gettop(L);
struct selectionvar *sel = l_selection_check(L, 1);
char *mapchr = dupstr(luaL_checkstring(L, 2));
xchar typ = check_mapchr(mapchr);
int lit = (int) luaL_optinteger(L, 3, -2); /* TODO: special lit values */
- struct selectionvar *tmp = selection_filter_mapchar(sel, typ, lit);
+ struct selectionvar *tmp, *tmp2;
if (typ == INVALID_TYPE)
nhl_error(L, "Erroneous map char");
- if (sel->map)
- free(sel->map);
- sel->map = tmp->map;
- if (tmp)
- free(tmp);
+ if (argc > 1)
+ lua_pop(L, argc - 1);
+
+ tmp = l_selection_push(L);
+ tmp2 = selection_filter_mapchar(sel, typ, lit);
+
+ free(tmp->map);
+ tmp->map = tmp2->map;
+ tmp2->map = NULL;
+ selection_free(tmp2, TRUE);
+
+ lua_remove(L, 1);
+
if (mapchr)
free(mapchr);
- lua_settop(L, 1);
return 1;
}
sel_pt_ne(seld, 6,4, 1, __func__);
end -- test_sel_grow
+function test_sel_filter_mapchar()
+ local __func__ = "test_sel_filter_mapchar";
+ local sela = selection.negate();
+ local sela_clone = sela:clone();
+
+ des.terrain(sela, ".");
+ des.terrain(5,5, "L");
+ des.terrain(15,10, "L");
+
+ local selb = sela:filter_mapchar("L");
+ sel_are_equal(sela, sela_clone, __func__);
+ sel_has_n_points(selb, 2, __func__);
+ sel_pt_ne(selb, 5,5, 1, __func__);
+ sel_pt_ne(selb, 15,10, 1, __func__);
+end -- test_sel_filter_mapchar
+
test_selection_params();
test_sel_negate();
test_sel_logical_and();
test_sel_fillrect();
test_sel_randline();
test_sel_grow();
+test_sel_filter_mapchar();