8 ms·
Lua and Python (2020)
- speeder 6y agoLua is tied with C as my favourite languages. I personally DO use Lua sometimes to code general purpose stuff. Still, I don't see Lua ever having "batteries", the language wasn't invented for that purpose, and the original sponsor of the language wouldn't want it changing in that direction (I dunno if they still sponsor it though). Lua was invented by PUC-Rio (Catholic University, Rio de Janeiro campus) at the request of PETROBRAS, its purpose was "describe" stuff, and replace another language that they already had, plus being turing complete, because they got tired of hacking things endlessy whenever they needed to describe something "new" in their systems. So to "describe" stuff, Lua doesn't need libraries. That said... currently Lua most popular use is add some kind of scripting environment to other software, still that often means a library would be useless, and even then sometimes that usage is still to describe things, for example the game "Crusader Kings 2", use Lua to read a file named "defines.lua", and all it does is set some constants, another use of Lua that I find interesting is "xmake", Lua programs in it are very descriptive, using Lua syntax features to "tell" things to the system, instead of looking like anything resembling a normal imperative program. EDIT: about community size... yeah, it is tiny :( I never found a Lua job, companies that use Lua often hire a programmer of other languages and teach him Lua, I am also currently using PUC-Rio official GUI library (iup) and never found anyone else using it to ask questions about it, I've been in PUC-Rio during a tech event, and when I asked around if anyone knew where Lua authors were, the people that study and work there, didn't knew they had anything to do with Lua in first place!!!
- nerpderp82 6y agoHave I got a treat for you! http://terralang.org/ http://terralang.org/ https://github.com/pallene-lang/pallene https://github.com/pallene-lang/pallene
- karlmcguire 6y agoThanks for the pallene link! Terra was fun to play with but I've always wanted a simple compiled Lua.
- himujjal 6y agoNice info there. I recently started using xmake and for someone who is spoilt by npm, cargo and nimble i was really impressed by xmake. I finally dont have to write Makefiles. Lua is a very good choice for config files. Wezterm uses lua for configs. Lite editor uses lua only plugins and configs. And many more. Maybe someone/group of people can step up and declare an universal config format using lua for everyone. As for batteries, I would love to have that but wouldnt that again defeat the whole purpose of Lua as embeddable? But of course people would love to have it.
- centimeter 6y agoCheck out https://dhall-lang.org https://dhall-lang.org . It's kind of like a new approach to Lua, but strongly typed and turing-incomplete.
- Buttons840 6y agoCan it be used outside of the Haskell ecosystem?
- centimeter 6y agoYeah, there are interpreters for many languages and the output can be written to json (assuming it contains no functions).
- gugagore 6y ago> So to "describe" stuff, Lua doesn't need libraries. Maybe you can clarify what "describe" means. It reminds me of the subtle-possibly-false dichotomy between a program and a configuration. Turing-completeness could be one way to think about that dichotomy it, but in this case Lua is definitely Turing complete. In any case, if there's commonality to the stuff being described, then that's the kind of thing that is "batteries". Sequences, associative arrays, etc. come up all the time, and that's available. Surely there are some things that come up a bit less often when describing systems, though I don't have a concrete example on hand. My main question is, since any program is a description of a computation, then what kind of distinction are you making?
- hisham_hm 6y ago> I personally DO use Lua sometimes to code general purpose stuff. Speaking of general purpose application programming, you might be interested in my new(ish) project Teal: https://github.com/teal-language/tl https://github.com/teal-language/tl It's a statically typed dialect of Lua, which is compatible with all modern Lua versions. The core compiler itself is one tl.lua file which can be added to any Lua project, and includes a Lua package loader that makes Lua's `require()` support .tl files, and there's also a tl CLI for generating .lua from .tl files.
- deleted 6y ago[deleted]
- monoideism 6y agoI'm surprised there was no mention of Penlight in that article. Penlight, a supplemental standard library for Lua that is heavily inspired by Python's own standard library, has been around for years now: https://github.com/lunarmodules/Penlight https://github.com/lunarmodules/Penlight
- nightowl_games 6y agoAs someone who's barely used lua (only when forced to), I dont get it. There error messages aren't great, the 1-indexed arrays, the syntax is super weird. I understand there is good technical aspects to the language, but I am really thrown off by the syntax. I get that that could go away with time, but I have no reason to believe that "learning lua" would actually bear any fruit. Part of me is convinced that Lua is liked simply because it's unpopular, and that if it was used in production more, people would hate it. Kinda like we hate javascript and c++. Maybe it's that we hate our jobs, and blame the language, and then we go home and screw around in lua, we enjoy ourselves and blame the language. EDIT: Just to piggy back on my comment here: I've been optimistically looking at the wren scripting language. That seems like the "correct" way to make a scripting language, at least from the outside. I should make it clear that I am not speaking from a position of authority, but I am sharing my opinion of LUA as a pessimistic outsider, which I think is very common view. [1] https://wren.io/ https://wren.io/
- allthetime 6y agoI only use it to extend redis. I don't love lua, but I like what it does inside redis.
- tyree731 6y agoHaving used Lua a fair bit in the past year (in order to write custom plugins for Kong), the main draw (and in some cases, drawback) for me with Lua is its integration of coroutines. Draw as it makes writing event-driven code dead simple, with coroutines managed behind the scenes as you write code serially. Drawback as if you pull in the wrong library, one that does something in a blocking fashion (such as with a c module that doesn’t “get” Lua), you can get into some trouble. In terms of syntax it’s basically JavaScript with stupid array indexing, which is enough to turn people off I’m sure.
- yumaikas 6y agoSo, I like Lua as a language, but I think that Janet, 5 years down the road, will be a better fit for a "Lua+Batteries", for people that can stomach parens. It's already well on it's way there now.
- 6y ago
- kureikain 6y agoThing like JSON, make HTTP request all require external lib in Lua. It makes thing harder for first time user. I think at least JSON or HTTP client lib should be included? One of my use case is use Lua as an OAuth proxy, run inside Nginx, or use Lua as a S3 Proxy(with sign signature etc) and dealing with XML/JSON/HTTP Request is hard in Lua. When I installed an external lua rocks, for it to be embeded inside Nginx, I have to make sure lua lib path are sync between luarock/nginx. I don't know how to solve that problem other than reading the document. But explains all of them to a new comer to Lua/Nginx is hard. It takes a lot of time until they can write code.
- pull_my_finger 6y agoThis is actually documented by OpenResty [1] [1] - https://openresty.org/en/using-luarocks.html https://openresty.org/en/using-luarocks.html
- ZoomZoomZoom 6y agoLua is a bit weird and I think it's actually the strong point in favour of Lua (besides the obvious: nice performance and great portability). We need more variability to explore different ways to achieve our goals and to suit widest range of preferences. I'd love to see a big and strong standard library for the language to see it used for wider variety of tasks. In my extremely limited experience with Lua, the only thing that I definitely didn't like was its weak-ish dynamic typing, so I'd been keeping my eye on tl[1] and wu-lan[2] which both transpile to Lua for a while. 1. https://github.com/teal-language/tl https://github.com/teal-language/tl 2. https://github.com/wu-lang/wu https://github.com/wu-lang/wu
- stretchcat 6y agoReal regex would be nice. I understand not going full beans with the batteries, but surely a few more wouldn't go amiss? Perhaps a 'battery' for formatting a Lua table as a string, since tables are such a big deal in Lua? This would help immensely when debugging scripts during development.
- ziml77 6y agoA built-in function to convert a table to a string would be great. It's not hard to write one myself but tables are so core to the language and printing them is handy for debugging and exploration.
- ufo 6y agoFor more complex string matching tasks that the built-in patterns cannot handle, LPeg might be a good choice. I think it's not likely that something like PCRE-compatible regular expressions would be included in the Lua standard library because PCRE is fairly large, by Lua standards. By the way, for formatting Lua tables for debugging I like using "inspect". (It's not part of the standard library but oh well, that's the whole topic of today's discussion). http://www.inf.puc-rio.br/~roberto/lpeg/ http://www.inf.puc-rio.br/~roberto/lpeg/ https://github.com/kikito/inspect.lua https://github.com/kikito/inspect.lua
- stretchcat 6y agoSure PCRE support would be big, but even posix-style BRE would be a very welcome improvement I think. (As for formatting tables, presently most of my Lua code has been written for mpv which has a builtin utils.to_string(v) for this purpose. In the manpage, this is documented as "only needed because Lua is terrible." I think that's a bit too far, but the frustration this must have caused really comes across.)
- pull_my_finger 6y ago> PCRE support would be big I have to say, once I learned to appreciate the combo of Lua's builtin pattern matching (no not _that_ kind of pattern matching) and LPEG, I really loathe having to use cryptic regexp's in languages like JS. Patterns are enough for most stuff, and when you want to get into more complex patterns, a PEG (LPEG in particular) is much more readable and expressive than a regex that would come out looking like a generated password.
- narrationbox 6y agoLua is a great language, but the fragmentation between versions makes it difficult to be adopted outside of niche embedded areas. On a side note, we maintain a Lua newsletter but haven't had time to update it. This article looks perfect for a new edition. https://luadigest.netlify.app https://luadigest.netlify.app
- PLenz 6y agoNeeds a (2020) - this article is a year old
- andrewmcwatters 6y agoI agree with speeder in that Lua and C are probably two of my most favorite languages. I think developers come away with that feeling for the same ideological reasons. Lua is also hands down the easiest programming language to embed. There's just no comparison. LuaJIT's C FFI also makes embedded work ludicrous.
- vlmutolo 6y agoWow, I was prepared to argue the “arrays shouldn’t start at zero” bit of your comment, but it disappeared. I had a link to Dijkstra and everything. https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/E...
- shadowgovt 6y agoI once wrote a system where we chose Lua as the scripting language specifically because of its lack of batteries. When embedding a language in another system, you have to worry about the abstractions the standard library enforces upon the rest of your system if those abstractions are deep. Far better, for our purposes, to use a language with an absolute handful of primitive types and build abstractions atop it.
- Pfhreak 6y agoI've used Lua professionally and for hobby projects, and it's near the bottom of my list for languages I'd reach for in any context. There's a significant mental lift for me to be productive in Lua, there are tons of weird gotchas, and I find it to be super verbose. Even basic stuff like parsing JSON I end up having to go rummage around for support for. These days, I'll use javascript or python for my smaller needs, and I'd much rather have a JS runtime embedded than a Lua one for any game scripting I'm doing.
- deleted 6y ago[deleted]
- metreo 6y agoInteresting as I've just recently turned to learning Lua for use precisely as it is described as a "scripting language". Out of several dozen alternatives (the other scripting languages from a list on Wikipedia), my analysis is that Lua offers a very compelling and attractive technical profile. I haven't been using it long, but so far I haven't seen evidence otherwise. Prior to Lua I would have used Bash, or maybe Python in a pinch.
- aidenn0 6y agoI may just use python for different things than other people, but it's rare for me to see a script that doesn't have at least one external dependency.
- grawprog 6y agoI like lua, it's the language that really made me start to 'get' programming. It's great for lots of things, but it does have some weirdness I find makes some tasks a little more difficult. The lack of 'batteries' has never really been something that's bothered me with lua. A few other things though: The starting arrays from one thing, while not that big of a deal, can be a bit annoying, especially if you're using lua and c together. You've just always kind of got to be aware of it. Tables and metatables are great, until they're not. Lack of true integers(at least when I used it) made at least one task I tried to use lua for unfeasible and I had to use a different language in the end. In the end though, lua's still probably my favourite scripting language to write in.
- spc476 6y agoLua has had true integers (and binary operators) since version 5.3, released in January of 2015.
- capitainenemo 6y agoYeah, but adoption is slow. Nonetheless, looking forward to it. Hedgewars uses deterministic lockstep, and the various creative ways in which floating point is calculated really mess up games like this. 0AD and Spring discovered this in the past as well - so the result is scripters have to be very careful when using math, and Hedgewars had to expose its own bitops and integer division for lua scripting. http://hedgewars.org/kb/LuaRules http://hedgewars.org/kb/LuaRules - I see someone wrote some hopefully correct guide on that last point.
- spc476 6y agoYes, Lua 5.1 was a very good version. Lua 5.2 made some significant changes in how global variables work, which lead to a split between Lua and LuaJIT [1][2]. Lua 5.3, with true integer support [3] and some UTF-8 support made for a compelling reason to update. Lua 5.4 is out now with support for a more deterministic way to release resources. I think LuaJIT being mostly stuck with Lua 5.1 is a cause for the lack up uptake on more modern versions of Lua. [1] Mike Pall, creator of LuaJIT, disagreed with the direction that Lua 5.2 went and remained with Lua 5.1 semantics. [2] I personally found Lua 5.2 a "meh" version and didn't bother upgrading. [3] Including some functions to pack and unpack integers and floats into strings, in both big-endian and little-endian formats.
- corysama 6y agoI think a lot of people complain about Lua because they are trying use use it as a Python alternative. Lua and Python are suited for very, very different tasks. 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.
- greenshackle2 6y agoYes, this. We use Lua for embedding and even the few batteries were more than we wanted. We stripped out file and network I/O and some other stuff I can't remember right now.
- einpoklum 6y ago"Batteries included" doesn't mean you have to _use_ the included batteries... or like Lorenzo Donati says in the article: > "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"
- greenshackle2 6y agoSure, yeah, you can try to make future Lua do both what current Python and current Lua do well. I, personally, don't see the appeal, because Python already exists - the only reason I use Lua is that it fills a niche that Python doesn't. It's great at filling that niche but if I want something like Python I just use Python.
- genericone 6y agoI use Lua daily at work for implementing new features for our robot offerings. One of our motion equipment suppliers had an existing set of products for industrial automation which were originally programmed in C++, but also offered a more standards compliant version for doing PLC programming. My employer negotiated very early on ( pre 2000 ) for them to provide a simpler interfacing layer, and we got Lua libraries as a result. Now we do the bulk of our automation equipment programming using a fully featured Lua library, which interfaces with the core controller/amplifier/motor/sensor/IO libraries already present on their original product. A sizeable portion of our equipment now are programmed purely in Lua, and we work closely with said supplier so that they update the library when a feature deficiency is noted. Wish I could say more about it, but you can count me in the group that enjoys programming in Lua, and does it daily. I'm not using it for general purpose software, its for a highly specific use case that is tied very tightly to proprietary hardware unavailable for purchase without purchase contracts, so this is very different from what normal programmers might have to deal with.
- scythe 6y agoPython is extremely popular in education and I'm convinced this is a huge part of its overall popularity. In that, it displaced Java in a move wildly popular with students; the language designers practically targeted college classes. But professors are conservative and won't usually change languages unless there is a compelling advantage. So, you might think Lua can't compete with Python in education. But we have an ace in the hole: concurrency. Lua can be a great sandbox for learning concurrent programming, with built-in coroutines and a reentrant interpreter on top of an extremely simple semantics and basic type system. The problem is that nobody is going to want to use an ad hoc combination of Lua and some questionably maintained 3P libraries to teach a course. If Lua is to be useful for teaching parallel programming, it needs a built-in or at minimum endorsed solution for parallelism. Penlight, probably the most popular "Lua batteries" collection, includes almost everything except parallelism! Another issue in education, though, is 1-based arrays. They're a minor annoyance in practice, but learning to count from zero is important in many CS courses.
- antattack 6y agoEspressif IoT line (ESP8266) took off in part because of NodeMCU that used Lua firmware.
- zubspace 6y agoOn the last advent-of-code I thought, that I should give Lua a try. But geez, on windows I really had a rough start. First and foremost there is no easy guide how to even get started. Do you need MSYS2? TDM-GCC? Should I use WSL? Are there any precombiled binaries? Is there an editor? Then by sheer luck I found the ZeroBrane Editor [1] and was quite excited. Simple installation, everything included, autocomplete and debugging! Awesome. The first thing I had to do was trimming a string. Oh Boy! [2] I mean really.. As a beginner, this completely wrecked me. I have a task to do, why should I worry about which Trim implementation is best? Switched to Nim (which I had not used before either) and never looked back. [1] https://studio.zerobrane.com/ https://studio.zerobrane.com/ [2] http://lua-users.org/wiki/StringTrim http://lua-users.org/wiki/StringTrim
- severak_cz 6y agoThat string trim problem is easily solved - just copy&paste one of these functions to your code.
- soapdog 6y agoI started typing a really long response here to address many of the comments I have been reading. In the end, it was becoming a huge wall of text, which is not something that I think this site is suitable for. So, I wrote a blog post about it instead: https://andregarzia.com/2021/01/lua-a-misunderstood-language.html https://andregarzia.com/2021/01/lua-a-misunderstood-language... I'm speaking from the point-of-view of someone who used Lua for games, hardware, and web, in there. I am not an expert in the language, but I feel that many people here are approaching the language with the wrong perspective, and thus are unable to see what makes it great. All I write there is my own personal opinion of course, I'm totally OK if you still hate Lua after reading it, but I'd encourage those here who have criticism about it to double check my article and reach out if they want to talk more about it.
- severak_cz 6y agoLua was basically made as tool for making scripting environment for your app. It has minimal batteries because it's up to you to provide functions/API for your scripts. I personally like lua because it's conceptually very simple. It has just eight basic types and that's all. Also it does not dictate you how to use it. It provides mechanisms, not policies.
- einpoklum 6y agoFrom the article: > "Everyone has different needs so the places where serious money is getting poured into using Lua don't really have much of an incentive to standardize -- it wouldn't give them any benefit." I really don't think that's true. It _is_ true that a standard library doesn't cater to single developers' or companies specific, custom needs and performance tradeoffs. But that's only true for limited parts of the code. Most of an application's code is not the critical "secret sauce", and typically, we are well served with standard library facilities. We simply don't use the small part where we need something different. It's like that for basically any high-level language, I believe; and standardization is desirable and appreciated. Are we really to believe that most big LUA users need their own regex library for LUA? Their own sqlite library? etc.
- sosodev 6y agoThis is really timely article for me. I just chose to use Lua in a brand new project (https://github.com/Hyperspace-Logistics/heart https://github.com/Hyperspace-Logistics/heart) and lot of the criticism so far has been “why Lua?” Personally I think it’s very capable language. It’s such a comfortable scripting language that I think nearly anybody could pick it up and get up to speed pretty quickly. LuaJIT is also ridiculously powerful and so satisfyingly stable (Lua 5.1 for over a decade). Heck Lua 5.1 even makes an excellent transpile target so you might not even need to use Lua to appreciate the software that runs Lua.
- ivan_ah 6y agoRE > "an official list of approved Lua libraries", which could be searched and that would provide information on the strengths and weaknesses of the library Perhaps something to emulate could be https://djangopackages.org/ https://djangopackages.org/ which has repeatedly helped me with "how do I do X" questions in the context of Django web projects.