Expose stairway data to lua
This commit is contained in:
20
doc/lua.adoc
20
doc/lua.adoc
@@ -253,6 +253,26 @@ Example:
|
||||
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
|
||||
|
||||
Show the text in the message area as if someone said it, obeying eg. hero's deafness.
|
||||
|
||||
32
src/nhlua.c
32
src/nhlua.c
@@ -18,6 +18,7 @@
|
||||
static int nhl_dump_fmtstr(lua_State *);
|
||||
#endif /* DUMPLOG */
|
||||
static int nhl_dnum_name(lua_State *);
|
||||
static int nhl_stairways(lua_State *);
|
||||
static int nhl_test(lua_State *);
|
||||
static int nhl_getmap(lua_State *);
|
||||
static void nhl_add_table_entry_bool(lua_State *, const char *, boolean);
|
||||
@@ -880,6 +881,36 @@ nhl_dnum_name(lua_State *L)
|
||||
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 } );
|
||||
*/
|
||||
@@ -935,6 +966,7 @@ static const struct luaL_Reg nhl_functions[] = {
|
||||
{"dump_fmtstr", nhl_dump_fmtstr},
|
||||
#endif /* DUMPLOG */
|
||||
{"dnum_name", nhl_dnum_name},
|
||||
{"stairways", nhl_stairways},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user