17 ms·
Lua is so underrated
- up2isomorphism 2y agoUntil its array start from 1.
- transpute 2y agoIf you like Lua, see Terra, https://terralang.org/ https://terralang.org/ > Terra is a low-level system programming language that is embedded in and meta-programmed by the Lua programming language.. Like C/C++, Terra is a statically-typed, compiled language with manual memory management. But unlike C/C++, it is designed from the beginning to be meta-programmed from Lua.. In Terra, we just gave in to the trend of making the meta-language of C/C++ more powerful and replaced it with a real programming language, Lua.. Terra programs use the same LLVM backend that Apple uses for its C compilers. This means that Terra code performs similarly to equivalent C code. From Pat Hanrahan's research group at Stanford, https://amturing.acm.org/award_winners/hanrahan_4652251.cfm https://amturing.acm.org/award_winners/hanrahan_4652251.cfm Hanrahan and his students developed Brook, a language for GPUs that eventually led to NVIDIA’s CUDA. The prevalence and variety of shading languages ultimately required the GPU hardware designers to develop more flexible architectures. These architectures, in turn, allowed the GPUs to be used in a variety of computing contexts, including running algorithms for high performance computing applications, and training machine learning algorithms on massive datasets for artificial intelligence applications. Papers: https://terralang.org/publications.html https://terralang.org/publications.html
- trott 2y ago> Terra programs use the same LLVM backend that Apple uses for its C compilers. Can it use anything else (as an option), e.g. Lua? That would be useful during development/debugging thanks to faster iteration and memory safety.
- transpute 2y agoLLVM would not be easily replaced, https://chriscummins.cc/2019/llvm-cost/ https://chriscummins.cc/2019/llvm-cost/ > 1.2k developers have produced a 6.9M line code base with an estimated price tag of $530M.
- ajb 2y agoAlthough it's true that replacing LLVM like-for-like would indeed be expensive, I feel like you missed GP's point. To make the easier to debug, what you want is to replace LLVM with something simple, like a plain interpreter. And writing one (or adapting one) would be nothing like this cost.
- transpute 2y agoAny precedent example for an LLVM-hosted language? There are benefits from being on the same toolchain as popular languages.
- dvtkrlbs 2y agoRust is experimenting with a codegen tool called cranelift which powers wasmtime. The plan is to use it for debug builds. There is also a backend implementation in the works using gcc jit and a dotnet backend as well
- brabel 2y agoZig is actually trying to get rid of LLVM for default builds, though they intend to keep it as one of the "backends" for the forseeable future. The problem is that LLVM is very slow (as it applies lots of optimisations) and heavy, and that makes a compiler slow even in debug mode. D has 3 backends, LLVM is used by the LDC compiler. Then there's DMD which is the official compiler (and frontend for all three), and GDC which uses GCC backend. D code typically compiles quite a bit faster on DMD, but the code is more highly optimised with LLVM or GCC, of course. It's a great tradeoff specially since all compilers use the DMD frontend so it's almost guaranteeed that there's no differences in behaviour between them.
- emmanueloga_ 2y agoBoth Terra and Extempore [1] implement the same basic idea, which is provide a way to generate performant machine code on the fly but keeping a language surface that feels like you are working with a dynamic language (Lua or Scheme correspondingly). I think Scopes [2] could be mentioned here too. The concept is really cool and different from JIT compiling in that the developer is given the tools to generate machine code, as opposed to some "magic" JIT compiling happening opaquely behind the scenes. That being said, I don't think either of these languages is practical for real world projects for several reasons: lack of (or low quality) documentation, bus factor (lack of developers), tiny communities, lack of tools, lack of libraries, etc etc etc. -- 1: https://extemporelang.github.io/ https://extemporelang.github.io/ 2: https://sr.ht/~duangle/scopes/ https://sr.ht/~duangle/scopes/
- transpute 2y ago> I don't think either of these languages is practical for real world projects Maybe not yet, but prior work by this research team eventually lead to CUDA. Terra may be useful as a productivity DSL for some high-performance computations, e.g. listed in their papers: our DSL for stencil computations runs 2.3x faster than hand-written C our serialization library is 11 times faster than Kryo our dynamic assembler is 3–20 times faster than Google’s Chrome assembler 2021 HN thread, https://news.ycombinator.com/item?id=27334065 https://news.ycombinator.com/item?id=27334065 > Terra is a workhorse and it gets the job done.. Having first-class code generation capabilities has been really nice, especially with built-in support for things like parsing C header files, vectorization, and CUDA code generation. The language is stable and generally doesn't have many surprises. Unlike, say, C++ or Rust, there aren't as many corners to hide odd behaviors.
- brabel 2y ago"I am here to warn you, traveler, that Terra sits on a throne of lies. I was foolish. I was taken in by their audacious claims and fake jewels. It is only when I finally sat down to dine with them that I realized I was surrounded by nothing but cheap plastic and slightly burnt toast." Source: https://erikmcclure.com/blog/a-rant-on-terra/ https://erikmcclure.com/blog/a-rant-on-terra/
- transpute 2y agohttps://news.ycombinator.com/item?id=27337278 https://news.ycombinator.com/item?id=27337278 > Please note: The entire "windows" portion of that article has largely been resolved at this point, because I fixed it myself.
- almostgotcaught 2y agoy'all realize that this thing (terra) was a phd project that is (for a long time) fully abandoned by the guy that did the phd (zach) right? > Terra programs use the same LLVM backend that Apple uses for its C compilers lol is this a flex? or is it just dated? everyone uses LLVM for all of their compilers.
- transpute 2y agoFortunately, open-source projects can have more than one contributor. 2024 commit log includes: Bump CI to macOS 13 Add AVX512 support Update LuaJIT Document AMD, Intel, Nvidia GPU support Add support for LLVM18 Support SPIR-V code generation
- almostgotcaught 2y agoI'm well aware but consider what it means that the guy that created it has walked away from it
- PicassoCTs 2y agoPeople change, interests wander. The guy who made brainfuck wrote parts of the sauerbraten engine. Is that a betrayal of brainfuckery?
- transpute 2y agoIf the project is actively maintained after 10 years, it means he created a sustainable foundation. If you're aware of specific open issues with the project, identified by the founder or others, please share details.
- almostgotcaught 2y agodo you understand that "use one language to emit another language that is then immediately compiled" is literally like hundreds of languages now? numba/cupy/pytorch/jax/julia/etc/etc/etc. they all implement both a high level IR that can be transformed via the high level language (python) and a JIT/compiler/whatever. so like why would i ever use this thing terra+lua+"5 guys maintaining it in a basement somewhere" thing?
- miohtama 2y agoI guess one of the issues is that because Lua is tailored for embedded use case, it lacks appeal as a general purpose software development ecosystem and thus its usage is marginal.
- hinkley 2y agoIt’s been adopted in game engines to handle story logic, so the people writing the game can be decoupled from the people writing the engine, and don’t have to code in a low level language against a constantly moving target. And I would argue that a lot of the staying power of World of Warcraft came from the Lua based addons democratizing the UI. Blizzard co-opted a lot of features from best of breed addons back into the base game. (That and negative pressure in the economy to keep from having every new character wielding the third best sword in the game due to deflation, but that’s a story for a different thread)
- arccy 2y agoLua is nice but it being embedded in many different places means that there will often be environment specific context that's injected for you to interact with, but any editor tooling won't know what's injected
- pseudony 2y agoNot necessarily true. LuaLS, the most popular LSP, uses LuaCATS (Lua comments and type system) annotations. You can place annotation files (type stubs) in a directory and the LSP will pick them up. I use this for a project of mine where I embed a Lua interpreter where I made several additional Lua modules available.
- leptons 2y agoI ran into this recently with OBS scripting. I don't really like Lua, so I wanted to try making a Typescript-to-Lua toolchain specifically for OBS scripting. Well OBS injects a ton of stuff into the Lua environment, and I'd have to find a way to mock all of that in Typescript. Sadly, I don't have time for it, and I've chosen a different product than OBS because I don't really want to invest so much time learning a new language to accomplish something with free software when I can purchase something that just works for $40. My time is way more valuable, and this is the only time I've ever needed to code something in Lua. Yeah, OBS supports Python too, but I dislike Python even more than Lua.
- kragen 2y agoI'm surprised to hear that there's proprietary software that's competitive with OBS Studio. What is it?
- leptons 2y agoI just needed a program to capture a portion of the screen under my mouse and stream it as a webcam device to Zoom, so I can screen cast a portion of my gigantic workstation desktop (6480x3840) to people with 1920x1080 screens, while following my mouse cursor around. OBS was one stop along my journey to get there, as there's some Lua and Python scripts that achieve something similar, but not quite exactly what I wanted with multi-screens, so I began trying to modify the script to do what I needed it to do. In the end I'm going with something called "SparkoCam" which achieves this easily with no hassle, but it costs $40. Since $40 is less than what an hour of my time is worth, it was kind of a no-brainer to abandon the hassles of learning Lua (a many hour detour) and fiddling with OBS Studio to get what I wanted. I have no real use for Lua outside of this, so it would be time wasted on this one project.
- EGreg 2y agoIs Lua currently even faster than JS and PHP, after all the effort that went into those languages’ optimizations?
- shakna 2y agoIt depends. In Debian's [0][1] benchmarks, JS is clearly ahead in a handful of the benchmarks, but in the rest, Lua is either on-par or faster. They're within a shout of each other. There are some places where Lua has surprisingly poor performance. However, in almost everything else, it's one of the fastest around. Luajit is still one of the fastest JITs in existence. In the real world, rather than constraints of a benchmark, Lua tends to be on-par from what I've seen. When you're not cold-cacheing everything, its memory use is lower. But it's standard library is ISO-C, and that's about it. No batteries. And the others beat it soundly there, whilst being close to the same performance. Which will mean they will just about always win out. [0] https://benchmarksgame-team.pages.debian.net/benchmarksgame/measurements/lua.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/... [1] https://benchmarksgame-team.pages.debian.net/benchmarksgame/measurements/node.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
- igouy 2y ago> a handful of the benchmarks Now made a little easier for your comparison https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/node-lua.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
- Rochus 2y agoThanks. I calculated the geomean of the speed-up factors based on the average results (cpu secs) per benchmark. Overall, Lua 5.4.6 is factor 5.1 slower than V8 v23. Only in k-nucleotide Lua is slightly faster than V8, but in n-body Lua is even factor 26 slower. Btw. it seems notable that Lua 5.4.6 is about 40% slower than Lua 5.4.1, see http://software.rochus-keller.ch/are-we-fast-yet_Lua_results_2024-06-20.pdf http://software.rochus-keller.ch/are-we-fast-yet_Lua_results....
- lopatin 2y agoI think it's a stretch to call it underrated. Isn't it the defacto language for embedded scripting stuff? I've seen it used as a mini language in production in game engines, databases, and trading systems. On the other hand, if the article is saying that it deserves to be more highly rated in the non-embedded space, I think I would need more than a handful of syntactical niceties to explain why it deserves to be in the same conversation as Python, Ruby, etc...
- librasteve 2y ago…raku
- deleted 2y ago[deleted]
- helpfulContrib 2y agoI was infected by the Lua mind virus 15 years ago and I have not recovered. I simply don't see any reason not to use it .. for everything. I've built games with it. I've built GUI's with it. I've built scientific analysis tools with it. I've used it as a total solution for previously-impossible embedded problems. I've used it for desktop applications and mobile apps. I've automated entire production lines with it. It has huge appeal as a general purpose software development ecosystem - but those who know how to do this, tend to keep it to themselves for some reason. It can do everything. There's just nothing I want to do with computers that I can't, legitimately do, with Lua - or its VM. Or, LuaJIT. Or, all of the above and a bit of luarocks built in. Throw some luastatic in while we're at it, bundle it all up as a .deb, and nobody needs to know a thing. Its just so versatile. I hope someone builds an OS around it some day, making everything and anything the user wants to do, accessible through a Lua module, or some smart libffi wrappers around a handful of .so's, somewhere .. In my retirement, I'll take antirez' LOAD81, turn it into a proper Lua editor, add integration with luarocks and luastatic and maybe a shit-tonne of IPFS, and then there won't be any need, ever again, to deal with anything else.
- discreteevent 2y agoThis happened to me about 6 months ago. (I didn't seek it out, just ended up working on something where lua was involved). So thanks for the warning. I didn't realise it could last for 15 years or more. The big thing for me is how easy it is to make something that feels like a DSL while it's still just Lua when you debug it.
- helpfulContrib 2y ago[dead]
- HexDecOctBin 2y agoHow do you debug it? I tried a little bit and kept running into issues due to the dynamic typing.
- 2y ago
- dr_kiszonka 2y agoIt looks like Lua's conditionals, for loops, and function definitions terminate with the "end" keyword. Is this considered more readable or does it bring some other benefits besides helping the interpreter parse code? Many people love Lua, so I suspect there is a good reason for this.
- bawolff 2y agoAll programming languages have tiny differences. Some use }, some use keywords like "end" or "fi", some use indentation like python. Its a trivial difference that does not matter.
- 01HNNWZ0MV43FF 2y agoWikipedia says that came from Modula, but I can't find why Modula did it or why Lua decided to copy it. I thought I read somewhere that Lua was meant for use by non-programmers, so the "end" would be easier to type and read than curly brackets.
- bawolff 2y agoModula is based on pascal which is based on algol. The "end" thing is in the first version of algol from 1958. This is 14 years before C was invented. Presumably they thought the more verbose syntax would be more readable.
- int_19h 2y agoAlgol (and Pascal) originally did the same thing that C did, except that you used `begin` and `end` instead of `{` and `}` when you needed a compound statement as a branch etc. Modula changed it so that all structured constructs implicitly introduced a compound statement, and terminated one where appropriate (e.g. on `else`), but this still required some end marker for the last one. If the question is why `begin` and `end` and not `{` and `}` - for one thing, Algol was designed to be the language you'd write reference implementations of algorithms in for publication, so readability was more important than terseness. For another, it predates ASCII, and not all charsets in use at the time even had `{` and `}` as symbols.
- hprotagonist 2y agoespecially with fennel on top, i can certainly see the uses and appeal! coming from mostly python, i miss a robust stdlib.
- digdugdirk 2y agoI've been more and more intrigued by fennel lately, and I've been meaning to dive into the functional end of the pool. Any recommendations for how to get started with it, especially if coming from a python background?
- n8henrie 2y agoAlso interested in resources here -- familiar with python, go, rust, but never used a lisp. As a learning experiment, I was able to use the fennel website to convert my Hammerspoon config from lua to fennel, but I still struggle to add new functionality. Certainly have not delved into macros, but this is where much of the power lies AIUI.
- livrem 2y agoI have learned it (somewhat) by playing around in TIC-80 and Löve2D (including LoveDOS). Both Lua and Fennel are tiny languages. You can skim all the documentation in a short evening. Fennel does not even have its own standard library, so keep the Lua documentation close at hand. I appreciate the simplicity of both Lua and Fennel. There are some ugly parts, but all languages have those. Janet (later project by Fennel's creator) is a nicer language that is also portable and embeddable, and has a nice standard library, but Fennel runs anywhere Lua runs. Janet is great just on its own for scripting and not sure I would want to use Fennel for that anywhere Janet is available. But as a way to script games in e.g. Löve2D it seems like an excellent choice.
- TekMol 2y agoWhen it comes to languages, I was enlightended when I changed from {}; languages to Python. I could never go back.
- Trasmatta 2y agoRuby is the sweet spot for me. I don't like the syntactic whitespace in Python, but still prefer the cleaner look it not having braces everywhere.
- librasteve 2y agoraku - the bastard child of functional and OO class MyTable is export { has @.data; multi method new(@data) { $.new: :@data; } method render { table :border<1>, tbody do for @!data -> @row { tr do for @row -> $cell { td $cell } }; } }
- DonHopkins 2y agoMany languages like Ruby have sweet "Syntactic Sugar", but Raku has "Syntactic Syrup of Ipecac".
- librasteve 2y agolol - thanks for adding to my vocab! [in defence of raku, while it truly is marmite wrt Ruby / Python, there is a very loyal core of smart people that love the freedom and expressiveness it offers]
- klibertp 2y ago> there is a very [tiny, very] loyal core of smart people FTFY ;) Honestly, I love Raku - it's almost like Racket of the non-sexp world - but the community is microscopic, and the development is slow. It's a shame because, solely based on features and in terms of design, it's a serious contender for the most powerful dynamic language out there. It's packed with interesting features (junctions, phasors, traits, quote/unquote macros (soon), typed variables and subsets, coercible types, augment, OO system with multiple inheritance, interfaces, generics, multi-subs and multi-methods everywhere, custom operators including circumfix, regexes and grammars, etc, etc...) out of the box and it's actually really impressive how all these features work together in a cohesive design. Unfortunately, the underlying implementation seems a bit chaotic; some features are either not fully implemented or specified, the performance could be better, and so on. So, while I love and still use Raku for almost all my scripting, if I were to start a serious project, I think I'd go with Common Lisp instead. CL has fewer features out of the box, but many of the missing ones are one `ql:quickload` away (or you can use CIEL), while the underlying implementation (SBCL in my case) is diamond-solid. --- Aside: that `render` method could be sweetened a lot! For example: tbody @!data.map: { tr .map(&td) } ==> table :border<1> or: tbody @!data.map(*.map(&td).&tr) ==> table :border<1> or finally (using the fact that hyper descends into subarrays): tbody @!data».&td.map(&tr) ==> table :border<1> (I think Raku is unrivaled in one-liners!)
- synergy20 2y agoi wish luajit has been actively evolving though
- hinkley 2y agoIt’s hard to tell since there’s no changelog, but it looks like there are at least some improvements ongoing other than just simple bug fixes. Some of the changes in August for instance look like more than just for correctness.
- mardifoufs 2y agoIt is evolving, they just don't want to take the same direction Lua has been taking since the past few releases.
- aeturnum 2y agoI have really enjoyed working with Lua when it's come up and I think it's an extremely good language. In particular, as Noë says, its interface for embedding into C/C++ is clean and flexible. There are performance concerns, but considering how widely Lua is used for game logic in high performance video games clearly those concerns can be addressed. That said, I think there are other warts that can be confusing and make the language difficult. The Nil-Terminated Arrays section points out one oddity about `nil` - but there are many others. There are a number of confusing corner cases (or were - I haven't used it in a while). As an example, if you have a list of values and you pass that list into a new table, the resulting table may be different than if you add each value in that list in order. I also think that the flexibility of embedding means that you are often learning the Lua <=> C interface as much as you are learning Lua. So jumping from deploy to deploy is more confusing than most languages. Nevertheless I fully agree the language is underrated!
- 01HNNWZ0MV43FF 2y ago> you are often learning the Lua <=> C interface as much as you are learning Lua. One time I had a memory leak in a game, something like exactly 4 bytes per frame. It turned out I was not popping the Lua-C parameter passing stack properly after each frame. I found this out after some unhelpful person suggested that "all programs just leak memory" lol
- spacechild1 2y agoThe Lua C API is fantastic from a design perspective, but as you have discovered, it is rather error prone. Fortunately, there are many wrapper libraries that take care of all the stack manipulation. For example, I'm using https://github.com/ThePhD/sol2 https://github.com/ThePhD/sol2 to interface with C++ and the API is incredibly ergonomic.
- ahoka 2y agoAn API cannot be “fantastic” if it’s error prone.
- pavlov 2y agoMy humble opinion is that most applications that need scripting should just embed JavaScript. It has a massive advantage in the existing ecosystem. People don’t always love it, but millions of them already know it. You don’t need to re-learn array indexing and nil termination quirks and the dozens of other things where Lua is subtly different in ways that you’ll find out at runtime. There are JS engines in all sizes, from tiny interpreters to world-leading JIT performance monsters. And most operating systems nowadays ship with a high-quality engine and embedding framework that you can access without installing anything, like JavaScriptCore on the Apple platforms. Do your users a favor and just use the boring standard language instead of making them learn a completely new one that doesn’t offer meaningful practical benefits for them. It’s probably not as much fun for you, but you’ll save time for both the users and yourself in the end.
- Demiurge 2y agoOn one hand, you do have JavaScript ubiquity, on the other hand, you have the JavaScript "WTF" equality and typing conversion matrix, "WTF" scoping, and dozens of other foot guns that Lua doesn't have. Some people would rather everyone learned Lua subtle differences and wrote less buggy code. I've had to use for the web for 20 years, and if I have any choice, I would avoid it. Anyway, every language has some fans, and I don't mean to dismiss them, but ubiquity is not the top priority, all the time.
- therein 2y agoThere is the equality gotchas on JavaScript but then you have 1-indexed arrays in Lua, which is a footgun that I know exists, I try to avoid shooting myself in the foot with it but I keep doing it. It is beyond a footgun, more like a footgun concealed as a shoehorn. Either way I find embedding a Lua VM into a project so much easier than embedding a Javascript one.
- kragen 2y agoWhich JS VMs have you tried embedding? People in this thread have suggested https://github.com/Moddable-OpenSource/moddable https://github.com/Moddable-OpenSource/moddable, https://bellard.org/quickjs/ https://bellard.org/quickjs/, and https://duktape.org/ https://duktape.org/, but I haven't tried any of them.
- cute_boi 2y agoI feel Scala is also very underrated.
- fsloth 2y agoHow do you use Scala as an embedded scripting language?
- 01HNNWZ0MV43FF 2y agoI've had fun embedding Lua a couple times, but as with wasm I almost never have a case where I need to run new code without being able to recompile the whole binary, so I don't get to use it often. The most fun was when I made a game engine ("engine") in C++ that used Lua for all the game logic. The fast debug cycles are very useful there. Maybe I should still do that for Rust gamedev, since Rust notoriously compiles slowly. The second-most fun was an IRC bot that could reload its Lua logic without disconnecting. Nowadays I'd write a bouncer and just let the main process restart. (Or use wasm, a wasm IRC bot would be good...) The third-most fun was using Lua as a Turing-complete configuration language. If I needed an array of something, I just made Lua make an array, instead of generating Lua code. One of the least fun was the Blender plugin that exported 3D models as generated Lua. If I did that one again today, I'd just use MsgPack or some ad-hoc binary format.
- Levitating 2y agoI can't say I appreciate Lua any more after reading this. It only reinforced my annoyances with it. It's been a while since I wrote any Lua but I didn't think it was intuitive at all. Why are arrays tables, why are they nil terminated and why do they start at 1. I don't think it's underrated either. It's very popular for writing scripts in (older) game engines.
- selimthegrim 2y agoThe system software for newer TI graphing calculators is written in Lua and often emulated to Z80.
- kristopolous 2y agoa bunch of that comes from awk.
- matheusmoreira 2y ago> Why are arrays tables I might be able to provide at least some insight into that. One of the things I found while implementing my language was that the ordering of elements in a hash table is essentially random. Literally random if you mix in some randomness into the hash function's initial state in order to harden it against collision attacks. Many languages guarantee insertion ordering. It's a useful property to have, makes testing easy and deterministic and it's intuitive for users. A simple way to implement that is to put a perfectly normal array of values into the hash table, and then have the buckets which the keys hash into contain indexes into that array. That way the indexes of values remain stable no matter what the keys hash to. So a sufficiently advanced hash table will have an array of values inside it. I suppose some language designers took one look at that situation and decided to just merge both types already by using hash tables for everything. For example, PHP also did that. Associative arrays, they call it.
- kragen 2y agoCPython's hash table (dict) evolved to have an array of values indexed by a hash table of indices for performance reasons, but later decided to guarantee the insertion ordering that this permitted for iteration. "Associative array" is just the term used for hash tables (dicts) in Awk, bash, Tcl, and, most relevantly for PHP, Perl4. It doesn't specifically mean that the language lacks a separate container type for small-integer-indexed arrays. It just means that that particular container type can be indexed by something other than small integers, usually strings.
- protomolecule 2y agoIt's my language of choice for letting users customize an app, but the last client wanted Python because many people are already familiar with it and 'Scriptable with Python' looks better from the marketing point of view(
- toastercat 2y agoI love Lua as a language; even if it can be a bit cumbersome at times, its simplicity and low barrier of entry is refreshing. I'm currently building a full-stack web application with https://redbean.dev https://redbean.dev in Lua and it's mostly been a joy.
- hipadev23 2y agoLuau [1] developed by Roblox is a backwards-compatible fork of Lua 5.1 with some very significant improvements to speed and QoL [2]. It also mostly alleviates the nil-terminated array problem. [1] https://github.com/luau-lang/luau https://github.com/luau-lang/luau [2] https://github.com/luau-lang/rfcs/tree/master/docs https://github.com/luau-lang/rfcs/tree/master/docs
- orphea 2y agoHappy to see Luau is mentioned! Its greatest improvement over vanilla Lua is better sandboxing. Lua is just pain in the ass to embed safely. So many footguns.
- pentaphobe 2y agoOut of curiosity: does this post read like LLM (generated or assisted) to anyone else?
- johnzim 2y agoThe conclusion at the end definitely does
- lioeters 2y agoPretty sure in a year or two the ratio will flip to where people will pick up on articles that are not assisted by LLM. Does this post read like it's been written completely by a human? And the models will probably get better until it's mostly indistinguishable.
- leptons 2y agoLLMs and bots will probably be the thing that leads to a second version of the internet being created. Eventually the thing we currently know as "the internet" will be nothing but bots and LLMs continually regurgitating in a giant 100-billion-watt-consuming feedback loop.
- driggs 2y agoAn LLM would have written a much more convincing argument that "Lua is underrated". This blog has just three posts, none with significant content. I was curious how this article even wound up on HN, until I realized that it was submitted by the blog's author: https://news.ycombinator.com/user?id=nflatrea https://news.ycombinator.com/user?id=nflatrea
- soapdog 2y agoReally liked that post, then again Lua is one of my favourite languages. I wrote this post https://andregarzia.com/2021/01/lua-a-misunderstood-language.html https://andregarzia.com/2021/01/lua-a-misunderstood-language... some time ago and it kinda touches similar points as the OP. Read on if any of yous want to see yet another person talking about Lua.
- beanjuiceII 2y agonah, it's overrated ackshulaly
- Animats 2y agoExcept for "tables". Lua tables are too weird. Trying to make one construct do the work of an array, a struct, and a dict leads to a messy construct.
- giraffe_lady 2y agoThere is also a very common two-liner invocation that turns them into prototypical classes as well. Extremely versatile data structure (pejorative).
- ramses0 2y agoPerl would like to have a word... ;-) But seriously, they do have some interesting quirks which make sense if you think of it (and maybe Lua as a semi-contemporary got its ideas from there), specifically, hashes are pairs of keys (even/odd) in a flat array... and of course objects are just key/values, but with some values being names and functions... https://perlmaven.com/creating-hash-from-an-array https://perlmaven.com/creating-hash-from-an-array
- int_19h 2y agoThere was a time when this approach was common for dynamic languages in general. PHP and, to some extent, JS also come to mind. I think it's clear in retrospect that it makes more sense to keep lists and maps separate even in a high-level dynamic language that doesn't care much about perf, and any purported gains in simplicity from having a single data structure are illusory because of footguns. But perhaps it wasn't so clear before we had enough experience with this kind of design. Then again, Python had a clean separation between lists and dicts from the get go, and it predates Lua as well as PHP and JS...
- Animats 2y ago> even in a high-level dynamic language that doesn't care much about perf Lua is mostly used inside games, and the JIT compilers for it are said to be pretty good. (I haven't tried this yet, but will have to soon.)
- jmnicolas 2y agoMeh. I don't get the love Lua gets on HN. At least version 5.1, I didn't try the others. No first class support for OOP, you got to use tables instead. No "continue" keyword to go to the next iteration of a loop. So you have to use some ugly elseif. No try catch! It's a dynamic language so everything goes. A function will return nil or a number or whatever you wish. A function can also returns any number of variables, so obviously some moron will abuse it: looking at you Blizzard intern (you must have been an intern right?) that thought returning 20 variables on the combat event log was a good idea. Ever heard of tables??? The LSP can't do miracles when there are almost no rules so auto-completion is more miss than hit, which is quite shocking in 2024. The IA is helpful sometimes but create subtle bugs some other times. A simple uncaught typo will create a hard to find bug (yesterday copilot auto-completed myObject.Id instead of myObject.id, there went 20 minutes of my life trying to find why some code that was running solidly for weeks was now failing silently). So all in all, Lua is fine to write small imperative scripts of a few hundred loc. Anything bigger and more complex you should run away IMHO. I never realized C# was such a well designed language until I tried Lua.
- IshKebab 2y agoI agree. Also tables are quite weird, and 1-based indexing is definitely a mistake (sorry 1 fans but it is). I think it just doesn't have much competition in the "embeddable languages" space unfortunately. As another commenter said, JavaScript is probably the best choice in most cases today. There's a list of options here but most of them are not really good options usually: https://github.com/dbohdan/embedded-scripting-languages https://github.com/dbohdan/embedded-scripting-languages E.g. Python would be a terrible choice in most cases. Awk? Some of them aren't even general purpose programming languages like Dhall. If you narrow it down to embeddable-like-Lua there are hardly any.
- cardanome 2y ago> No first class support for OOP, you got to use tables instead. You get meta tables instead which allow you to trivially write an OOP system that perfectly fits your needs. Yes there is more than class-based OOP. And I mean trivially: https://lua-users.org/wiki/SimpleLuaClasses https://lua-users.org/wiki/SimpleLuaClasses For some people not being locked into one form of OOP or any OOP at all is a huge advantage. > No "continue" keyword to go to the next iteration of a loop. So you have to use some ugly elseif. Yeah, that sucks. Thankfully Luau fixes that and basically all annoyances I have with Lua. https://luau.org/syntax https://luau.org/syntax > I never realized C# was such a well designed language until I tried Lua. Lua and C# have fundamentally different design goals. C# sucks for embedding, you have to include a huge runtime. Godot still hasn't figured out how to support C# on web builds. Lua values minimalism and flexibility. That obviously means it lacks some quality of life features of bigger general purpose languages. Language design is about trade offs.
- tga 2y agoMandatory plug for Redbean[0], a standalone Lua webserver (a single-file that runs natively on six OSes!), and Fullmoon[1], a web framework built on top of it. Not exactly mainstream, but so simple and elegant. [0] https://redbean.dev/ https://redbean.dev/ [1] https://github.com/pkulchenko/fullmoon https://github.com/pkulchenko/fullmoon
- jmclnx 2y agoLua can be used to access the NetBSD kernel, which is interesting. I have said it before, I should spend time learning Lua.
- kragen 2y agoYou won't have to spend very much time. It's a very small language.
- fsmv 2y agoI built a chatbot with lua plugin commands and I really had an awful experience trying to incorporate it in my C++ program. I really don't understand why people say it's easy to embed because you have to do a ton of stack manipulation to do anything. Not only that but the language itself is cumbersome, frustrating, and does nothing at all to help you when you make a mistake. I will never use lua again and avoid any project that uses it.
- Etheryte 2y agoMy experience has been similar, even though not as drastic. Lua is fine for small extensions and such (e.g. Hammerspoon), but a lack of any kind of a reasonable standard library really bites me the wrong way. Sure, I can write a function to log an array, but why can't I just log an array like a decent human being?
- deleted 2y ago[deleted]
- kragen 2y agoWhat language did you find was easier to embed, and how does it handle the lifetime management that Lua's embedding API handles with its stack? The language itself may be a matter of taste. I prefer languages which, "in the face of ambiguity, refuse the temptation to guess," but certainly I've spent enough time using Perl, bash, JS, and BASIC to be able to deal with Lua's relatively mild level of DWIMminess.
- le-mark 2y agoI would use quickjs today for embedding over lua. Everyone know js nowadays and quickjs is really nice. The advantage lua has is library support via Lua rocks. Maybe someone can comment on the quickjs ecosystem?
- kragen 2y agoIt sounds like you're saying quickjs is what you'd try if you wanted to embed a language, but you haven't tried embedding quickjs yet?
- pdimitar 2y agoNo transparent parallelism? And no, I don't mean threads. Underrated? Eh... it does stuff better than others but that doesn't mean much. We really don't learn.
- RossBencina 2y agoLua has coroutines, and you can use a coro scheduler such as lanes if you wish.
- pdimitar 2y agoCool, good to know, thanks for bringing it to light. Still not a fan but it's nice that it has the facilities.
- ternnoburn 2y agoLisa is deeply, deeply overrated, ime. But I'm coming from the games industry where it's widely used. The only benefit of Lua ime is the ease at which it embeds in C++. Beyond that, it's a nightmare.
- julianeon 2y agoI'm getting the sense overall that Lua is correctly rated.
- K0IN 2y agoI used Lua the first time in Garry's mod, and I had a absolute blast, was my first real programming language, I can vouch, it's easy to pick up :) I also must admit, the gmod lua extension (glua) was so much more enjoyable, that since then I keep my own lua version with patched ! for not and != as alternative for ~= (Luas way for not equal)
- nxobject 2y agoAh yes, GLON with a touch of datastream ;)
- bvrmn 2y agoIt's hard to use lua for any sizeable chunk of code due to weak typing, absence of type hints and error handling. No it's not underrated in any way. It's funny how through the years I've started to appreciate statically typed languages and type hints (Python, TypeScript) as well. Up to my current stance: it's a disservice for a community to write hintless python or js code. P.S. Recently I've rewritten 1.5k cloc of JS into TypeScript. As usual there were dozens of cases of missed nulls, null attribute accesses or semantically questionable nulls.
- liendolucas 2y ago> Up to my current stance: it's a disservice for a community to write hintless python or js code. Strongly disagree. If you are you using Python or Javascript or any other duck typing language you are supposed to know what you are doing and types are completely unnecessary. I'm amused at how the community in general praises and adopts TypeScript in so many projects. You can just write realiable JS code as it is. I have ever written any hinted Python code and everything just works as expected. If you need some guarantees then I would probably switch to some unit testing which at least for me brings more value that using types.
- jchw 2y ago- Documentation is great, but documentation can fall out of date. Strong types usually can't; they are checked in both directions. - Tests are great, but it's hard to maintain 100% coverage that checks all of what types do. It's very possible to have tests that pass that shouldn't. Types can not only find stealthily broken code, but also broken tests. - Type checking gives even more instantaneous feedback than almost any test runner. - Most projects have multiple developers. Types don't communicate everything, but they are a reliable form of communication that is guaranteed to be up-to-date even when documentation isn't, which is great combined with good function names and good parameter names. - Most programs need to deal with requirements that shift, either because they evolve or our understanding evolves. Refactoring code without types is hard: if you change the return value of something, how can you be sure that all of the usages are up-to-date? What about if your refactor has been rebased a number of times before merging? I've run into a real-world production incident caused by this, when a return type changed to a tuple and it only exploded in an important Celery job that didn't have a test around the specific boundary that broke. "If you know what you're doing" is not enough. Programs change, and they are changed by multiple people concurrently. This is the same reason why Rust continues to grow, people can say what they want but moving errors to the left is the only way forward because even if you're literally perfect you still have to know 100% of what's going on to never merge anything that causes a problem. (But really, people are not perfect, and never will be, so better tools Will win eventually.)
- pshc 2y agoLua as a language is pretty warty, with some obvious omissions. But it’s widespread as an embedded language, and has been around a long time, and I think that tends to give it a nostalgic halo effect. I would like to see more minimalist scripting languages with modern sensibilities replace it.
- opticfluorine 2y agoHaving just gone through the exercise of integrating Lua with a custom game engine over the past few weeks, I have to echo how clean the integration with other languages is. It's also worth noting that the interface is clean in such a way that it is straightforward to automatically generate bindings. In my case, I used a handful of Roslyn Incremental Source Generators to automatically generate bindings between C# and Lua that matched my overall architecture. It was not at all difficult because of the way the interface is designed. The Lua stack together with its dynamic typing and "tables" made it very easy to generate marshallers for arbitrary data classes between C# and Lua. That said, there are plenty of valid criticisms of the language itself (sorry, not to nitpick, but I am really not a fan of one-based indexing). I'm thinking about designing an embedded scripting language that addresses some of these issues while having a similar interface for integration... Would make for a fun side project one of these days.
- zogomoox 2y agoif you fix the one based indexing you should call yours KT@ or Kt`
- ADeerAppeared 2y ago> sorry, not to nitpick, but I am really not a fan of one-based indexing It is very funny how this is just the one sole criticism that always gets brought up. Not that other problems don't exist, but they're not very talked about. Lua's strength as a language is that it does a lot quite well in ways that aren't noticeable. But when you compare things to the competition then they're quite obvious. E.g. Type Coercion. Complete shitshow in lots of languages. Nightmare in Javascript. In Lua? It's quite elegant but most interestingly, effortlessly elegant. Very little of the rest of the language had to change to accomodate the improvement. (Excercise for the reader: Spot the one change that completely fixes string<->number conversion) Makes Brendan Eich look like a total clown in comparison.
- PicassoCTs 2y agoOne based indexing is also the one thing every beginners course has to hammer into people, as its so non-intuitive until you know about pointers.
- wruza 2y agoLua is not underrated. It’s how many now, still 4(?) different languages which continue to suicide after a few years, all with cringe [re]design decisions, half-assed mechanics and lack of convenience that authors refuse to address. I spent many years on it (embedding, metaprogramming, all the deep things) and it is one of my biggest regrets in the choice of tech. The amount of effort you’ll put into not sliding out of this crazy ride nullifies all the promises of easyness, which is limited to trivial things anyway and explodes with complexity in any non-trivial data exchange. Its only upside is low footprint, but I fail to see where it matters today (apart from nodemcu whose active users could probably fit in one closet). https://github.com/nodemcu/nodemcu-firmware https://github.com/nodemcu/nodemcu-firmware Based on Lua 5.1.4 or Lua 5.3 but without debug, io, os and (most of the) math modules As expected, they didn’t bother to support all versions and probably were done with it after 5.4 announcement.
- unscaled 2y agoLua is definitely not underrated as an embedded Language. It is the uncontested winner of this field. If anything, I feel it is slightly overrated: it is easy to embed, but has no other real strength. Everything else feels about Lua feels a little bit meh for me. It is completely serviceable, and there are many apps where I have used Lua very effectively like Hammerspoon or Wezterm. But in the end of the day, every time I have to deal with a system that embeds Python or modern JavaScript, I am 2-5 more productive than I am with Lua. Sure, Python and JavaScript have their own warts, but they have grown and improved their ergonomics since the 90s. Lua, on the other hand, is a language that is philosophically hostile ergonomics. Lua's philosophy, as far as I can get it, is to be minimalist and allows for emergent features. You want arrays? We don't natively support arrays, but you can use tables as arrays. You want classes? You can build your own class system or prototype system using tables. You want to implement anything else? Well, we've got some metaprogramming for you. The problem with this approach, is that you don't end up with one language, but with hundreds of different and confusing dialect, where each programmer does their own thing, this is how JavaScript used to be with regards to concurrency and classes, and it wasn't good. The other issues that arise from this philosophy is that Lua lacks a lot of ergonomic features which cannot easily emerge out of its simple tables+closures+coroutines foundations. There are no type hints (like Python got), const (like JavaScript), default argument values, array/table destructuring, try/catch blocks, string interpolation, foreach loops, immutable values, etc. These features sure add a lot of complexity to the language implementation, but they are extremely valuable in saving programmer time and cutting down bugs. Lua takes the Worse Is Better approach here and saves implementation complexity by pushing it down to the user. If this complexity doesn't exist in the Lua interpreter it doesn't disappear: the programmer has to deal with it by making bugs more likely and debugging harder. Lua might be a worthwhile trade-off where the choice is between embedding Lua or Embedding nothing, since other languages are harder to embed. Or in industries where it's deeply established like gaming. But I cannot say it's a language I enjoy programming, and I don't see any reason to use it in a non-embedded context. Apparently no one else does, but that's not because Lua is underrated.
- booleandilemma 2y agoThe 1-based indexing feels too icky to me. It was a language designed for non-programmers and it shows, imo.
- unleaded 2y agoThis is a very common complaint about Lua and i really don't understand it. I get that it's weird but is it hard to remember it while you're programming or something? I never run into it much anyway but I guess it depends on what kind of code you're writing. I think there's a lot more to language choices than syntax and weird behaviors like that, it's more about how you run/implement the language and the ecosystem and things like that. Think about when people say javascript is a bad language because if you add together two empty arrays you get the number 0 or something. Or think about how you might be annoyed if you had to use a desktop app written in PHP (yes people do this) because the author likes PHP..
- dmpk2k 2y agoI used to think the same as you about 1-based indexing in Lua... until I tried using Lua in a game engine. I was constantly getting hit in the face with problems (e.g. coordinate systems and off-by-one errors), even after spending far too much time trying to abstract around this mismatch to make these problems go away. In theory I was okay with the indexing. In practice it was an absolute PITA. Plus there were other numerous papercuts; it felt like Lua was actively fighting me every step of the way. I went from liking Lua to absolutely despising it. In the end I switched to C++11, which amazingly was much more productive. As in night-and-day difference.
- aulisius 2y agoI recently came across TypescriptToLua[0] which has improved my experience of writing Lua manyfolds. No more having to deal with 1-based indexes or lack of type hints. [0] - https://typescripttolua.github.io/ https://typescripttolua.github.io/
- kragen 2y agoI feel like, except for small size, this post doesn't really get into what I like about Lua, which is pretty unfortunate. Lua deserves a better case than this. I'm maybe not the best person to write this because I'm not really a huge Lua fan. Though on projects with others I'll use whatever language they're using, left to my own devices, I probably write about 3× as much JS as Lua, about 32× as much Python as Lua, and about 20× as much C as Lua. But Lua has some really nice attributes. It's a pretty reasonable very-high-level language comparable to Python, JS, Groovy, Perl, or Clojure. You can get a lot done in very little code. You don't have to crank out piles of boilerplate the way you do in Java or sometimes C. It comes with concise and readable syntax, flexible data structures, garbage collection, strong dynamic typing, list structure, hashmaps, dynamic method dispatch, inheritance, operator overloading, cooperative multithreading, eval, exception handling, namespaces, closures with lexical scoping, etc. Its documentation is first-class. Most of this is pretty much standard for the dynamic-language category nowadays; there's not much special in here to pick one language from the category over another. Lua's biggest advantage is that LuaJIT is motherfucking alien technology from the future. I wrote a straightforward escape-time fractal renderer in https://gitlab.com/kragen/bubbleos/-/blob/master/yeso/mand.lua https://gitlab.com/kragen/bubbleos/-/blob/master/yeso/mand.l... with a dynamic function invocation in the inner loop (to switch between fractals) and LuaJIT's trace compilation just compiles that right out. There's also a real-time animated raymarcher in that directory in LuaJIT, though the framerate and resolution are pretty bad. You can literally just write high-level code at like a Python or JavaScript level and, as often as not, it just goes faster than C. (Sometimes it doesn't. JIT compilers are unpredictable and sometimes disappointing.) Now, probably somebody is going to reply to this and tell me that everybody runs JS in JIT compilers too, so this isn't a real difference. Unfortunately that's horseshit. I'm sorry, but V8 and SpiderMonkey are just not in the same league, though not because their implementors are less brilliant. They're just attempting a much harder job, because JS is a much hairier language. Consequently their performance is an order of magnitude worse. (Even regular non-JIT Lua is a lot faster than most other very-high-level languages, almost to the level of JS JIT compilers.) LuaJIT's C FFI is also just ... there's no expression in English sufficiently emphatic to express how great it is. The expression I'd normally use translates literally as "it's a very child of ten thousand whores," which hopefully conveys some of the emphasis if not the content. Here's the FFI binding for Yeso, the graphics library used for the above fractal demo: https://gitlab.com/kragen/bubbleos/-/blob/master/yeso/yeso.lua https://gitlab.com/kragen/bubbleos/-/blob/master/yeso/yeso.l.... Yeah, just by pasting the relevant lines from a C header file into your Lua program, you can call C code from a shared library as if it were Lua code. It's almost as easy as calling C code from C++! After getting screwed over (along with everybody else) by the Python community's gratuitous and ongoing breakage of backward compatibility, coupled with public shaming to persuade more people to break backward compatibility, the Lua community's approach to backward compatibility is looking pretty appealing. The vibe is that old versions of the language live forever, and you should keep using them instead of upgrading, but new versions usually aren't compatible. However, it's much easier to make a Lua library compatible with every existing version of Lua 4 and Lua 5 than to make a Python library compatible with any version of both Python 2 and Python 3. Being small, fast, and implemented purely in portable standard C makes it practical to run Lua even on larger microcontrollers like the ESP8266, even when they use weird CPU architectures. Even interactively. https://github.com/nodemcu/nodemcu-firmware https://github.com/nodemcu/nodemcu-firmware LuaJIT is much less portable than PUC Lua, and also more than twice the size, about 580kB on my machine. This is still orders of magnitude less than something like Python or the JRE. Lua is a little more annoying than Python or node.js to develop interactively with, but it's overall pretty comparable. For code I'm writing myself (as opposed to getting from a library) the Lua version usually ends up being just a little bit bigger than the Python or JS version. Lua is more bug-prone, though, due to a number of language design flaws. Lua is a very newbie-friendly language, I think even more so than JS or current Python. It's very successful in systems aimed at beginning programmers, like Minetest (Luanti), World of Warcraft, and LÖVE2D. The barrier to entry is very low; you don't have to be learning the GUI of a new IDE at the same time that you're learning the programming language and, possibly, how to program. The standard library is small rather than overwhelming. And the download for standalone Lua development is tiny.
- habibur 2y agoAdd, no way to determine size of Array, which is the primary data structure anyway. No item.length propery. You might decide to count with foreach(), but that will terminate when it encounters the first value in the array that is NULL.
- talideon 2y agoGiven the way that tables work, the concept of a 'length' is a fuzzy one. However, the '#' operator will give you the last index of a table, which for tables used as arrays is pretty much what you want. There's also the '__len' metamethod, which is what's invoked if it's present if you use the '#' operator. The operator's been in the language since at least 5.1. It's a bad idea to think of Lua tables as arrays. They're maps/dictionaries with some extra semantics to allow them to be used similarly to arrays.
- MomsAVoxell 2y ago> You might decide to count with foreach(), but that will terminate when it encounters the first value in the array that is NULL. True only if the programmer doesn’t take the effort to understand the difference between ipairs and pairs.
- shmerl 2y agoI started using Lua for Cyberpunk 2077 mods and neovim configuration, it's fun to use.
- garbagelang 2y ago[flagged]
- YoshiRulz 2y agoThere are a lot of good comments here already, but I can't let this pass by the main page without taking the opportunity to rail against Lua because, no, it's not underrated. It's everywhere and terrible. This article is fairly light on detail, only mentioning a couple table footguns, but there are MANY more. (I also disagree with it being "accessible even for beginners", but I'll stick to objective things.) For starters, the size operator `#` doesn't work on map-like tables, and there's no easy way to copy part or all of a table, or to serialise one for printing. Lua doesn't have `switch` or even `break`/`continue`. Though it added a `goto`—years after we collectively realised that's an antifeature. You can use `and`+`or` as a ternary, but you need to remember that it works differently with bools and that `nil` is falsey ofc. And `0` is truthy. Using a variable which hasn't been declared yet or is otherwise out of scope gives `nil` rather than an error. In fact most logic errors are SILENT (yay dynamic typing), and some syntax errors are raised far from the actual cause. `<const>` isn't. Before Lua 5.3, all numbers were floats. The patterns used for `string.match` look superficially like RegEx but they are not, despite them predating Lua. The stdlib is woefully lacking, with the official documentation seeming to taunt you with examples of how several common functions could be implemented, but it's left to you to copy them into your projects. So yeah, Lua might be small and quaint, but that's only because so much is not included "in the box", and what is included is no good.
- garbagelang 2y ago[flagged]
- cromantin 2y agoThe best way to use Lia is using Typescript - https://typescripttolua.github.io/ https://typescripttolua.github.io/ We have huge Lia codebase for game client and game server shared code all written in typescript. Our developers only see lua if something does not work and it’s not often.
- aaroninsf 2y agoDid they ever fix the 1-index thing?
- gustavopezzi 2y agoLua is a great language for extending systems and very high-level scripting. I like it. I had the pleasure of teaching a module in 2020 together with Roberto Ierusalimschy where we used Lua and LPeg to teach students how to write a simple programming language. It was a very fun class.
- jezek2 2y agoIf you like how easy is to embed Lua but not liking it's syntax or features you can try FixScript. It's a language I've created that has C-like syntax, the implementation is a single .c file. It's unique feature is an ability to arbitrarily extend the syntax (in fact classes and the type system is implemented as a library). This can be used for specific needs of your project. It has also an ability to have time limits for execution and is able to reload scripts in place for live code updates. It also has a JIT by default. More information here: https://www.fixscript.org/blog/introduction https://www.fixscript.org/blog/introduction
- jdblair 2y agoLua fits the same niche as Tcl, but the runtime is smaller and way better. Tcl started as a simple, embeddable scripting language (and low performance, it was just string substitutions!) and evolved into Tcl8, a mostly backward compatible object system after successive iterations to improve its performance and expressiveness. "everything is a table" gets you pretty far in Lua, in much the same way that "everything is a list" in lisp, and was a much better abstraction than Tcl's "everything is a string." When I last used Lua professionally (10 years ago) I did discover some foot-guns related to the handling of NULL / nil in the LuaSQL module. The Lua array length function was based on nil-termination, so a NULL value in a column could cause issues. Maybe this has been fixed by now?
- thunkle 2y agoI've been writing lots of lua recently. The only two things that bother me are indexes starting at 1. It's made my 2d grid math more complicated. I also don't like how I have to write a goto statement if I want to continue/next inside a loop. Other than that I love the simplicity.
- jhoechtl 2y agoLua as a language is underrated, yes. Lua as the implementatation of PUC Rio is what it is. It misses abstractions in the runtime to make it pre-emptive and parallel. It is also somewhat telling that Mike Pall despite his come back announcement didn't deliver. It comes with batteries but they only fitt into one brand well. Compare this to eg golang or Python.
- fire_lake 2y agoIndexes should start at one in all languages IMO. The zero thing is a historical quirk due to pointer arithmetic.
- rdfc-xn-uuid 2y agohttps://www.cs.utexas.edu/~EWD/ewd08xx/EWD831.PDF https://www.cs.utexas.edu/~EWD/ewd08xx/EWD831.PDF
- antirez 2y agoLua is great to embed, but for Redis I picked it as a scripting language with many regrets because I don't like the language itself: it looks almost like designed to have some kind of friction compared to what you expect to write in a language that is at the same level of abstractions. Little design decisions here and there that cumulate into a language that is somewhat hostile (for me, at least). Yet, it is so fast, easy to integrate, small footprint and reliable, that many times it is still the way to go. Btw, the hostility is present even at C-API level, with the stack approach: it's not rocket science but more cognitive load than needed. Even if I was exposed in the past to stack languages like FORTH, I still had to do some mental gym while writing the bindings. Why?
- helpfulContrib 2y ago[dead]
- ck45 2y agoDid you consider any other languages, like TCL? If yes, do you remember the pros and cons of that set of languages?
- matheusmoreira 2y ago> the hostility is present even at C-API level, with the stack approach > Why? I suspect it's because implementing control mechanisms is much easier when you reify the language's stack. Especially advanced ones such as generators and continuations which require copying the stack into an object and restoring it later. Making that work with the native stack is really hard and many languages don't even try. It also makes garbage collection precise. Lua values in C variables would be placed in registers or the native stack. In order to trace those values, Lua would require a conservative garbage collector that spills the registers and scans the entire native stack. By managing their own stack, they can avoid doing all that.
- orthoxerox 2y agoI like Lua. It's a saner version of JS with much fewer warts. However, JS has a massive, enormous, insurmountable advantage in popularity. If I need an embeddable scripting engine in 2025, I will most likely go with JS.
- ashdnazg 2y agoIn the Spring/Recoil RTS game engine[1] we adapted Lua to have deterministic execution allowing synchronous multiplayer simulation. In addition we relatively easily implemented a precise[2] serialization of the Lua VM, allowing us to support save/load for games with no code required from their side. In other languages these would require much more effort. [1] https://github.com/spring/spring https://github.com/spring/spring or https://github.com/beyond-all-reason/spring https://github.com/beyond-all-reason/spring (yay for forks!) [2] Preserving the order of iteration on items in a hash table after deserialization and further manipulations.
- eviks 2y ago> The one that bothers me the most, might be the fact that arrays (tables used as arrays) are nil-terminated, meaning the end of the array is marked by a nil value This alone should underrate the language even more so that no poor user is exposed to this kind of nonsense
- deleted 2y ago[deleted]
- cyberpunk 2y agoDoesn’t lua use 1 indexed arrays? Breaks my brain.
- tecleandor 2y agoBy default, yes. But you can define them to start in a 0 (doing it index by index, not sure if you can make that default). Or you if you feel like messing with someone, you can start them in any other number. Like -5, for example. :D https://www.lua.org/pil/11.1.html https://www.lua.org/pil/11.1.html
- pjmlp 2y ago> Lua is used in nvim for plugins since 0.5.0, you bet it's efficient ! Not necessarily, plenty of editors have scripting options that aren't going to win any performance price. Also VI architecture goes back to the days of single digit MHz.
- owenthejumper 2y agoThe article doesn't mention some of the most famous Lua cases out there: Roblox used it for game developers, HAProxy uses it for extending the LB, and others.
- enduranceX 2y agoI took Roberto's awesome "Building a Programming Language" course in 2022 and during a live class I had the opportunity to ask why they don't incorporate more stuff into the language. He said that it was designed to be lightweight, effective and simple. Anything that goes against those principles should not be integrated into Lua's codebase.
- liberix 2y agoMaybe it's time to check out Luon [1], which has a syntax similar to Oberon and takes some concepts from Lua, it's statically typed and targets the LuaJIT VM. It was recently covered in HN [2] [1] https://github.com/rochus-keller/Luon/blob/master/Readme.md https://github.com/rochus-keller/Luon/blob/master/Readme.md [2] https://news.ycombinator.com/item?id=42413343 https://news.ycombinator.com/item?id=42413343
- xedrac 2y agoMy complaints with Lua are mostly superficial, but they irk me nonetheless. So if I have to use it, I'll usually opt for Fennel.
- ouraf 2y agoI wonder how viable is Lua for a full stack application or webpage. It has a very barebones standard library by design
- IYasha 2y agoScripting language with the worst syntax I've seen so far.