Lua pushkey and getlin · NetHack/NetHack@49a87bd · GitHub
Skip to content

Commit 49a87bd

Browse files
committed
Lua pushkey and getlin
Allow lua nh.pushkey to push multiple keys, make getlin return the keys in the command queue.
1 parent b9f8f84 commit 49a87bd

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

‎src/nhlua.c‎

Lines changed: 4 additions & 1 deletion

‎src/windows.c‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,6 +1867,27 @@ void
18671867
getlin(const char *query, char *bufp)
18681868
{
18691869
boolean old_bot_disabled = gb.bot_disabled;
1870+
char *obufp = bufp;
1871+
boolean got_cmdq = FALSE;
1872+
struct _cmd_queue *cmdq = NULL;
1873+
1874+
while ((cmdq = cmdq_pop()) != 0) {
1875+
if (cmdq->typ == CMDQ_KEY) {
1876+
got_cmdq = TRUE;
1877+
*bufp = (cmdq->key != '\n') ? cmdq->key : '\0';
1878+
bufp++;
1879+
if (cmdq->key == '\n')
1880+
break;
1881+
} else {
1882+
break;
1883+
}
1884+
}
1885+
1886+
if (got_cmdq) {
1887+
*bufp = '\0';
1888+
pline("%s %s", query, obufp);
1889+
return;
1890+
}
18701891

18711892
program_state.in_getlin = 1;
18721893
gb.bot_disabled = TRUE;

‎test/test_src.lua‎

Lines changed: 10 additions & 0 deletions

0 commit comments

Comments
 (0)