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