TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

What I think about Lua after shipping a project with 60k lines of code

321 pointsby gamescodedogs12 months ago

31 comments

JSR_FDED12 months ago
I wrote a trading system where the strategies are written in Lua. It has been a delight, fast and simple. The traders have the expressivity of a full programming language and I can add any function to that language and provide any data as well so that their programming (and execution) sandbox is extremely ergonomic and suited to their specific task. In other words, a trading DSL.<p>Other code outside the sandbox pulls in up to date price data and if certain safety rules are violated will automatically close out positions. So even if the traders code their way into an infinite loop or make other mistakes, the supervisor can step in and automatically prevent disaster.<p>Using Lua to make a language for others has been a wonderful experience. FYI, it was approx 11K lines of Lua).
评论 #40550837 未加载
评论 #40550101 未加载
评论 #40551042 未加载
评论 #40552895 未加载
评论 #40553489 未加载
评论 #40551542 未加载
samiv12 months ago
I&#x27;ve embedded Lua in my game engine and I&#x27;d say that<p><pre><code> - performance is a joke - GC can cause really bad hick-ups - loose runtime typing makes it hard to build static tooling for developer support - lack of predetermined more rigid structure makes some things confusing (like you can mess with the internals such as the meta tables and stuff, which can be useful but also confusing) + functionality wise it&#x27;s adequate for a game programmer, perfect for writing (smallish) scripts of game play + it&#x27;s simple to integrate and provide bindings for + lots of flexibility how you use it and what kind of code you use to write with it </code></pre> In my experience I&#x27;d say that if you&#x27;re planning to integrate and use Lua in your projects you need to<p><pre><code> - have a fallback for performance sensitive code, either by being able to mix and match native and Lua user (game) code or provide functionality natively in your engine OOTB - make sure you can run things properly (using real threads not joke threads) in parallel as much as possible - stay on top of perf at all times and integrate performance tests and bench marks to your development process </code></pre> Despite the problems I&#x27;ve managed to build a Lua code editor that has<p><pre><code> a) auto formatting b) syntax highlighting c) auto completion (limited but still) d) simple navigation support e) built-in help </code></pre> The editor is integrated in my game engine&#x27;s editor.<p>You can find more details on my GitHub<p><a href="https:&#x2F;&#x2F;github.com&#x2F;ensisoft&#x2F;detonator">https:&#x2F;&#x2F;github.com&#x2F;ensisoft&#x2F;detonator</a>
评论 #40553093 未加载
评论 #40552841 未加载
评论 #40555579 未加载
评论 #40552793 未加载
评论 #40552641 未加载
评论 #40557317 未加载
nequals3012 months ago
I&#x27;m wrapping up a multi-year personal project, a game written fully in lua using love2d.<p>To me, the beauty of lua is the simplicity and lack of learning curve: I can usually accomplish whatever I need to without looking anything up (as the author said, everything is a table so there isn&#x27;t much to overthink). Also, the community and support around love2d is fantastic.<p>One thing that&#x27;s bothered me is that lua silently returns nil when you reference non-existing elements. That&#x27;s been a pain when debugging, since a line with a typo (`a = typo`) doesn&#x27;t fail, and the code fails much farther downstream (e.g. when doing arithmetic on `a`). So almost all my errors end up being &quot;trying to do operation on a nil value&quot;, and there is no indication of why it&#x27;s nil.
评论 #40548341 未加载
评论 #40549153 未加载
评论 #40550740 未加载
评论 #40554306 未加载
评论 #40548459 未加载
评论 #40548371 未加载
评论 #40548422 未加载
评论 #40548388 未加载
AlphaWeaver12 months ago
&gt; After that, I went back to Dmitry and asked him if my understanding of “everything is a table” was correct and, if so, why Lua was designed this way. Dmitry told me that Lua was created at the Pontifical Catholic University of Rio de Janeiro and that it was acceptable for Pontifical Catholic Universities to design programming languages this way.
评论 #40548296 未加载
_ugfj12 months ago
It&#x27;s interesting to see Haskell vibes mentioned.<p>Where&#x27;s the &quot;well yes but actually no&quot; meme when one needs it.<p>It&#x27;s not Haskell, it&#x27;s Scheme.<p><a href="https:&#x2F;&#x2F;www.lua.org&#x2F;doc&#x2F;hopl.pdf" rel="nofollow">https:&#x2F;&#x2F;www.lua.org&#x2F;doc&#x2F;hopl.pdf</a><p>&gt; Semantically, Lua has many similarities with Scheme, even though these similarities are not immediately clear be- cause the two languages are syntactically very different. The influence of Scheme on Lua has gradually increased during Lua’s evolution: initially, Scheme was just a language in the background, but later it became increasingly important as a source of inspiration, especially with the introduction of anonymous functions and full lexical scoping<p>Of course, Haskell was also Scheme influenced although it&#x27;s an ML descendant.<p>Speaking of this, I wonder what would&#x27;ve happened if they embedded Lua into Netscape instead of writing JavaScript...
评论 #40550316 未加载
评论 #40548458 未加载
bhaney12 months ago
&gt; I thought I knew C++, but working with ClickHouse showed me otherwise<p>Only language where you can keep having this realization over and over forever. Of course people prefer lua if they can get away with it.
评论 #40548480 未加载
评论 #40548189 未加载
评论 #40554262 未加载
BaculumMeumEst12 months ago
My favorite thing about Lua is that it trivially builds anywhere with a C compiler. Lots of other languages that bill themselves as &quot;embeddable&quot; are a real pain in the ass to build on weird platforms.
评论 #40548882 未加载
评论 #40548289 未加载
thefaux12 months ago
&gt; However, when it comes to separating code into modules or packages, Python is more convenient.<p>Kind of curious about this. I find packaging in Lua quite convenient. I make a file and return either a value or a table full of values and then I require that file in the dependent file that uses the package.<p>Also, wrt to the missing features like an increment operator. It is possible in at most a few thousand lines of lua to implement a lua&#x27; -&gt; lua transpiler where lua&#x27; adds some missing features, such as increment operators, in an idiomatic way. In other words, the generated code looks almost exactly the same as the input code except in places where say `x++` gets translated to `x = x + 1`. As long as your file is less than a few thousand lines of code, the transpiler can run in &lt; ~200ms (and obviously much less for shorter files or much faster if the transpiler is implemented in a faster language). Of course the tradeoff is that the original source code may break existing tooling for lua, though the generated code will work fine.
评论 #40550400 未加载
评论 #40550053 未加载
smaddox12 months ago
&gt; It seems that using OOP in Lua can quickly and surprisingly lead developers into a situation where adding new features becomes really hard.<p>Not just in Lua...
koeng12 months ago
I’ve used teal before, the statically typed Lua that is mentioned at the end. It’s actually really good! There are some limitations (especially around generics) that can be annoying, however. Overall, I really enjoyed using it and would use it again.
评论 #40548046 未加载
评论 #40554619 未加载
评论 #40553135 未加载
mhh__12 months ago
Lua is a language that I really hate quite a few aspects of the design of but still like quite a lot. Weird that.
评论 #40549304 未加载
评论 #40549645 未加载
jmclnx12 months ago
Lua is one language I have been wanting to use, especially since it has hooks into the NetBSD kernel.<p>And<p>&gt;And what about the lack of classes in Lua?<p>to me is a big plus :)
评论 #40548361 未加载
评论 #40548032 未加载
fwsgonzo12 months ago
Congrats on shipping a game! It&#x27;s truly an insane amount of work these days, with all the competition out there.
评论 #40547864 未加载
评论 #40539086 未加载
kbd12 months ago
Anyone here use <a href="https:&#x2F;&#x2F;fennel-lang.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;fennel-lang.org&#x2F;</a> to make Lua more palatable&#x2F;fun?
评论 #40550847 未加载
QuaternionsBhop12 months ago
After 10 years and many projects, the greatest with 40k lines of code including a time-of-intersection-solving single body physics system, I have come to know how to use Lua for my purposes. Even so, from the moment I started watching Rust hype videos on YouTube, I knew I would eventually be converted into a Rust fanatic. At the end of a 2 year project to rewrite my Lua game with a new physics system, I felt it was a good time to learn Rust (and rewrite the game again in Rust). So far I have spent 6 months in Rust and my old tool looks like a toy. How did I ever live without iterators, algebraic data types, the safety of a strong type system, and especially separate types for arrays and hashmaps for god sakes?<p>Lua makes the scope of learning programming smaller compared to other languages, so it is probably fair to say that it is a good language to learn programming with. However, knowing the details of heap vs stack, array vs hashmap, and explaining that to someone learning programming for the first time within a language that attempts to hide those details is frustrating. I can&#x27;t see the smaller picture and view a table simply as a thing that you get and set values from, I can&#x27;t see the weak types as anything more than an annoying source of bugs at runtime, and I crave the borrow checker which saves me from myself.<p>My 10 years of Lua set me up to appreciate Rust&#x27;s fantastic design choices, and I&#x27;m having a great time in Rust land. I wish to remain in Rust land but my finances demand me to use my Lua skills at least a little while longer. End of ramble
评论 #40548066 未加载
评论 #40548471 未加载
评论 #40551520 未加载
评论 #40548123 未加载
评论 #40550774 未加载
评论 #40548208 未加载
评论 #40551370 未加载
NelsonMinar12 months ago
Balatro is another game written in Lua, using the Love2d engine. About 30,000 lines of code (including comments) you can read if you unpack the Steam distribution. Great game and runs very well on many platforms.
andrewmcwatters12 months ago
I don’t know whether or not it’s still the case that at Planimeter we ship the largest pure Lua game engine published on GitHub, but I remember our biggest issue being rather unrelated to the language itself in that game development has some real performance concerns that are hard to measure even with standard tools.
hgyjnbdet12 months ago
I&#x27;ve been wanting to pick up lua for ages. My only issue, as always, is where to start. Is there a runtime I can install where I can start creating with lua? Cross platform, windows and Linux? That will allow someone with no c&#x2F;c++ experience to start doing stuff with it?
评论 #40550213 未加载
评论 #40548281 未加载
评论 #40548351 未加载
评论 #40548370 未加载
评论 #40554036 未加载
Aerbil31312 months ago
Lua is a just perfect for application scripting. It fills a real market gap. It&#x27;s astoundingly simple compared to any other language. In my mental map of programming languages, it&#x27;s C but garbage collected, it&#x27;s Python but simple, it&#x27;s for the express purpose of application scripting.<p>You can have and mutate global variables in Lua. I&#x27;d never voluntarily write in any language with global mutable shared state. But after using Lua in my job for several months I&#x27;ve realized that using mutable global shared state is really the right tool for the job scripting.
annaglotova12 months ago
60k lines sounds crazy for Lua...
wiradikusuma12 months ago
My experience with Lua is only writing Redis scripts.<p>Maybe I&#x27;m pampered, but I found its lack of editor support is off-putting. I juggle between different languages (I&#x27;m writing a &quot;full stack&quot; book about building mobile apps, <a href="https:&#x2F;&#x2F;opinionatedlaunch.com" rel="nofollow">https:&#x2F;&#x2F;opinionatedlaunch.com</a>), so I always need auto-complete when coding.<p>Edit: FYI I use IntelliJ with Lua support, and I&#x27;m comparing it relative to other languages that I also use (Java&#x2F;Scala, Dart, Python, JS)
评论 #40551968 未加载
bartwe12 months ago
We used Lua in the past, but mostly because doing quick iterations in c++ in that project was unrealistic due to 10+ minute build times.
indymike12 months ago
I learned Lua modding the game Homeworld and writing access control filters for NGINX. So easy to understand, mostly because Lua is pretty bare bones. I&#x27;ve always wanted to fit it into a project, but Javascript and Python are tough competition for a language like Lua.
lyu0728212 months ago
what do you think about this take by Jonathan Blow about scripting languages in gamedev: <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=y2Wmz15aXk0" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=y2Wmz15aXk0</a>
评论 #40549334 未加载
评论 #40548678 未加载
评论 #40547818 未加载
shmerl12 months ago
I got exposure to Lua with Cyberpunk 2077 mods and neovim plugins. Some stuff is indeed strange (like array indexes starting from 1 by default), but overall it&#x27;s easy to use.<p>Not sure I&#x27;d want to use it for something big though.
bru3s12 months ago
Congrats on your game!<p>Which would you say were the major hurdles you&#x27;d found with C++ that convinced you against using it again?
rewgs12 months ago
Congrats to the author, but I really can&#x27;t stand Lua. It takes its commitment to simplicity too far IMO, especially with regards to tables not really specifying between (in Python terms) &quot;dict-like&quot; and &quot;list-like&quot; tables. Recursively searching through a table of tables can for this reason be annoyingly difficult.<p>Every time I write it, I find myself wanting a language with just a few more batteries included.
评论 #40550481 未加载
rmetzler12 months ago
Is it intentional that the variable is named “place_f_older” and not “place_h_older”?
wruza12 months ago
Lua is both cool and not, depends on how you look at it. I used it for several years before going elsewhere. I wrote a graphical toolkit with animations in it (based on pango&#x2F;cairo), embedded it for a business-objects platform and used in Quik trading platform for trading bots.<p>It’s very nice, but it has rough edges that never get addressed, despite being proposed in the mailing list in every proposal phase.<p>__newindex only works once, then it’s not “new” anymore. You have to proxy your table with an empty table and a metatable, also make sure you now implement all metamethods for your proxy table to be indexable, iterable, #-able, tostringable and so on. No __setindex for you. Every version of Lua has little changes in there (it uses no semver), so your 5.x iteration protocol&#x2F;etc are bound to that x. Why would you upgrade then? Cause every 5.x lacks something you really want and it’s in 5.&lt;x+1&gt;. There’s also something you don’t want.<p>“a and b or c” and “b or c” paradigm doesn’t work with boolean “false”, because it’s unsurprisingly as false as nil. It’s not haskell vibes, it’s a lack of ?: and ?? operators right there. Nil&#x2F;false are basically second class citizens in Lua cause only these two share the same room, also nil is prohibited from any array.<p>Lua ignores most syntactic ergonomics. You can’t destructure a table, everything has to be “local a, b, c = t.a, t.b, t.c”. And vice versa: “{a=a, b=b, c=c}”, which is syntactically non-fixable due to table duality. Its “…” literal has inconvenient semantics of collapsing before another argument: f(…, x) is equivalent to f({…}[1], x). So you have to “local t = {…}; table.insert(t, x); f(unpack(t))”. No way you can get something like t.push(x) either, for reasons too long for a medium sized comment. Lua is also highly function-esque, but there’s no way to shorten “function (x) return &lt;mylambda&gt; end”.<p>Also its gc is pretty much stop the world. They experimented with it in recent versions, but at 5.1 times you didn’t expect your complex scripts to not freeze for a substantial amount of frames if you “wow so simple”d them and created {} here and there. It takes time to collect the garbage.<p>Rocks, Lua package manager tends to build everything locally, but your windows box ecosystem is out of luck. If you can’t find a pre-built dll, you’re in the mud. That’s windows fault, but your problem at the end of the day. Luckily you can make it yourself, cause Lua has great C API and LuaJIT has ffi. No &#x2F;s here, I made all my wrappers and connectors myself.<p>Overall it’s a nice language idea, fully functional prototype, you name it. It works in the falling in love phase and has unique features for a non-esoteric lang. But don’t expect too much from it in a “marriage” if you’re one of those who want things to get out your way and you don’t get why an obvious feature cannot be done for ideological reasons while compatibility gets broken regularly anyway.<p>I understand that this post looks negative, but that’s because it enumerates only downsides, which are real, although sometimes subjective. I have pretty fond memories of it, but still had to move on.
dcreater12 months ago
TL;DR?
pacoverdi12 months ago
I had two encounters with Lua many years ago.<p>The first to write &quot;stored procedures&quot; in Redis (I forget the correct terminology). It allowed to improve the performance of Django endpoints by an order of magnitude.<p>In the second, I wrote a Wireshark plugin (also not sure of the proper term) to dissect a proprietary protocol.<p>I don&#x27;t remember the details but this is not a programming experience I look forward to renew... (Same feeling about Perl btw)<p>Possibly indices starting at 1 were the most disturbing.
评论 #40554085 未加载