Forum:Motivation for move to LUA?

From NetHackWiki
Revision as of 15:52, 19 October 2021 by Paxed (talk | contribs) (reply w actual link to lua adoc)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


Hi Gang!

Does anybody know offhand what the motivation was to use LUA as a new level description language? Does it bring new capabilities? Netzhack (talk) 11:11, 13 October 2021 (UTC)

Yes, it allows levels to be much more dynamic. Compare https://github.com/copperwater/xNetHack/blob/master/doc/lua.adoc to https://nethackwiki.com/wiki/Des-file_format . Testbutt (talk) 17:04, 13 October 2021 (UTC)

I can't speak to the devteam's motivations, so I'm not looking to argue why Lua was chosen over whatever other format. But having worked extensively with the special level code and themed rooms in xNetHack, I can say:
  • First, practically anything would be an improvement over des-file format. DES files, being a domain-specific language, complicated the build process by having to compile levels into binary format and requiring lex/yacc tools to make sense of the format. This also posed a huge maintainability problem, since any developer needed to clear a high bar in terms of learning the des format before being able to do anything, since none of it is standard.
  • Even worse if the developer wanted to change the capabilities of the special level parser, such as adding a new flag monsters could be specified with, because now in addition to learning DES, one now had to learn yacc and lex in order to understand how to change the DES language. Seriously, look at this and see how impenetrable it is if you're not into language design. Changing to something more standard, with its own documentation (plus lua.adoc for documentation of NetHack-specific extensions), alleviates much of this.
  • Lua offers a number of convenient built-in abstractions (key-value tables, functions as first-class objects, easily created lambdas) and it can do it with a much smaller overhead than another scripting language like Python (at least from the perspective of supporting older systems; if you have the Lua sources, all you need to link them into nethack is a C compiler).
  • DES is (sort of) declarative; Lua is procedural. That's a better paradigm for special levels, since the underlying C code is procedural too, and it's more natural to describe a level or themed room as a sequence of commands rather than a sequence of declarations. Also, setting and reusing variables, and reading the in-progress game state, makes more intuitive sense when it's procedural.
  • It's (probably) easier to hook into NetHack's c routines, though paxed would know way better than me about that since he was the one who set it up.

— Preceding unsigned comment added by Phol ende wodan (talkcontribs)

Okay, thanks for that. I see that Lua in itself is a powerful and documented language, but I'm still not sure what I can put in a special level made with Lua that I couldn't make with DES. (I had to get into DES this year to enforce equal-opportunity hiring of quest guardians, including a little bug-chasing in the level compiler.) I'm not being a stick-in-the-mud, just wondering what's been won. If I understand correctly, the idea is that in the future the generation of special levels may use the running game's state information? Netzhack (talk) 10:30, 19 October 2021 (UTC)
What Phol said above. Main reason was to remove the dependency to yacc/lex and make it easier to add stuff to the special levels, and lua specifically because it's pure C, has a small footprint, and is used in a lot of other projects too. Just take a look at lua.adoc and try to implement stuff like getmap or stairways in yacc/lex. --paxed (talk) 15:52, 19 October 2021 (UTC)