by corysama · 5y ago · 0 comments
If you are whipping up a command-line script because what you want is too complex to attempt in Bash, use Python. Lua is terrible for this.
If you are making an application from scratch using just the stand-alone interpreter, your scripts and a bunch of dependencies from the internets, use Python. People work really hard to make this semi-viable in Lua, but it is a path of frustration.
If you have your own C/C++ program and you want an easy path for configuring and composing features that are written in C/C++, deciding between Lua and Python depends on your goals.
Do you want MAXIMUM POWER for the scripter to whip together any crazy feature they might dream of? No concerns about footguns, hanging ropes or corner-painting? Memory and performance are secondary concerns to flexibility? Go use Python!
Do you want minimum power for the scripter so as to keep their creations constrained within a defined box? Is there a pre-defined role that the script will play? Are there definite restrictions on what should and should not be done in scripts? Are you going to be responsible in practice for debugging some monstrosities that the scripters build for themselves? Are performance and memory primary concerns above flexibility? Then Lua is well suited for embedding into your application.
It's unfortunate that Lua doesn't work well for this. The Lua implementation's light weight, portability and robustness [0] seem ideal for building these applications - especially for building applications that can be distributed to end-users (a scenario which is not a focus of Python [1]).
Obviously Lua is never going to include a large standard library because that conflicts with its embeddability. However, even in the Python community, “batteries included” is no longer considered entirely beneficial [2]. Instead, I think Lua would benefit from a set of officially recommended external libraries. This would improve the situation for people trying to write standalone applications in Lua, and I believe it would also help those who are writing scripts targeting embedded interpreters.
[0] https://www.lua.org/bugs.html
[1] https://twitter.com/gvanrossum/status/1347045076401147904
That said - the Lua ecosystem in 2021 is not the same as it was in 2005 or whenever people compare it to. There is a healthy amount of Libraries and choices of libraries for solving most tasks on Luarocks. And I would suggest you produce a better end project by selecting which libraries are included in your project that uses Lua for scripting. You can even further remove your choice of the libraries that _are_ included ootb.
[1] - https://github.com/rjpcomputing/luaforwindows
[2] - https://luapower.com/
[3] - http://luvit.io/
Back in games we put the whole game state (including ai routines written by designers using coroutines) in a 400kb preallocated block on a system that had only 8mb of system ram. Worked like a champ.
We'd also manually run a fixed number of GC steps per frame in our games. The higher average CPU use was worth the much lower variance.
I would rather use Tcl for that purpose :)
You can also get to a middle-ground state between "no batteries" and "just enough batteries" to get a large portion of the expected work done if the problem space is understood and has some bounds. E.g. including a library to make HTTP requests, parse JSON and work with an embedded SQL database will be enough for a lot of use-cases in the "user-defined glue logic on an existing application" space.
> "But no one is suggesting that a set of batteries become a requirement for Lua—even the existing Lua standard library can be compiled out for use cases where it is not needed"
It's great at filling that niche but if I want something like Python I just use Python.
If you have in-house coders who can't agree on what language to use, I guess WASM could allow them to agree to disagree. I'm not sure if that's a better path than using the languages' native tools and focusing on improving the compile-debug iteration time.
If you have external coder customers who will demand differing languages, WASM sounds great!
If you have external, semi-technical users who don't flat-out demand JavaScript-or-Die, standardizing on either Lua or Python is probably better for them both in terms of complexity and consistency of documentation and community help.
In general, for semi-technical users, see my above post on power levels.