Expose stairway data to lua

This commit is contained in:
Pasi Kallinen
2021-06-24 18:55:20 +03:00
parent 420863252a
commit 1e7b75eb8b
2 changed files with 52 additions and 0 deletions

View File

@@ -253,6 +253,26 @@ Example:
local str = nh.s_suffix("foo"); local str = nh.s_suffix("foo");
=== stairways
Returns an array of stairway data. Each entry is a hash with the following keys:
|===
| x, y | location of the stairs on the map
| up | boolean, is it up stairs?
| ladder | boolean, is it a ladder?
| dnum | dungeon number where the stairs lead to
| dlevel | dungeon level where the stairs lead to
|===
Example:
local stairs = nh.stairways();
for k, v in pairs(stairs) do
nh.pline("stair[" .. k .. "]:(" .. v.x .. "," .. v.y .. ")," .. tostring(v.up));
end
=== verbalize === verbalize
Show the text in the message area as if someone said it, obeying eg. hero's deafness. Show the text in the message area as if someone said it, obeying eg. hero's deafness.

View File

@@ -18,6 +18,7 @@
static int nhl_dump_fmtstr(lua_State *); static int nhl_dump_fmtstr(lua_State *);
#endif /* DUMPLOG */ #endif /* DUMPLOG */
static int nhl_dnum_name(lua_State *); static int nhl_dnum_name(lua_State *);
static int nhl_stairways(lua_State *);
static int nhl_test(lua_State *); static int nhl_test(lua_State *);
static int nhl_getmap(lua_State *); static int nhl_getmap(lua_State *);
static void nhl_add_table_entry_bool(lua_State *, const char *, boolean); static void nhl_add_table_entry_bool(lua_State *, const char *, boolean);
@@ -880,6 +881,36 @@ nhl_dnum_name(lua_State *L)
return 1; return 1;
} }
/* local stairs = stairways(); */
static int
nhl_stairways(lua_State *L)
{
stairway *tmp = g.stairs;
int i = 1; /* lua arrays should start at 1 */
lua_newtable(L);
while (tmp) {
lua_pushinteger(L, i);
lua_newtable(L);
nhl_add_table_entry_bool(L, "up", tmp->up);
nhl_add_table_entry_bool(L, "ladder", tmp->isladder);
nhl_add_table_entry_int(L, "x", tmp->sx);
nhl_add_table_entry_int(L, "y", tmp->sy);
nhl_add_table_entry_int(L, "dnum", tmp->tolev.dnum);
nhl_add_table_entry_int(L, "dlevel", tmp->tolev.dlevel);
lua_settable(L, -3);
tmp = tmp->next;
i++;
}
return 1;
}
/* /*
test( { x = 123, y = 456 } ); test( { x = 123, y = 456 } );
*/ */
@@ -935,6 +966,7 @@ static const struct luaL_Reg nhl_functions[] = {
{"dump_fmtstr", nhl_dump_fmtstr}, {"dump_fmtstr", nhl_dump_fmtstr},
#endif /* DUMPLOG */ #endif /* DUMPLOG */
{"dnum_name", nhl_dnum_name}, {"dnum_name", nhl_dnum_name},
{"stairways", nhl_stairways},
{NULL, NULL} {NULL, NULL}
}; };