reformatting for nhlua.c
This commit is contained in:
92
src/nhlua.c
92
src/nhlua.c
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.7 nhlua.c $NHDT-Date: 1579901146 2020/01/24 21:25:46 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.29 $ */
|
||||
/* NetHack 3.7 nhlua.c $NHDT-Date: 1580427882 2020/01/30 23:44:42 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.31 $ */
|
||||
/* Copyright (c) 2018 by Pasi Kallinen */
|
||||
/* NetHack may be freely redistributed. See license for details. */
|
||||
|
||||
@@ -254,7 +254,8 @@ lua_State *L;
|
||||
nhl_add_table_entry_int(L, "tx", ttmp->tx);
|
||||
nhl_add_table_entry_int(L, "ty", ttmp->ty);
|
||||
nhl_add_table_entry_int(L, "ttyp", ttmp->ttyp);
|
||||
nhl_add_table_entry_str(L, "ttyp_name", get_trapname_bytype(ttmp->ttyp));
|
||||
nhl_add_table_entry_str(L, "ttyp_name",
|
||||
get_trapname_bytype(ttmp->ttyp));
|
||||
nhl_add_table_entry_int(L, "tseen", ttmp->tseen);
|
||||
nhl_add_table_entry_int(L, "madeby_u", ttmp->madeby_u);
|
||||
switch (ttmp->ttyp) {
|
||||
@@ -321,7 +322,8 @@ lua_State *L;
|
||||
/* FIXME: some should be boolean values */
|
||||
nhl_add_table_entry_int(L, "glyph", levl[x][y].glyph);
|
||||
nhl_add_table_entry_int(L, "typ", levl[x][y].typ);
|
||||
nhl_add_table_entry_str(L, "typ_name", levltyp_to_name(levl[x][y].typ));
|
||||
nhl_add_table_entry_str(L, "typ_name",
|
||||
levltyp_to_name(levl[x][y].typ));
|
||||
Sprintf(buf, "%c", splev_typ2chr(levl[x][y].typ));
|
||||
nhl_add_table_entry_str(L, "mapchr", buf);
|
||||
nhl_add_table_entry_int(L, "seenv", levl[x][y].seenv);
|
||||
@@ -340,27 +342,42 @@ lua_State *L;
|
||||
lua_newtable(L);
|
||||
|
||||
if (IS_DOOR(levl[x][y].typ)) {
|
||||
nhl_add_table_entry_bool(L, "nodoor", (levl[x][y].flags & D_NODOOR));
|
||||
nhl_add_table_entry_bool(L, "broken", (levl[x][y].flags & D_BROKEN));
|
||||
nhl_add_table_entry_bool(L, "isopen", (levl[x][y].flags & D_ISOPEN));
|
||||
nhl_add_table_entry_bool(L, "closed", (levl[x][y].flags & D_CLOSED));
|
||||
nhl_add_table_entry_bool(L, "locked", (levl[x][y].flags & D_LOCKED));
|
||||
nhl_add_table_entry_bool(L, "trapped", (levl[x][y].flags & D_TRAPPED));
|
||||
nhl_add_table_entry_bool(L, "nodoor",
|
||||
(levl[x][y].flags & D_NODOOR));
|
||||
nhl_add_table_entry_bool(L, "broken",
|
||||
(levl[x][y].flags & D_BROKEN));
|
||||
nhl_add_table_entry_bool(L, "isopen",
|
||||
(levl[x][y].flags & D_ISOPEN));
|
||||
nhl_add_table_entry_bool(L, "closed",
|
||||
(levl[x][y].flags & D_CLOSED));
|
||||
nhl_add_table_entry_bool(L, "locked",
|
||||
(levl[x][y].flags & D_LOCKED));
|
||||
nhl_add_table_entry_bool(L, "trapped",
|
||||
(levl[x][y].flags & D_TRAPPED));
|
||||
} else if (IS_ALTAR(levl[x][y].typ)) {
|
||||
/* TODO: bits 0, 1, 2 */
|
||||
nhl_add_table_entry_bool(L, "shrine", (levl[x][y].flags & AM_SHRINE));
|
||||
nhl_add_table_entry_bool(L, "shrine",
|
||||
(levl[x][y].flags & AM_SHRINE));
|
||||
} else if (IS_THRONE(levl[x][y].typ)) {
|
||||
nhl_add_table_entry_bool(L, "looted", (levl[x][y].flags & T_LOOTED));
|
||||
nhl_add_table_entry_bool(L, "looted",
|
||||
(levl[x][y].flags & T_LOOTED));
|
||||
} else if (levl[x][y].typ == TREE) {
|
||||
nhl_add_table_entry_bool(L, "looted", (levl[x][y].flags & TREE_LOOTED));
|
||||
nhl_add_table_entry_bool(L, "swarm", (levl[x][y].flags & TREE_SWARM));
|
||||
nhl_add_table_entry_bool(L, "looted",
|
||||
(levl[x][y].flags & TREE_LOOTED));
|
||||
nhl_add_table_entry_bool(L, "swarm",
|
||||
(levl[x][y].flags & TREE_SWARM));
|
||||
} else if (IS_FOUNTAIN(levl[x][y].typ)) {
|
||||
nhl_add_table_entry_bool(L, "looted", (levl[x][y].flags & F_LOOTED));
|
||||
nhl_add_table_entry_bool(L, "warned", (levl[x][y].flags & F_WARNED));
|
||||
nhl_add_table_entry_bool(L, "looted",
|
||||
(levl[x][y].flags & F_LOOTED));
|
||||
nhl_add_table_entry_bool(L, "warned",
|
||||
(levl[x][y].flags & F_WARNED));
|
||||
} else if (IS_SINK(levl[x][y].typ)) {
|
||||
nhl_add_table_entry_bool(L, "pudding", (levl[x][y].flags & S_LPUDDING));
|
||||
nhl_add_table_entry_bool(L, "dishwasher", (levl[x][y].flags & S_LDWASHER));
|
||||
nhl_add_table_entry_bool(L, "ring", (levl[x][y].flags & S_LRING));
|
||||
nhl_add_table_entry_bool(L, "pudding",
|
||||
(levl[x][y].flags & S_LPUDDING));
|
||||
nhl_add_table_entry_bool(L, "dishwasher",
|
||||
(levl[x][y].flags & S_LDWASHER));
|
||||
nhl_add_table_entry_bool(L, "ring",
|
||||
(levl[x][y].flags & S_LRING));
|
||||
}
|
||||
/* TODO: drawbridges, walls, ladders, room=>ICED_xxx */
|
||||
|
||||
@@ -441,10 +458,10 @@ static int
|
||||
nhl_menu(L)
|
||||
lua_State *L;
|
||||
{
|
||||
static const char *const pickX[] = {"none", "one", "any"}; /* PICK_x */
|
||||
int argc = lua_gettop(L);
|
||||
const char *prompt;
|
||||
const char *defval = "";
|
||||
const char *const pickX[] = {"none", "one", "any"}; /* PICK_NONE, PICK_ONE, PICK_ANY */
|
||||
int pick = PICK_ONE, pick_cnt;
|
||||
winid tmpwin;
|
||||
anything any;
|
||||
@@ -506,7 +523,8 @@ lua_State *L;
|
||||
char buf[2];
|
||||
buf[0] = picks[0].item.a_char;
|
||||
|
||||
if (pick == PICK_ONE && pick_cnt > 1 && *defval && defval[0] == picks[0].item.a_char)
|
||||
if (pick == PICK_ONE && pick_cnt > 1
|
||||
&& *defval && defval[0] == picks[0].item.a_char)
|
||||
buf[0] = picks[1].item.a_char;
|
||||
|
||||
buf[1] = '\0';
|
||||
@@ -666,15 +684,16 @@ get_table_boolean(L, name)
|
||||
lua_State *L;
|
||||
const char *name;
|
||||
{
|
||||
static const char *const boolstr[] = {
|
||||
"true", "false", "yes", "no", NULL
|
||||
};
|
||||
/* static const int boolstr2i[] = { TRUE, FALSE, TRUE, FALSE, -1 }; */
|
||||
int ltyp;
|
||||
int ret = -1;
|
||||
|
||||
lua_getfield(L, -1, name);
|
||||
ltyp = lua_type(L, -1);
|
||||
if (ltyp == LUA_TSTRING) {
|
||||
const char *const boolstr[] = { "true", "false", "yes", "no", NULL };
|
||||
/* const int boolstr2i[] = { TRUE, FALSE, TRUE, FALSE, -1 }; */
|
||||
|
||||
ret = luaL_checkoption(L, -1, NULL, boolstr);
|
||||
/* nhUse(boolstr2i[0]); */
|
||||
} else if (ltyp == LUA_TBOOLEAN) {
|
||||
@@ -805,10 +824,17 @@ int anytype;
|
||||
void *src;
|
||||
{
|
||||
anything any = cg.zeroany;
|
||||
|
||||
switch (anytype) {
|
||||
case ANY_INT: any.a_int = *(int *)src; lua_pushinteger(L, any.a_int); break;
|
||||
case ANY_UCHAR: any.a_uchar = *(uchar *)src; lua_pushinteger(L, any.a_uchar); break;
|
||||
case ANY_SCHAR: any.a_schar = *(schar *)src; lua_pushinteger(L, any.a_schar); break;
|
||||
case ANY_INT: any.a_int = *(int *) src;
|
||||
lua_pushinteger(L, any.a_int);
|
||||
break;
|
||||
case ANY_UCHAR: any.a_uchar = *(uchar *) src;
|
||||
lua_pushinteger(L, any.a_uchar);
|
||||
break;
|
||||
case ANY_SCHAR: any.a_schar = *(schar *) src;
|
||||
lua_pushinteger(L, any.a_schar);
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -817,8 +843,7 @@ static int
|
||||
nhl_meta_u_index(L)
|
||||
lua_State *L;
|
||||
{
|
||||
const char *tkey = luaL_checkstring(L, 2);
|
||||
const struct {
|
||||
static const struct {
|
||||
const char *name;
|
||||
void *ptr;
|
||||
int type;
|
||||
@@ -848,6 +873,7 @@ lua_State *L;
|
||||
{ "uen", &(u.uen), ANY_INT },
|
||||
{ "uenmax", &(u.uenmax), ANY_INT },
|
||||
};
|
||||
const char *tkey = luaL_checkstring(L, 2);
|
||||
int i;
|
||||
|
||||
/* FIXME: doesn't really work, eg. negative values for u.dx */
|
||||
@@ -933,10 +959,10 @@ lua_State *L;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* read lua code/data from a dlb module or an external file, insert the
|
||||
file name as new first record so that we aren't at the mercy of whoever
|
||||
edits it to maintain that, and since we're forced to muck with messy
|
||||
details, replace comments with empty lines so that Lua won't need to */
|
||||
/* read lua code/data from a dlb module or an external file, insert the file
|
||||
name as new first record so that we aren't at the mercy of whoever edits
|
||||
it to maintain that, and since we're forced to muck with messy details,
|
||||
replace full-line comments with empty lines so that Lua won't need to */
|
||||
boolean
|
||||
nhl_loadlua(L, fname)
|
||||
lua_State *L;
|
||||
@@ -1095,8 +1121,8 @@ lua_State *
|
||||
nhl_init()
|
||||
{
|
||||
lua_State *L = luaL_newstate();
|
||||
luaL_openlibs(L);
|
||||
|
||||
luaL_openlibs(L);
|
||||
nhl_set_package_path(L, "./?.lua");
|
||||
|
||||
/* register nh -table, and functions for it */
|
||||
|
||||
Reference in New Issue
Block a user