7 ms·
After years of people saying things like they wish they had Lua in the browser instead of "awful" JS, I finally used Lua for the first time writing games with P
by hombre_fatal 7y ago
After years of people saying things like they wish they had Lua in the browser instead of "awful" JS, I finally used Lua for the first time writing games with Pico8 (https://www.lexaloffle.com/pico-8.php https://www.lexaloffle.com/pico-8.php).
I found Lua to be so bare-bones and even quirky that I yearned for the expressiveness of C. I was so unimpressed and miserable working with it that I wondered if these people in the wild who supposedly love Lua have used another programming language in the past 15 years.
So, with that said, MoonScript looks essential.
- chubot 7y agoThat was my experience with it too. I read the "Programming in Lua" book from cover to cover 10 years ago, and it remains one of my favorite programming books. There's a lot of great information in that book (not just about Lua). And I read a lot of their academic papers which taught me a lot about PL design and implementation. However whenever I try to program in Lua it feels both impoverished and verbose compared to Python. People complain about runtime errors in Python but Lua has even more of them. And the libraries are significantly worse for the same task.
- chii 7y ago> I found Lua to be so bare-bones that's a design feature. Though I do hate the 1-based indexing...
- rs23296008n1 7y agoCertainly makes calculations annoying when referring to indices. Not a showstopper but its a niggle nonetheless.
- seibelj 7y agoI love lua but the 1-based indexing is the worst decision of all. Just makes it an odd-duck when bouncing between languages.
- rogual 7y ago1-based indexing I can live with. The fact that the "array length" operator stops at the first nil in the array is what makes Lua unusable for me. Edit: 1-based indexing I can live with. The fact that the things you create with {a, b, c} act for the most part like arrays except for the fact that if they contain nils, the "length" operator is undefined and usually stops at the first nil, is what makes Lua unusable for me.
- klibertp 7y agoThey are not arrays. There are no arrays in Lua. There's only one compound data type (excluding userdata) and that's table. Tables are hash maps, or dicts, not arrays. You can represent arrays with tables, but that would still be "tables acting somewhat like arrays" and not "arrays". Also, you cannot actually store a `nil` value in a table. Nils are what you get when you access nonexistent key; that means the iteration stops at the first n from a 1,2,3... sequence which has no value in the table. If you need to represent a "hole" in the array, use a placeholder object, then convert it to nil at the point of use. There are many libraries of common utilities that make working with tables-as-arrays more convenient. If you don't want to use them, it's mostly trivial to write them yourself. What you shouldn't do, though, is trying to use the raw tables as arrays: that could indeed be a frustrating experience.
- tvb12 7y agoThat's a really common misconception. If there is a "hole" in the table, the result from the length operator is undefined. It doesn't always stop at the first instance of nil. Tracking the table length manually and stashing it in a key (usually "n") is something you see pretty often.
- crtlaltdel 7y ago^this, to me is hard to imagine. i’ve taken it for granted that i didnt need to track the lengths of my list-like data structures myself. at the least checking the length of the list of dictionary keys via some builtin.
- nathcd 7y agoI can (obviously) only speak for myself, but the reason I use and like lua isn't because I particularly love lua-the-language; it's because lua's syntax/semantics/implementations are tiny. I can easily hold it in my head and build on top of it. Its simplicity is its strength.
- jcheng 7y agoBut then surely the Lua code you write has to be more complex, harder to hold in your head, etc.?
- kevsim 7y agoNot sure I buy that argument. By that reasoning Code written in Go must be more complex than code written in Scala since the language is much less expressive. However in practice I haven’t found that to be the case at all.
- jcheng 7y agoThat’s so interesting to me, I totally have had that experience specifically with Go! The lack of exceptions and genetics contribute greatly to Go’s simplicity but I have always felt like my code suffers for it. Do you find that your Go code is, if not more complex, at least more verbose than in Scala?
- nathcd 7y agoIf that were the case, would you also say that surely c++ code is simple and easy to hold in one's head, since c++ itself is comparatively large and complex?
- jcheng 7y agoFor the same algorithm implemented in both C and C++, I generally find the C++ easier to write and follow, yes. Am I weird?
- 7y ago
- Marazan 7y agoThe pico-8 Lua variant does strip out a bunch of stuff that would make it more expressive.
- Supermancho 7y agoLua is a simpler (and dumber) javascript. In some ways this is great, in others it's awful.
- int_19h 7y agoLua is also a much more consistent JavaScript, and that is usually what makes it that much better.
- samatman 7y agoI'm a fan. It takes some getting used to, because things which are semantic features of other languages (anything that's an object, notably) is a construct in Lua. But the entire language fits in your head, and it's a powerful and composable system. I use LuaJIT fwiw; after you get a taste of its FFI, it spoils you. First-class environments, overriding of indexing and assignment, coroutines, there's a lot to love (not you, Wirth indexing and default globals).
- camgunz 7y agoThe "bare-bones" nature of Lua is really nice when you need it, so I like that it's an option. But I would guess that most of the time you need Penlight [1], and I found middleclass [2] to be a pretty good OO library. After that, just build some abstractions. It's very easy to build DSLs in Lua, or if that's a little too dynamic for you (it is for me), it's very easy to use patterns like Builder or use an OO library and build some class taxonomies. Anyway, Lua's not batteries included in lots of ways. It does take a little time to build it up for your specific usage. But most users think that's a core feature. [1]: https://stevedonovan.github.io/Penlight/api/index.html https://stevedonovan.github.io/Penlight/api/index.html [2]: https://github.com/kikito/middleclass https://github.com/kikito/middleclass
- klibertp 7y agoYes, exactly. There are many libraries of common helpers - I use Microlight, Moses, fun, and std; there's a lot of overlap, but they all have unique features, and there's no real cost to bundling them all, so I do just that.
- camgunz 7y agoWow Moses and fun are bonkers. People should know about these haha.
- boomlinde 7y agoAs a Lua proponent, I'll say that it's simple, small and easy to embed in an application. That's worth a lot, and I do think there are solutions that are much easier to express in Lua than in e.g. C. Compared to JavaScript, there are very few surprises, which I think is where people wishing for its replacement are coming from. My gripes with the language are probably common: no arithmetic-assignment operators like "+=", no real arrays, few array-like operations built-in, array-like tables' first index is 1, no integer type... Maybe some of your frustrations come from the characteristics of the PICO-8 API and its development environment. It leans on you to implement a lot of basic game logic in a single file, and if you're editing within PICO-8, you only have a basic text editor with a 128x128 pixel looking glass view into that file. I find that Lua works best when you offload a lot of the gritty logic to the host application and use Lua mostly as a glue language, but in PICO-8 the opposite mostly seems to work to its advantage because it's more approachable to newbies with its small, obvious API surface and all-in-one development environment.
- Rochus 7y agoThere is a whole bunch of languages compiling to Lua, see e.g. https://github.com/hengestone/lua-languages https://github.com/hengestone/lua-languages LuaJIT is still one of the fastest VMs around and it's worthwhile to be used as a backend either by transpiling to Lua or compiling directly to LuaJIT bytecode. Here is a project which implemented both approaches: https://github.com/rochus-keller/Oberon https://github.com/rochus-keller/Oberon
- ebg13 7y ago> I found Lua to be so bare-bones The language itself being bare bones is great. The standard library being bare bones is not so great.
- DayDollar 7y agoI found the luarocks eco-system to be quite typically of web module software. Fractured between versions, incompatible and constantly requiring intervention to work. I do not blame them though- the language has gone through several 2.7 ~ 3.0 years of the snake shisms. PS: Looked around, and it turns out - there is even a lua implementation for the javascript vm.. https://fengari.io/ https://fengari.io/
- anonymoushn 7y agoUsing luaver and luarocks has been a pretty great experience for the last several years, except that there is often no library at all to do what you want. In this case I usually use a C library and the FFI.
- dvfjsdhgfv 7y ago> instead of "awful" JS It's not that JS is awful in itself, it's more that the combination of HTML, JS and CSS is not optimal for creating applications, especially when compared with some desktop options.
- jdance 7y agoI have worked professionally with Java, C#, C++, Javascript, Python, PHP and Lua. Guess which is my favorite language? :) I think I might prefer something like Kotlin or a good lisp to Lua but I have not used them as extensively. Lua is just so consistent and so powerful. Coming back to it after a year off is like coming home. Compared to javascript and python it's behavior has not suprised me once. Closures, variable scope, everything just makes sense, always. I have not googled syntax in years. Once in a while I look at the tiny reference doc. That said I would not write certain things in lua because the ecosystem is very lacking.
- fit2rule 7y agoPico8 is hardly representative of what's great about Lua. Its a fantasy console, designed to be limited. If you want to understand the Lua love, check out some of the other game frameworks like Cocos2D, MOAI, or Godot .. I've used pretty much every language under the sun, but I keep coming back to Lua as my first choice for scripting because its so efficient, and easy to use. There really isn't much that can't be done with Lua and metatables. I prefer it over python because python dependencies are hell, whereas luarocks is a dream by comparison .. plus, libffi is just so darned useful ..