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

Function nhl_meta_u_index

src/nhlua.c:1963–2028  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1961DISABLE_WARNING_UNREACHABLE_CODE
1962
1963staticfn int
1964nhl_meta_u_index(lua_State *L)
1965{
1966 static const struct {
1967 const char *name;
1968 void *ptr;
1969 int type;
1970 } ustruct[] = {
1971 { "ux", &(u.ux), ANY_UCHAR },
1972 { "uy", &(u.uy), ANY_UCHAR },
1973 { "dx", &(u.dx), ANY_SCHAR },
1974 { "dy", &(u.dy), ANY_SCHAR },
1975 { "dz", &(u.dz), ANY_SCHAR },
1976 { "tx", &(u.tx), ANY_UCHAR },
1977 { "ty", &(u.ty), ANY_UCHAR },
1978 { "ulevel", &(u.ulevel), ANY_INT },
1979 { "ulevelmax", &(u.ulevelmax), ANY_INT },
1980 { "uhunger", &(u.uhunger), ANY_INT },
1981 { "nv_range", &(u.nv_range), ANY_INT },
1982 { "xray_range", &(u.xray_range), ANY_INT },
1983 { "umonster", &(u.umonster), ANY_INT },
1984 { "umonnum", &(u.umonnum), ANY_INT },
1985 { "mh", &(u.mh), ANY_INT },
1986 { "mhmax", &(u.mhmax), ANY_INT },
1987 { "mtimedone", &(u.mtimedone), ANY_INT },
1988 { "dlevel", &(u.uz.dlevel), ANY_SCHAR }, /* actually coordxy */
1989 { "dnum", &(u.uz.dnum), ANY_SCHAR }, /* actually coordxy */
1990 { "uluck", &(u.uluck), ANY_SCHAR },
1991 { "uhp", &(u.uhp), ANY_INT },
1992 { "uhpmax", &(u.uhpmax), ANY_INT },
1993 { "uen", &(u.uen), ANY_INT },
1994 { "uenmax", &(u.uenmax), ANY_INT },
1995 };
1996 const char *tkey = luaL_checkstring(L, 2);
1997 int i;
1998
1999 /* FIXME: doesn't really work, eg. negative values for u.dx */
2000 for (i = 0; i < SIZE(ustruct); i++)
2001 if (!strcmp(tkey, ustruct[i].name)) {
2002 return nhl_push_anything(L, ustruct[i].type, ustruct[i].ptr);
2003 }
2004
2005 if (!strcmp(tkey, "inventory")) {
2006 nhl_push_obj(L, gi.invent);
2007 return 1;
2008 } else if (!strcmp(tkey, "role")) {
2009 lua_pushstring(L, gu.urole.name.m);
2010 return 1;
2011 } else if (!strcmp(tkey, "moves")) {
2012 lua_pushinteger(L, svm.moves);
2013 return 1;
2014 } else if (!strcmp(tkey, "uhave_amulet")) {
2015 lua_pushinteger(L, u.uhave.amulet);
2016 return 1;
2017 } else if (!strcmp(tkey, "depth")) {
2018 lua_pushinteger(L, depth(&u.uz));
2019 return 1;
2020 } else if (!strcmp(tkey, "invocation_level")) {

Callers

nothing calls this directly

Calls 5

nhl_push_anythingFunction · 0.85
nhl_push_objFunction · 0.85
depthFunction · 0.85
Invocation_levFunction · 0.85
nhl_errorFunction · 0.85

Tested by

no test coverage detected