11 ms·
Tables
- oweiler 8y agoStarted coding in Lua 2 months ago and instantly fell in love. Higher order functions, coroutines, the ability to return multiple values from a function, no coercion on comparison operators make coding in Lua a breeze. You can learn most of the language within a day. Ofc not everything is perfect: The package ecosystem is growing but still small compared to other languages. Anonymous function definitions are pretty noisy. Still I think it's one of the best designed languages you can find.
- sdegutis 8y agoLua is amazing in that it is very small, portable, and easily embeddable. But aside from those three things, Lua is semantically almost identical to modern JavaScript. I've embedded both and used them heavily in my various window managers, and these days I personally recommend embedding JavaScript over Lua if possible. But when a small, portable and lightweight language is needed, there's also Sparkling[1], which is like the best ideas of JavaScript with the minimal footprint and portability of Lua. [1]: http://h2co3.github.io/sparkling/ http://h2co3.github.io/sparkling/
- vmsp 8y agoWhat JavaScript interpreter do you use for embedding? I know of MuJS [1] but it only supports ES5. [1] https://mujs.com/ https://mujs.com/
- sdegutis 8y agoMy JS-embedded apps only target macOS so I use Apple's builtin JavaScriptCore framework.
- nikki93 8y agoIn my experience LuaJIT in interpreter only mode has better performance than using JSC (you can’t use JIT in JSC either — only WKWebViews can JIT). (edit: sorry this is regarding iOS)
- sdegutis 8y agoMaybe, but my use-cases (window manager and other automation stuff) don't really have a strong need for speed or high performance. Mostly it just sits there idle 99% of the time and runs callbacks quicker than the UI that it manipulates is visibly updated.
- nikki93 8y agoYeah I think it does end up boiling down a lot to use cases because the big differences b/w Lua and JS are in availability of libs / integration and perf. In my case I do a lot of 2d graphics where love2d.org is available and perf is important. :) C interop is also really important, and LuaJIT C FFI is waaaaay nicer to use than JSC C API. I’ve ended up doing a lot of JS with React Native for “app-y” mobile apps though.
- sdegutis 8y agoIf perf is important, I'm surprised you're using Love2d and not just using C++ with SDL and Box2d directly. Afaik Love2d just uses vanilla Lua (and not LuaJIT) which, while faster than similar languages, is still pretty wasteful of cycles when high perf is needed.
- dividuum 8y agoThere's duktape (https://duktape.org/ https://duktape.org/), which, from skipping over the documentation seems very similar to Lua when it comes to embedding: It also uses the stack based approach. Looks like there's some ES6/7 support.
- zeotroph 8y ago> Sparkling All these "Let's do Lua, but right" languages fill me with both hope AND dread. This also shows what Lua could have become if a few more bold decisions were made. But I guess without a large commercial entity behind it, that was inevitable. Is there list of lua-ish (especially wrt. speed and easy C integration) languages somewhere? I did not know this one for example.
- engineer331 8y agoYou might want to check out Squirrel[1]. It has some major differences when compared to Lua[2], such as a C-style syntax and true objects, but like Lua is known for easy embedding in C and C++. The Source Engine includes Squirrel as one of its supported scripting languages[3], and it's used in non-gaming applications such as the Code::Blocks IDE. [1]: http://squirrel-lang.org/ http://squirrel-lang.org/ [2]: http://wiki.squirrel-lang.org/mainsite/Wiki/default.aspx/SquirrelWiki/Lua%20Compared%20to%20Squirrel.html http://wiki.squirrel-lang.org/mainsite/Wiki/default.aspx/Squ... [3]: https://developer.valvesoftware.com/wiki/Squirrel https://developer.valvesoftware.com/wiki/Squirrel
- mingodad 8y agoThere is also a squirrel fork SquiLu[1] that add some Lua code (like pattern matching, some stdlib), extend it with string IO, have several extensions (sqlite3, http server, mpdecimal, axtls, curl, ...), accept a subset of Javascript/Java/C/C++, ... [1]:https://github.com/mingodad/squilu https://github.com/mingodad/squilu
- vvanders 8y ago> Lua is semantically almost identical to modern JavaScript. Having spent a lot of time looking pretty hard at Lua, LuaJIT, and embeddedable variants of JS(duktape and the like) I think that's a bit of a stretch. It's pretty trivial to induce JS memory leaks[1] that can be brutal on embedded platforms. We had a prototype project written in JS and Lua, same functionality but hit issues like this pretty often. Like most memory leaks they weren't straightforward to track down as well. For my money LuaJIT still reigns supreme despite the fact that it's not under active development any more[2]. [1] http://point.davidglasser.net/2013/06/27/surprising-javascript-memory-leak.html http://point.davidglasser.net/2013/06/27/surprising-javascri... [2] https://www.freelists.org/post/luajit/Looking-for-new-LuaJIT-maintainers https://www.freelists.org/post/luajit/Looking-for-new-LuaJIT...
- wruza 8y ago>almost identical to modern JavaScript What do you mean by ‘almost’? You cannot have fair separate threads of execution or substitute function’s global environment in javascript, but this is the other way ‘almost’. What features does js have beyond syntactic sugar and second-hand techniques?
- Immortalin 8y agoIf you are interested, join my newsletter for Lua: https://luadigest.immortalin.com https://luadigest.immortalin.com Difficult for Lua to reach the same momentum as other languages since it's mostly embedded but every bit helps.
- oweiler 8y agoThank you, I've joined your newsletter. This is exactly what Lua is currently lacking. When I have more time, I'll probably do some writeups on Lua, especially CI/CD and developing libraries.
- Immortalin 8y agoIf you are willing, drop me an email with anything you want me to publish as e.g. a contributing editorial etc. You can reach me at Luadigest at <my username> .com
- AnIdiotOnTheNet 8y agoYou seem like you might know the answer to this question that I've had about Lua: I can find games, window managers, embedded devices, and a bunch of other stuff that can be scripted with Lua, but there doesn't seem to be anything like a Visual Basic equivalent that lets you layout a GUI graphically and tie the controls and events together with Lua, at least not for native applications. Why is that? It seems like it'd be a good fit.
- Immortalin 8y agoI have some familiarity with GUI builders. In general, those tend to be targeted at end-user consumer software like desktop applications, web services, and mobile apps. For game development and embedded systems, there is a strong preference for custom, bespoke stuff. It's especially bad in embedded systems which never had an open source "standard library" till Arduino. The ecosystem is highly fragmented compared to e.g. your average smartphone and PC. An industrial control panel UI using Material Design on a high end ARM core won't necessarily run on a health tracker powered by a STM32 or Atmel chip. For gaming, the story is a bit different. Lua is heavily used there but because every game is different, the GUI parts tend to be done with custom designs. The type of UI builders used in Game Development is rather different than the sort used in desktop software but there are plenty. If you are looking for a minimal resource consumption language with good cross-platform rapid UI development as a first-class priority, I recommend you check out the Red programming language. For Lua, it's use as a mainstream application development language is still in it's early stages. The language follows the mantra of move fast and break things so backwards compatibility isn't a top priority and this can be an issue in evergreen codebases like web apps (unless you are willing to lock to a specific version). Most web servers (most famously OpenResty, a Lua NGINX hybrid) are still on 5.1 due to LuaJIT.
- zeotroph 8y ago> The package ecosystem is growing That is a nice euphemism. The lack of something even remotely resembling a standard library is what keeps me from using lua more than I absolutely have to. Because more complex constructs can be created so easily in Lua everybody is happily copy/pasting half baked stuff from the web. That means there is no common style which might make it consistent across code bases so Lua remains a "Bring Your Own" language. No proper arrays, no easy exceptions, no easily recognizable classes ("but it is so easy with setmetatable etc."), iterators, prettyprint... Plus the various annoyances, such as nil access not being an error, no += (I read all the reasons against it), weird "false" concept, that tables are - if you look closely - neither arrays nor dictionaries, the "require" imports are not modules but more akin #include. In my opinion Lua 6 should drop some historic weirdness (~=!) and make the core language more in line with JS or Python and provide a standard library - even if components there sacrifice some of the holy performance.
- ufo 8y agoI dont understand what you mean by comparing require with include. Lua's require only loads each module once, and doesn't introduce any new variables to the local scope.
- wruza 8y agoLuvit is node-copied environment, which nils “no library” downside. Lua doesn’t push it, but it is there and even works. As of no classes or ‘weird’ parts, js has more rich history of bullshit included, not included or misbehaved than any language ever. I’m not going to enumerate these here. You just get used to it and now can’t stand it in others. Js prototyping is much dumber though, so it could be hacked by 5-minute newbies easily, unlike mt/index magic. But there is no such thing like ‘being in line’ with javascript, since it draws no line. You can write a parser that makes Lua js-like (or even better) in a couple of hours, but that woudn’t make it popular. Including it into a browser would though. But browsers still resist to include anything viable like RxRS scheme-likes at least that could be transpilation target, repeating that unsmart ‘maintaining complexity’ argument. You’re stuck with js and that’s why rants go all the way. If it had enough concepts, there would be less rants and more transpilers, but it is dumb af and oriented on end-developers rather than on library, system or metadevelopers. At least wasm is a hope, but it was not seen seriously yet in this regard. Ps. require() is a regular one-time module-load routine, nothing to do with #include.
- enriquto 8y ago> not everything is perfect: The package ecosystem is growing but still small compared to other languages. This is a positive point to me. I love python but hate pip and stuff.
- Annatar 8y agopip really sucks, in fact any packaging system discrete to its programming language sucks, because it bypasses the operating system's software management subsytem (pkgadd, pkgsrc, rpm, et cetera). Then one has to have an imaging system like Docker to work around that, so developer's convenience leads to one bad decision after another in the operational repeatability space.
- pmontra 8y agoI used to install Ruby gems with apt circa 10 years ago but quickly gave up because they were outdated and I couldn't have different versions in different projects. Same with Python later on. Things like virtualenv solve the problem of having multiple versions of the same package or interpreter in different projects. Rpm and apt can't do that, that's why developers are using package managers for virtually every language. Furthermore creating native packages for even the major distros and LTS releases is too difficult. There are also tools like asdf that handle multiple languages (and databases!) Docker solves the problem of distributing the application. Virtualenv is quite weak about that. Docker can also be used to create separate environments on the development machine and install packages without virtualenv. We still need pip because nobody creates native packages. The same reasoning applies to every language I'm working with (Ruby, Node, Elixir, PHP.)
- Annatar 8y ago"Furthermore creating native packages for even the major distros and LTS releases is too difficult." This is simply not correct: the truth is that people are lazy and don't want to spend the required time reading the documentation, the first thing a real engineer does. Instead, they just want instant gratification. They just want to hack. OS packaging is actually quite easy. "We still need pip because nobody creates native packages." I created over 170 CRAN R packages as RPM's. Was it time consuming? You bet! But now it's done correctly. Now it's done cleanly. Now I don't need nonsense like Docker, and I could even plug them all directly into Kickstart and have Kickstart spit out ready to serve systems with a rich R environment on them. With no scripting or any code. Just because I made RPM's, the client now has an architecturaly simple application ecosystem. Simple is robust.
- jxub 8y agoSo... You've yet to fall in Löve?
- ungzd 8y ago> Higher order functions, coroutines, the ability to return multiple values from a function These features are in almost any language nowadays, including most of languages that AOT-compile to native code. Well, maybe without multiple returned values, with tuples instead, but this is the same thing, especially if there's some primitive destructuring support. Type coercion for comparison is quite rare too, even js has `===`. But no standard library at all, so everyone brings his own incompatible hacks (by copy-pasting snippets) and processes lists (hashes emulating lists because there are no real lists) with `for` loop. Even with `for` loop it's not that obvious how to loop over list. I tried writing in Lua and can't stand it at all, even JS feels much nicer. Lua is minimalism for sake of minimalism, and it heavily hampers practicality. Easily embeddable? Who cares if embedded runtime is 100 Kb or 2000 Kb? Well, it might be a good language if comparing it to Basic from 80s home computers, so it's used in PICO-8.
- vvanders 8y ago> Who cares if embedded runtime is 100 Kb or 2000 Kb? We ran Lua on the PSP with 8MB of system memory inside a pre-allocated block of 400kb. Did the whole game logic and state management with no hiccups(and this was before LuaJIT). Not everything is desktop scale, lots of applications in spaces like routers, wearables and other constrained devices. I've also seen few langauges handle coroutines and clean and simple as Lua does them.
- fb03 8y agowhat game?
- rebolek 8y ago> Who cares if embedded runtime is 100 Kb or 2000 Kb? That's a joke, right?
- sdegutis 8y agoLua tables are semantically almost identical to JavaScript objects. The one key difference is that any object can be a key in a Lua table, whereas all JS object keys are coerced into strings. The other more minor difference is that you use getmetatable() and setmetatable() instead of modifying or setting object.__proto__
- fixermark 8y agoThis is one of the things I enjoyed about Lua relative to JavaScript. Subjectively, Lua tables felt like a cleaner abstraction than JS objects. In general, I have both of the languages filed in my head as "Decent scripting languages with the risks associated with any-typed variables and soft coercion", but given those risks, I prefer Lua because it's simpler; there are just fewer abstractions and corner cases to trip over. Contrasting with JavaScript, where the sheer scope and complexity of the language (which has only grown as features have been added to try and avoid the sharp edges, which unfortunately only makes the sharp edges into legacy sharp edges, it doesn't eliminate them) means there are an uncounted number of ways to shoot yourself in the foot (https://www.destroyallsoftware.com/talks/wat https://www.destroyallsoftware.com/talks/wat).
- sdegutis 8y agoI've been a fan of that talk since 2012, and I agree that JS is full of bad decisions (but hindsight's 2020). But I use JS every day for work and probably the only gotcha I actually run into is due to hoisting, which my linter (tslint) catches for me within my IDE (VS Code). Meanwhile all the new features are actually letting me code more quickly and easily, so that writing Lua now feels archaic and frustrating. Destructuring for example is a great way to emulate multiple return values, and it's more generally useful than just multiple returns too (used in parameter lists, etc). I do hope for the day backwards compatibility in JS is broken and we get a cleaner, lighter, more portable, more embeddable spec and implementation. I don't think we'll see that for another 15 years at this rate. But it'll probably arrive one day.
- andai 8y ago
- funnotatparties 8y agothe standard PHP array everyone its really an amazing object type, especially when you are given a great api to manipulate it. Which PHP does have.
- sdegutis 8y agoLua predates PHP by 2 years, and I'm sure this combination of arrays and hash-maps predates both languages. Either way, I'm not sold on it. Arrays and hash-maps are fundamentally different, not only for optimization's sake[1] but even in how people use them. [1]: Recent versions of Lua now try to detect whether a table is an array, and apply optimizations when all its keys are ordered numbers without holes.
- kgwxd 8y ago>Lua predates PHP by 2 years Woah, TIL. At most, I would have guessed it was 10 years old.
- majewsky 8y agoIt's amazing how many of the languages that feel recent today actually came out in the 90s: Python, JavaScript, Lua, Haskell, Java from the top of my head. Python is only five years younger (1990) than C++ (1985). I guess it shows how much time you need to invest until a language is mature enough to enter common use, unless it's backed by a large entity like Microsoft (C#), Google (Go) or Mozilla (Rust).
- wahern 8y agoLua doesn't try to detect whether a table is an array. The way it works is that a table is internally composed of two data structures, a hash part and an array part. Normally, integer keys go to the array part and everything else to the hash part. However, integer keys of a certain size will overflow into the hash part so that, e.g., storing a single integer key of 2^32 doesn't allocate an enormous empty array part. In this way Lua already optimizes the array use case naturally. It never tries to infer whether a table is supposed to have array semantics or hash semantics. You can use a table as a hash, as an array, or (commonly) as both. The cost of this simplicity and concision is born by the semantics of the length operator (#). The default __len metamethod on a table does a binary search looking for the first missing positive integer key, the boundary that marks the end of a logical array. The binary search will work even if your integer keys have spilled over into the hash part, though it works much faster if it doesn't have to inspect the hash part. This why in Lua your arrays can't have holes (non-sequential positive integer keys), at least not if you want #t to behave as expected. Lua has no way of knowing the size of your array otherwise, at least not for plain tables lacking user-defined metamethods. That said, there's a convention that uses the string key "n" to record the intended length. For example, table.pack() assigns the argument list to a table and sets "n" to the number of arguments. It does this because a nil argument value would create a hole. Also, since Lua 5.3 you can overload the __len metamethod, which could simply return t.n. Similarly, you can overload the __index and __newindex metamethods so that insertions update t.n or some other marker. FWIW, I've tried hard not to express any value judgments in the above description. I've also deliberately abstained from discussing array-related language proposals.
- leggomylibro 8y agoOne thing that I like about Lua over Javascript is how self-documenting, fun to write, and easy to read it is. It has a very simple syntax, but the extensibility of its core structures (like tables) let you accomplish a lot with that simplicity. Its 3rd-party libraries also tend to be closer to C/C++'s "drop-in" solutions like STB[1] than the enormous JS ecosystem which often requires extra tools like Node and/or extra packages like JQuery. Admittedly, Lua's ecosystem is much smaller than Javascript's, but in my experience Lua is vastly easier to maintain. You can certainly write bad Lua, but it's one of the only languages where I don't implicitly dread reading other people's code. It is sort of annoying that tables which are treated like arrays are 1-indexed by convention, though. [1]: https://github.com/nothings/stb https://github.com/nothings/stb
- chrisco255 8y agoDoes C/C++'s STB or Lua's 3rd party libs cover cross-browser quirks and http methods like JQuery does? It sounds like Lua/C and JavaScript are used for totally different things. And Node isn't an "extra tool" it's a server. No doubt JS projects sometimes come loaded with excessive dependencies but Node/JQuery are bad examples and not equivalent by any stretch to STB.
- nikki93 8y agoLua doesn’t really run in browsers (except with emscripten or WASM? and also fengari (Lua interpreter written in JS with interop and GC sharing)) but for http luasocket / cqueues / openresty libs are good, and for servering also openresty seems good. The equivalent for stb libs would be crossplatformness and in my experience they’ve worked for their advertised purpose on mac, windows, linux, android, ios.
- leggomylibro 8y agoNope; Lua is not a good choice for a website's frontend. But people use Javascript for a lot more than just websites, and I've lost count of how many times I've been frustrated that a JS library is distributed exclusively through package managers like NPM even when the library is not specific to a browser.
- dkrikun 8y agoHave been using Lua 5.3 and luajit for a few years. Also have bought the lua book for 5.3. My thoughts: -- really sweet consistent and simple language -- weak, fragmented ecosystem -- easily embeddable yet powerful -- few bad decisions: arrays as tables, coercions, 1-based arrays, no gradual typing
- stcredzero 8y agoGradual typing can be very useful. Coercions, like any implicit casting/conversion can have problems. 1 based arrays are a pain. On this much, I'd agree. Why are arrays as tables a problem? Is it a matter of efficiency, or is it a type safety issue?
- Jyaif 8y agoThe one-index is as idiotic as ever, especially for a language that is supposed to interact with other languages.
- dang 8y agoPlease follow the site guidelines when commenting here.
- jdonaldson 8y agoTables and metatables are incredibly flexible constructs in Lua. I was able to support nearly all the Haxe language constructs for Lua with little more than tables, floats, and strings. https://haxe.org/blog/hello-lua/ https://haxe.org/blog/hello-lua/
- anonytrary 8y agoLua's feature set is tiny, and that's precisely what I love about it. Ruby feels a lot like Lua, but I vastly prefer Lua to even Ruby, because of how minimal it is. As someone who writes ES6 on a daily basis, I feel that Lua's syntax explains itself -- you can start writing Lua code in 30 minutes. People have always said that Python is fun to write, but I've never felt that about Python. On the other hand, I can definitely say that Lua is pleasing to write in. Python, to me, has always felt like a chore compared to Lua.
- agumonkey 8y agoI'm on the python side of the fence, even though it's not my favorite thing by far, I rapidly clicked to their idioms. I like lua for all the reasons people say lua is great but I always forget it :)
- abecedarius 8y agoFunny, it's Lua that feels like a chore to me, because most things take around twice as many lines of code than in Python. (Though some of those lines are just 'end'.) I want to like Lua more because it's so much simpler and faster, but it could've come closer in expressiveness and catching errors.
- legends2k 8y agoSame is true for me too; lack of batteries (std lib) isn't helping either.
- prestonh 8y agoLua looks like such a fun language to program in, but unfortunately I cannot justify its use in my work aside from small side-projects.
- lxe 8y agoIn 2010 I worked on building a "dynamic" web app that would run on a very tiny embedded device -- no MMU, about 130 bogoMIPS. Think of an old wireless router you have at your parents' place. There aren't that many options for building a "modern" web backend on something like this -- the most popular being C compiled into executable(s) served via thttpd and CGI. Things like templating, or JSON parsing for that matter, would be much easier in something higher level than C, but python, PHP, node, etc are simply too huge and slow. I discovered Lua, and it fit the niche exceptionally well. The syntax and the data structures takes a while to get used to, but once you do, they feel rather powerful, especially for such a lean interpreter. It compiles into something like a 120k statically linked executable and is (relatively) phenomenally fast -- not only for the tiny computer on which I had to run it, but also for me, who had to write a complicated web app using it. I almost felt like a demoscene developer -- I was able to run something that would otherwise require a full featured machine on a tiny embedded board. Even to this day, LuaJIT, OpenResty, Lapis remain up there on the benchmark tables when it comes to web apps.
- slezyr 8y agoYou can run PHP on router with 3Mb of storage and 64Mb of ram. http://ph7.symisc.net/ http://ph7.symisc.net/ DIR-320 Used php for it's GUI.
- seppel 8y agoBack in 1998, Apache, PHP, Mysql and Netscape 4 did fit into 16 MB of RAM :)
- CharlesW 8y ago> Things like templating, or JSON parsing for that matter, would be much easier in something higher level than C, but python, PHP, node, etc are simply too huge and slow. FYI, there are some nice (small, performant) JavaScript runtimes now. A typical Moddable[1] xs engine app needs less than 200KB of ROM, runtime included, and a few dozen KB of RAM to run. [1] http://www.moddable.com/ http://www.moddable.com/
- ubertaco 8y agoDoes there exist something along the lines of Typescript for Lua that adds optional type annotations and static analysis?
- andrewmcwatters 8y agohttps://github.com/titan-lang https://github.com/titan-lang
- ufo 8y agoI think the closest analogy would be Typed Lua. Titan is a bit of a different approach (simpler type system, more focus on performance)
- krylon 8y agoMaybe not quite what you are looking for, but http://terralang.org/ http://terralang.org/ is very Lua-like, has static typing, and compiles to machine code.
- varunramesh 8y agoLua is an awesome language, but there are significant gotchas, especially with regards to the behavior of ipairs and the length operator - https://blog.varunramesh.net/posts/lua-gotchas/#the-behavior-of https://blog.varunramesh.net/posts/lua-gotchas/#the-behavior...
- andrewmcwatters 8y agoI love that Lua uses one-based numbering, if only to point out undesirable developers who don't understand the difference between offset and count. You don't work with pointer arithmetic directly in Lua syntax, so why would you need offsets? Complaints about ~= as the negation of equality are as petty as well. The syntax in question isn't just used by Lua, either, and it usually tells me that a developer can't respect differences between languages.
- Pimpus 8y ago> The syntax in question isn't just used by Lua, either, and it usually tells me that a developer can't respect differences between languages. Actually, the two examples you bring up are paragons of asinine design. I can't imagine it being easy to justify such design decisions, your attempt to do so was wholly unconvincing.
- ufo 8y agoLua uses 1-based indexing because its initial userbase were engineers used to FORTRAN. As for ~=, you need to keep in mind that Lua goes all the way back to 1991 and back then there wasn't a big pressure to make your syntax look like C (of Java or JavaScript) like happens today. Syntax used to be much more varied.
- int_19h 8y ago~= is a poor choice in and of itself, because it doesn't have any clear justification. It would make some marginal sense in C, where it's binary negation, but that's not the case in Lua - it only ever uses ~ to mean "not" in that one context of inequality. And, on the other hand, ~= looks too much like an attempt to spell out ≅ in ASCII, but the meaning is completely different. If anything, /= (as used in Algol-68, Ada, Eiffel etc) makes a great deal more sense as an obvious rendering of ≠. It's unfortunate that C confused matters by reusing it as assignment.
- scns 8y ago
- coleifer 8y agoLove lua. Luajit is stupid fast and the ffi stuff makes it a snap to integrate with other libraries. You can find Lua in neat places like nginx, redis, tokyotyrant... I dislike the direction python has been going (twisted...i mean asyncio, type annotations, f strings). Lua is like a breath of fresh air. Downsides are small standard library and 1-based indexing shudder.
- singularity2001 8y agolua could be really nice if they fixed these: indexing starts at 1 but a[0]=1 does SOMETHING -- // # stupid -- comments! // 0 is truthy # I just love the simple logical mathematical python way (0=ø=()=[]={}=false) if undefined … -- treated as nil function pseudoclass:new … But by far the biggest complain is the packaging. luarocks SUCKS more than almost anything, at least for me. luarocks install torch Error: Your user does not have write permissions sudo luarocks install torch Error: No results matching query were found. and on and on and on (non-representative excerpt of my pains)
- cozuya 8y agojavascript could be really nice if they fixed these: 0 is falsey
- andrewmcwatters 8y ago> 0 is truthy Nope. 0 being falsy only makes sense in pointer-oriented languages where NULL is a null pointer at address 0. In Lua, 0 is a number. It's not a pointer address. Which leads to: > a={1} a[0]==nil a[1]==1 indexing starts at 1 but a[0]=1 does SOMETHING So does -1: should -1 be falsy, too? > if undefined … -- treated as nil Pardon? It is. Are you asking for an undefined keyword? Why? In the Lua C API, you already get `lua_isnoneornil` to begin with. > function pseudoclass:new … Lua is a prototypal language. > but by far the biggest complain is the packaging. You know, thank God. Because JavaScript is probably the closest thing to Lua and look how that turned out. The only thing holding it back is that the community doesn't need or want it. It's also small enough that perhaps no one has made a good package manager for Lua yet. But the `package` module in Lua already provides search paths, so it's fairly low effort. Frankly, I've never had a need for it. I don't want npm for Lua.
- oweiler 8y agoYou just need to remember that only false and nil are false.
- int_19h 8y agoUsing -- for comments is a long-established convention: Ada, Eiffel, SQL... 0 (and everything but nil and false) is truthy is also pretty common in the Lisp world. Side note: I actually find it ironic that Python of all languages does this implicit falseness thing on so many types, given that it puts "explicit is better than implicit" on its banner. I don't see the difference between treating an empty list as false when the context requires a Boolean value, and treating string '0' as numeric 0 when the context requires a numeric value. And it can be a source of bugs - while there are many cases where an empty list and None are semantically equivalent, that's not always true. And it can be something that's very easy to forget when reading code that is broken that way (e.g. during code reviews). I'd much rather have functions like `is_none_or_empty`, `is_none_or_zero` etc that make it clear what the check is actually doing.
- scythe 8y agoLua is a pleasing language to work with, but only that, unfortunately. It has never caught on in desktop apps due to a lack of suitable GUI library bindings. It never caught on in web apps thanks to a lack of suitable web frameworks. There are at least a dozen half-implemented or abandoned Lua GUI projects, including at least three Lua-to-Qt binding toolkits and one briefly maintained by PUC-Rio (where Lua originates). But the other day I wanted to write a simple GUI to support formatting documents with a certain LaTeX template, and I struggled to find one that could guarantee that my users would be able to run the software on their various OS platforms. There are even more half-working Lua web frameworks, including Lapis, Ophal, Orbit, Sailor, and Tir, three of which have had brief moments in the limelight as the "preferred" Lua framework. There are at least three projects that attempted to add types to Lua, and no less than six parallelism libraries. If you view it as a competitor to Python, Lua is a case study in open-source community mismanagement. There are five projects that attempt to solve every outstanding problem usually none of which has more than three regular contributors. There are many competing "Lua standard libraries", and after the falling out between Mike Pall and PUC and the controversial introduction of integers, there are four similar but distinct versions of the Lua language in common use: Lua 5.1, Lua 5.2, Lua 5.3, and LuaJIT 2. But if you view it as a research project, Lua has been incredibly fruitful and continues to be. Any organization with the critical mass required to maintain their own internal ecosystem can use Lua without ever noticing the disarray in the wider community, and many do. It's just... annoying... from the perspective of the US/European open-source crowd.
- andrewmcwatters 8y agoPerhaps I'm uninformed, but I was always under the impression there were two camps: Lua 5.1.5/LuaJIT users, and Lua 5.2+ users. Game developers, performance-sensitive developers, FFI users all tend to use the former, and when not necessary, I've seen people use the newer versions. Is there more segmentation between 5.2 and 5.3 than I'm aware of?
- dividuum 8y agoMy favorite part of Lua tables is the syntax feature that makes it possible to use a single table argument when calling a function like this: some_func{ key = value; another_key = another_func{ foo = "bar"; } } Note the use of { and } instead of ( and ). This almost makes it possible to build a DSL. Oh. And the __mode option in metatables to create weak tables by key/value.
- i_feel_great 8y ago"A Lua configuration file is also code" is what won me over initially. https://www.lua.org/pil/10.1.html https://www.lua.org/pil/10.1.html
- shawnz 8y agoThis is a major antipattern IMO since it makes it very difficult to programatically change configuration files. Unfortunately it seems to be all the rage these days to make a DSL for your config files.
- i_feel_great 8y agoThat is probably true but I have been changing mine manually and then pushing them via version control.
- jessaustin 8y agoWhat do you have in these files that requires this?
- stevekemp 8y agoOne obvious thing I've missed in the past, in some program configuration-files is the ability to have per-host config checked into git. Sure you can create symlinks so "~/.foo" is a pointer to "~/.foo-www.example.com", or "~/.foo-www.example.net". But having the ability to load a per-host file, natively is a good thing.
- corysama 8y agoI don't understand. Lua config is just Lua data structures. Load Lua data structures, modify them directly because they are the language's native data types, serialize them back to text. How much easier do you want it?
- Annatar 8y agoA plain ASCII text file which doesn't require the user to be familiar with any programming language. The fathers of UNIX postulated that for a reason. It came out of experience.
- oldandtired 8y agoI have been using tables in Icon since 1986 (they were in Icon before that). Tables allow key/value pairs to be anything. You can set up a specific value to be returned if the key presented to the table doesn't exist. Lists, sets, tables, records are the mutable values, strings, csets, integers, reals are the immutable. Failure is an option, so all expressions can succeed and return a value or fail with no result. So there is not an issue with the truthiness of values and the semantics of true/false. Simple tests like if a < b < c < d then { do something } else { do something } are standard in the Unicon/Icon languages. Icon was my goto language until about 2000 or so and thereafter I have been using Unicon (the Unified Extended Dialect of Icon). 1 based indexing is very useful when you have the dual of indexes < 1 starting at the right hand end of any string or list. Hence, you can work from either end if you need and there are good use cases for starting from the RHS of strings and lists. I have looked at Lua in the past and nothing in it has given me any incentive to move away from Unicon/Icon. Lisp/Scheme/Kernel and FORTH/Factor have more notable (as far as I am concerned) facilities than Lua. Though Unicon/Icon has flaws and certain kinds of missing facilities like lambda's, I find that I am more productive in Unicon/Icon than I have been in other languages. YMMV.
- Grue3 8y ago>can be indexed not only with numbers, but also with strings or any other value of the language, except nil. What could possibly be a reason for not allowing nil?