MCPcopy Create free account
hub / github.com/NetHack/NetHack / l_selection_match

Function l_selection_match

src/nhlsel.c:681–720  ·  view source on GitHub ↗

local s = selection.match([[...]]); */

Source from the content-addressed store, hash-verified

679
680/* local s = selection.match([[...]]); */
681staticfn int
682l_selection_match(lua_State *L)
683{
684 int argc = lua_gettop(L);
685 struct selectionvar *sel = (struct selectionvar *) 0;
686 struct mapfragment *mf = (struct mapfragment *) 0;
687 int x, y;
688
689 if (argc == 1) {
690 const char *err;
691 char *mapstr = dupstr(luaL_checkstring(L, 1));
692 lua_pop(L, 1);
693 (void) l_selection_new(L);
694 sel = l_selection_check(L, 1);
695
696 mf = mapfrag_fromstr(mapstr);
697 free(mapstr);
698
699 if ((err = mapfrag_error(mf)) != NULL) {
700 nhl_error(L, err);
701 /*NOTREACHED*/
702 }
703
704 } else {
705 nhl_error(L, "wrong parameters");
706 /*NOTREACHED*/
707 }
708
709 for (y = 0; y <= sel->hei; y++)
710 for (x = 1; x < sel->wid; x++)
711 selection_setpoint(x, y, sel, mapfrag_match(mf, x,y) ? 1 : 0);
712
713 /* unless the (0, 1) coordinate is a match, this would wind up with a
714 selection with lx=COLNO, hx=0, etc, so fix the boundaries */
715 selection_recalc_bounds(sel);
716
717 mapfrag_free(&mf);
718
719 return 1;
720}
721
722
723/* local s = selection.floodfill(x,y); */

Callers

nothing calls this directly

Calls 10

dupstrFunction · 0.85
l_selection_newFunction · 0.85
l_selection_checkFunction · 0.85
mapfrag_fromstrFunction · 0.85
mapfrag_errorFunction · 0.85
nhl_errorFunction · 0.85
selection_setpointFunction · 0.85
mapfrag_matchFunction · 0.85
selection_recalc_boundsFunction · 0.85
mapfrag_freeFunction · 0.85

Tested by

no test coverage detected