Forum:Motivation for move to LUA?

From NetHackWiki
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 to . 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.