Commit Graph

42 Commits

Author SHA1 Message Date
Pasi Kallinen
7c44e06ab1 Dehardcode the monk minetown food shop conversion
Instead of trying to figure out in core whether to change a minetown
food shop to health food shop for monks, just figure it out in the
minetown level creation script.
2020-04-16 21:01:37 +03:00
Pasi Kallinen
d78dcdcb9b Allow matching any wall map terrain in lua scripts
When matching a terrain, allow using a "w" placeholder that matches
any solid wall:

For example:
   local s = selection.match([[w.w]]);
would match all floor locations with a wall to the left and right of it.
The walls can be solid stone, horizontal, vertical, etc.

This applies to selection.match(), selection.filter_mapchar(), and
des.replace_terrain()
2020-04-13 20:00:34 +03:00
copperwater
407f65aa8a Print out Lua error message when encountering an error
Rather than spitting out an error code number that is not particularly
useful. The string contains the line number and the nature of the error,
which is much more useful for debugging or reporting an issue.
2020-04-06 18:50:29 +03:00
Pasi Kallinen
e215f09ddb Fix even more warnings 2020-04-06 13:34:07 +03:00
nhmall
3bfb5a6c35 quiet windows x86 warnings
nhlua.c(628): warning C4244: 'function': conversion from 'lua_Integer' to 'int', possible loss of data
nhlua.c(644): warning C4244: 'function': conversion from 'lua_Integer' to 'int', possible loss of data
nhlua.c(646): warning C4244: 'function': conversion from 'lua_Integer' to 'int', possible loss of data
2020-04-01 12:58:36 -04:00
Pasi Kallinen
eec9c2e209 Expose core random number functions to lua
Expose nh.rn2() and nh.random() to lua.
Add a math.random() compatibility shim to nhlib.lua
2020-03-25 12:24:32 +02:00
Pasi Kallinen
00be8be45a Start of lua api docs
... in asciidoc format. Use "asciidoctor -b html5 lua.adoc"
to generate the HTML version.
2020-03-02 18:10:35 +02:00
nhmall
d81c096ce6 window port interface change - add mbehavior flags to start_menu()
Provide a way to communicate additional behaviors and/or appearances
desired from NetHack window port menus.

This is foundation work for changes to follow at a future date.
2020-02-20 20:12:51 -05:00
PatR
c03ed894de loadlua() simplification
nhl_loadlua() went from too simple to too complicated, now somewhere
in between.  Still doesn't assume that an entire file can be scooped
up with a single fread(), but no longer mucks about with the contents
of the file in order to insert a comment containing the file's name.
In order to have useful filename feedback in Lua error messages, just
use a different liblua routine to feed the file's contents to it.
2020-01-31 13:36:22 -08:00
PatR
162163c325 reformatting for nhlua.c 2020-01-30 15:44:55 -08:00
nhmall
183f9bca41 quiet a couple of warnings
..\src\nhlua.c(893): warning C4113: 'int (__cdecl *)()' differs in parameter lists from 'lua_CFunction'
..\src\nhlua.c(894): warning C4113: 'int (__cdecl *)()' differs in parameter lists from 'lua_CFunction'
2020-01-27 10:54:39 -05:00
PatR
dba6c20e2d loading Lua scripts
When loading a Lua script, modify it with a comment containing the
file name (or DLB module name) so that error reporting doesn't just
show the first 60 bytes of the script.  Also, don't assume that it's
possible to load an entire script in one fread().  Unfortunately
that got way out of hand and the result isn't pretty.  But something
of the sort is necessary.  (Reading the script into one string first
and then applying modifications while copying it into a second one
would probably be a lot cleaner than mixing the two operations.)

If a script starts with a comment or a blank line, the insertion of
the file name comment won't disturb the line number reported in an
error message.  But if the script starts out with code on its first
line, error reports will be off by one for the line number.  Showing
the file name is more useful than keeping that number accurate.
2020-01-24 13:26:01 -08:00
PatR
b2fa6292db Lua error reporting buffer overflow
nhl_error() was clobbering the stack.  I assume that the 'source'
field in the Lua debugging structure is normally a file name, but
nethack loads an entire Lua script into one long string because it
usually comes out of the DLB container, and 'source' contained the
full string.  That would overflow the local buffer in nhl_error()
if nethack encountered a Lua problem and tried to report it. (In
my case, the problem was in a level description file modification.)

[Not something under user control unless user can modify dat/*.lua
and put the result into $HACKDIR/nhdat.]
2020-01-24 12:52:35 -08:00
Pasi Kallinen
5e307335c3 Add missing NULLs to lua function reg array 2020-01-07 08:44:36 +02:00
Pasi Kallinen
1db0a5dda0 Fix unused param warning 2020-01-04 17:26:53 +02:00
Pasi Kallinen
1d312ee3fe Add some player lua methods
Adds u.clear_inventory() and u.giveobj(new.obj("rock")) and some other minor stuff.
2020-01-04 16:55:53 +02:00
Pasi Kallinen
6d8d3a9557 Add lua object references
Whenever a lua script references a core struct obj, increment a counter
in the obj struct. Core code will not free the obj, if there are any
lua references pointing to it, just makes it free-floating.
When lua script ends, the lua gc will free the free-floating objects.

Also exposes u.inventory to lua.

Breaks save and bones compat.
2019-12-26 19:15:24 +02:00
nhmall
308943aea4 groundwork for window port interface change to add_menu
groundwork only - window port interface change

This changes the last parameter for add_menu() from a boolean
to an unsigned int, to allow additional itemflags in future
beyond just the "preselected" that the original boolean offered.

There shouldn't be any functionality changes with this groundwork-only
change, and if there are it is unintentional and should be reported.
2019-12-22 18:28:24 -05:00
nhmall
b956e1a205 silence some compiler warnings that showed up recently 2019-12-15 14:03:25 -05:00
Pasi Kallinen
b24f4c5929 Expose traps to lua 2019-12-15 18:16:41 +02:00
Pasi Kallinen
7043e2134a Lua NetHack obj bindings 2019-12-11 20:10:59 +02:00
nhmall
a353202e87 more macosx Xcode warning quiets 2019-12-05 12:05:06 -05:00
nhmall
a701c5870d quiet a number of macosx warnings 2019-12-05 11:52:21 -05:00
nhmall
5e5217aceb more versioning bits 2019-12-01 19:38:47 -05:00
PatR
1603267cfa lua version bit 2019-12-01 16:33:01 -08:00
PatR
b7689128e7 mdlib.c tweaks
Eliminate a couple of warnings about unused static routines.
That led to a couple of other things.

I hope I got host vs target right in the mdlib.c '#if's.
2019-11-30 16:59:35 -08:00
nhmall
2a2021d5e4 use the copyright statement provided by the Lua distribution in lua.h 2019-11-30 18:43:57 -05:00
nhmall
7031b6b504 get lua version from lua itself 2019-11-30 17:23:14 -05:00
PatR
099fdca8cd no longer used variable 2019-11-29 15:59:50 -08:00
nhmall
453745701f casting lua_tointeger 2019-11-29 17:38:51 -05:00
Pasi Kallinen
f8a1059a87 Read lua files more efficiently
... replacing horribly hacky loop.
2019-11-29 21:49:03 +02:00
PatR
865607a392 3.7 Unix Makefiles
Copy lib/lua-$(VERSION)/src/liblua.h to lib/lua/ rather than lib/.

Instead of copying any of the header files or telling the compiler
where to find the lua ones, generate include/nhlua.h on the fly and
restrict the knowledge of where they are to it (paths are relative
to include/).

|/* nhlua.h - generated by top Makefile */
|#include "../lib/lua-5.3.5/src/lua.h"
|LUA_API int   (lua_error) (lua_State *L) NORETURN;
|#include "../lib/lua-5.3.5/src/lualib.h"
|#include "../lib/lua-5.3.5/src/lauxlib.h"
|/*nhlua.h*/

This might need to be redone (or augmented by having CFLAGS add back
'-I path-to-lua') if some compiler can't find '#include "luaconf.h"'
issued by lua.h.
2019-11-26 19:27:00 -08:00
PatR
8f5cca8e3d 3.7 build cleanup
Unix Makefile.utl wasn't aware of the dependency of makedefs.o on
src/mdlib.c so didn't rebuild makedefs when it should have.

Eliminate several warnings:
mdlib.c  - #if inside the arguments to macro Sprintf();
nhlua.c  - nhl_error() ends with a call to lua_error() which doesn't
           return, but neither of them were declared that way;
nhlsel.c - because of the previous, the 'else error' case of
           l_selection_ellipse() led to complaints about uninitialized
	   variables;
sp_lev.c - missing 'const'.

I did minimal testing which went ok, but revisiting a couple of levels
gave me un-freed memory allocated by restore.c line 1337.  (I haven't
looked at that at all.)
2019-11-24 17:56:01 -08:00
Pasi Kallinen
acf48fa305 Fix the lua integration parts marked for review
Also, explicitly allow traps of type "random".
2019-11-23 17:42:14 +02:00
Pasi Kallinen
cb4d350424 Fix unnecessary string copy 2019-11-20 21:20:35 +02:00
nhmall
29d378116e fix unplanned perm change 2019-11-15 22:22:19 -05:00
nhmall
298af2294f quiet some macosx warnings 2019-11-15 21:20:38 -05:00
Pasi Kallinen
4e438e0146 Use lua_tointeger instead of lua_tonumber 2019-11-07 19:28:58 +02:00
Pasi Kallinen
6dca5e0a49 Fix couple warnings
Alloc failure is already handled.
2019-11-07 18:13:48 +02:00
nhmall
223c31af0c some build fix-ups 2019-11-06 13:43:27 -05:00
Pasi Kallinen
9cd9280276 Lua: remove dgn_comp, use lua instead 2019-11-06 18:45:10 +02:00
Pasi Kallinen
fd55d9118e 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.
2019-11-06 18:43:20 +02:00