Use lua for special level files

Game is playable, and should compile on linux and Windows.
Assumes you have a lua 5.3 library available.

Removes level compiler and associated files.
Replaces special level des-files with lua scripts.
Exposes some NetHack internals to lua:
 - des-table with commands to create special levels
 - nh-table with NetHack core commands
 - nhc-table with some constants
 - u-table with some player-specific data (u-struct)
 - selection userdata

Adds some rudimentary tests.

Adds new extended command #wizloadlua to run a specific script,
and #wizloaddes to run a specific level-creation script.

nhlib.lua is loaded for every lua script.

Download and untar lua:
  mkdir lib
  cd lib
  curl -R -O http://www.lua.org/ftp/lua-5.3.5.tar.gz
  tar zxf lua-5.3.5.tar.gz

Then make nethack normally.
This commit is contained in:
Pasi Kallinen
2019-05-10 21:11:50 +03:00
parent 3e029d2900
commit fd55d9118e
189 changed files with 16653 additions and 27346 deletions

View File

@@ -22,8 +22,10 @@
char * trimspaces (char *)
char * strip_newline (char *)
char * stripchars (char *, const char *, const char *)
char * stripdigits (char *)
char * eos (char *)
boolean str_end_is (const char *, const char *)
int str_lines_maxlen (const char *)
char * strkitten (char *,char)
void copynchars (char *,const char *,int)
char chrcasecpy (int,int)
@@ -224,6 +226,31 @@ const char *str, *chkstr;
return FALSE;
}
/* return the max line length from buffer comprising of newline-separated strings */
int
str_lines_maxlen(str)
const char *str;
{
const char *s1, *s2;
int len, max_len = 0;
s1 = str;
while (s1 && *s1) {
s2 = index(s1, '\n');
if (s2) {
len = (int) (s2 - s1);
s1 = s2 + 1;
} else {
len = (int) strlen(s1);
s1 = (char *) 0;
}
if (len > max_len)
max_len = len;
}
return max_len;
}
/* append a character to a string (in place): strcat(s, {c,'\0'}); */
char *
strkitten(s, c)
@@ -468,6 +495,21 @@ const char *stuff_to_strip, *orig;
return bp;
}
/* remove digits from string */
char *
stripdigits(s)
char *s;
{
char *s1, *s2;
for (s1 = s2 = s; *s1; s1++)
if (*s1 < '0' || *s1 > '9')
*s2++ = *s1;
*s2 = '\0';
return s;
}
/* substitute a word or phrase in a string (in place) */
/* caller is responsible for ensuring that bp points to big enough buffer */
char *