8 ms·
I've never heard of Lua, but now that I am looking at it, it seems very friendly. Love how they call things what they are, for example `local` is just a local v
by kirillzubovsky 6y ago
I've never heard of Lua, but now that I am looking at it, it seems very friendly. Love how they call things what they are, for example `local` is just a local variable, or `repeat X until Y` for a loop. It's a joy to see, to be honest.
- umvi 6y ago1-index kept throwing me off though
- snazz 6y agoIt’s unfortunate that Lua makes some strange decisions, but the powerful functionality totally outweighs the weirdness (metatables are especially cool). I really like Lua, especially for game programming with LÖVE.
- DarkWiiPlayer 6y ago"strange" in the sense of different from other languages in 2020, yes, but not strange from the perspective of its developers. Lua is a language for both hardcore C programmers and complete n00bs wanting to configure their C programs. In that context, position-based indexing makes much more sense, as it's how most non-programmers think.
- anonymoushn 6y agoI find it strange that you choose to use terminology that does not uniquely identify what you are talking about when the rest of the thread uses terminology that does uniquely identify what they are talking about
- wafn 6y agoI think 0-index causes a lot of new programmers (and non-programmers) confusion because they aren't used to treating 0 as a counting instance. For example, A.D. 2020 suggests that (allowing for the various changes and debates) Jesus was born 2020 years ago, instead of counting the first year which would make (2021-1 day) years ago. I see this every year around New Year, headlines saying "Actually, it will be [year + 1]"
- shakna 6y agoOnce you get used to it, it does help prevent a whole bunch of off by one errors though, as you don't need math when grabbing a range. Like a string will always be: s:sub(1, #s) And a sequence table will always be: for i = 1, #t do t[i] end
- anonymoushn 6y agoI disagree. Particularly when parsing strings, it's useful if the upper bound of one substring is the lower bound of a nonoverlapping substring immediately after. For example, here's a routine to split a string into the part before the first dot and the part after: function split_dot(s) local idx = s:find(".", 1, true) if not idx then return s end return s:sub(1,idx-1), s:sub(idx+1) end It may come as a surprise that one should use a difference of 2 to skip over one character! In a language that used the half-open interval convention we would end up with: s:sub(0, #s) and for i = 0, #t do t[i] end which seem just as good to me.
- shakna 6y agoYou wouldn't end up with this: s:sub(0, #s) You would end up with: s:sub(0, #s - 1) Which demonstrates the off-by-one error.
- anonymoushn 6y agoCan you explain what the intent of the code is and what the error is? It looks like the original code just grabs a substring containing the entire string. If the language used half-open intervals with an exclusive upper bound, the code I posted would also do that. In python, for example, the operation of copying a list can be correctly written l[0:len(l)]. You're more likely to see l[::] or list(l) though. Edit: I think maybe the proposed error that's being avoided is "a user tries to use a closed interval when sub takes a half-open interval." It seems like the opposite error is similarly likely though. Some areas where it's nice to have half-open intervals like using a modulus to restrict a value to an interval or parsing strings don't have such a symmetry. Notably if you're making a binary heap the formulas come out much nicer with 1-indexing than with 0-indexing, but I haven't met any other examples where this is the case.
- joan_kode 6y agoThe main problem with that decision is that every discussion having anything to do with Lua always devolves into repetitive bikeshedding about the 1-indexing.
- catblast 6y agoIn the context of language design, the arguments for 0-based indexing rise above bikeshedding. https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/E... Sure it may not be the most critical point about language design, but it's not just bikeshedding either. For one thing, it is a language semantics issue rather than plainly syntax issue. I still like Lua, and maybe you don't even agree with Dijkstra's argument, which is also possible to make, but doesn't mean its bikeshedding - which seems to be a totally overused term to basically mean any argument I don't want to have.
- soneca 6y agoAre you bikeshedding bikeshedding?? Just kidding, I actually agree with your point that the term is just demonstrate that you don’t want to have a conversation by diminishing the value of anybody having it.
- skrebbel 6y agoFwiw Dijkstra practically invented bikeshedding
- andi999 6y agobikeshedding considered harmful
- pull_my_finger 6y agoRoberto Ierusalimschy makes an interesting point on this in an interview[1] last year. > When we started Lua, the world was different, not everything was C-like. Java and JavaScript did not exist, Python was in an infancy and had a lower than 1.0 version. So there was not this thing when all the languages are supposed to be C-like. C was just one of many syntaxes around. > And the arrays were exactly the same. It’s very funny that most people don’t realize that. There are good things about zero-based arrays as well as one-based arrays. > The fact is that most popular languages today are zero-based because of C. They were kind of inspired by C. And the funny thing is that C doesn’t have indexing. So you can’t say that C indexes arrays from zero, because there is no indexing operation. C has pointer arithmetic, so zero in C is not an index, it’s an offset. And as an offset, it must be a zero — not because it has better mathematical properties or because it’s more natural, whatever. > And all those languages that copied C, they do have indexes and don’t have pointer arithmetic. Java, JavaScript, etc., etc. — none of them have pointer arithmetic. So they just copied the zero, but it’s a completely different operation. They put zero for no reason at all — it’s like a cargo cult. [1] - https://habr.com/en/company/mailru/blog/459466/ https://habr.com/en/company/mailru/blog/459466/
- TedDoesntTalk 6y agoHow about this: The empty string and 0 are truthy. Why?
- cl3misch 6y agoMaybe because all variables are `nil` by default, and checking on undeclared variables does not raise an error. So `if foo then ... end` is often used as an existence check, where `foo = 0` should be truthy.
- anonymoushn 6y agoThis is probably a good thing, if you don't want to have tickets filed about whether midnight (time of day) is truthy, whether Jan 1, 1970 is truthy, why some type of empty collection is truthy but others are not, etc.
- pansa2 6y ago> This is probably a good thing, if you don't want to have tickets filed about whether midnight (time of day) is truthy Agreed. Here is an example of exactly that in Python: https://bugs.python.org/issue13936 https://bugs.python.org/issue13936
- DarkWiiPlayer 6y ago0? Because Lua isn't C. It makes sense for C to treat 0 as falsey, because (void*)0 is Cs way of expressing a nil-value, as well as not having a dedicated boolean value to keep the language simpler. Lua, both has a dedicated nil value and a boolean type, so there's no reason whatsoever to treat zero as falsey, other than the C cargocult. As for empty strings, I really don't see the rationale behind it. An empty string is not nothing. At the very least, it still holds the length-data of 0, so it's conceptually more than just nil and should thus still be truthy.
- pansa2 6y agoIf you make the empty string falsy, surely you need to make all empty collections falsy? Python does this, which leads to people checking whether a list is empty using `if l` rather than `if len(l) > 0`. I‘d rather they stuck with “explicit is better than implicit”.
- pansa2 6y agoYes. There are pros-and-cons of 1-based indexing when considered in isolation. But for Lua, a language that’s commonly used tightly-coupled to C, 1-based indexing is extremely awkward.
- Descartes1 6y agoCheck out (the now unfortunately named) CoronaSDK from (the also unfortunately named) Corona Labs. It's all Lua based and is now entirely MIT open sourced. One of the easiest to code cross platform development languages there is.
- grijul 6y agoI was introduced to game development (and my first "real" project) through CoronaSDK 3-4 years ago. Wrote a very simple android game. Ah it was fun! :-)
- andai 6y agoRenamed to Solar2D.
- lioeters 6y agoTo save someone a search, here it is: https://github.com/coronalabs/corona https://github.com/coronalabs/corona
- choicenotchance 6y agoWhoa! CoronaSDK got opensourced?! It was the hype back in 2012-15ish era. It and Ionic etc. Always wanted to learn something like that but never got beyond backend dev thanks to overloading office work by my jerk employer back then. Will definitely check it out now, now that I'm in a better place and have weekdays to myself purely.
- ericcholis 6y agoI was first introduced to Lua via World of Warcraft. It's the scripting language used for Interface Customization. https://www.wowhead.com/guide=5338/comprehensive-beginners-guide-for-wow-addon-coding-in-lua https://www.wowhead.com/guide=5338/comprehensive-beginners-g...
- JayPeaEm 6y agoSame here! SQL, Lua, C++, and HTML all around 2006 to host private World of WarCraft servers. Great talking point at my previous interviews.
- greggman3 6y agoA popular fantasy game console based around Lua https://www.lexaloffle.com/pico-8.php https://www.lexaloffle.com/pico-8.php Celeste, a successful commercial game, was prototyped in Pico-8 https://www.lexaloffle.com/bbs/?pid=11722#p https://www.lexaloffle.com/bbs/?pid=11722#p
- wastedhours 6y agoThe Defold game engine (recently spun back out of King) uses Lua as the main language [0] [0] https://defold.com/manuals/lua/ https://defold.com/manuals/lua/
- brainbag 6y agoThey also open sourced it and created a new organization, the Defold Foundation, to own it. I have built commercial games but only some incomplete side projects with Defold, Corona, and Love2D. Of the three I thought Defold was the best and was supported by a company of commercial game developers. If I were going to start today it would be my top one to consider.
- xorcist 6y agoThey didn't open source it. There was a (righteous) flamefest among the HN comments upon the announcement and they had to retract that part. Don't let that stop you using the software of course, as long as you have knowledge of the actual license being used.
- gauchojs 6y agoA decade ago, I thought Lua would be where JS is today. But JS won... A new text editor in Lua, why not: https://github.com/rxi/lite https://github.com/rxi/lite (Rxi is awesome, see https://rxi.itch.io/ https://rxi.itch.io/)
- cl3misch 6y agorxi indeed is awesome! Do you know in what language/engine his (her?) tools on itch.io are written? They all have an awesome pixelart look to them and I wonder if (s)he uses lua for them too.
- backpropaganda 6y agoIt's Lua. They use Love2D.
- soapdog 6y agoalso, just a sidenote which you might already be aware of, a lot of itch.io used to be written in Lua. Check out Moonscript, A language that is like the coffeescript of Lua (https://moonscript.org https://moonscript.org), and Lapis which is a web framework (https://leafo.net/lapis/ https://leafo.net/lapis/) that can use Lua or Moonscript. Itch.io used to be built with both, I don't know if that remains true today.
- metroholografix 6y agocurl -sI https://itch.io | grep -i server Server: lapis
- rxi 6y agoThe tools are all written in C and use microui[1] for the UI. The games are typically written in LÖVE with the exception of SCANLINE which uses Nim [1] https://github.com/rxi/microui https://github.com/rxi/microui
- felixr 6y ago
- chrisweekly 6y agoI first became aware of Lua in 2007, playing World of Warcraft. Really cool scripting language. Kinda wish it'd taken off the way it might've.
- andrewmcwatters 6y agoPlanimeter's Grid Engine[1] was posted to HN recently, which is entirely built in Lua and the largest pure-Lua game engine![2] [1]: https://www.planimeter.org/grid-sdk/ https://www.planimeter.org/grid-sdk/ [2]: https://github.com/topics/love2d https://github.com/topics/love2d Additionally, adnzzzzZ and I are both from the Facepunch/Knockout community, where a lot of Lua developers have come from due to its popularity in Garry's Mod. It also had a wonderful web dev community. There are a lot of cool developers from that community, like Gran PC who works at itch.io and worked on The Stanley Parable, and TheBerkin who designed rant, among many other highly skilled individuals, though most people at HN are probably more familiar with developers like sebmck who wrote 6to5, which later became Babel, and Gabriele Cirulli who wrote 2048.
- erlend_sh 6y agoThere’s a successor to Lua in the works called Mun: https://mun-lang.org/ https://mun-lang.org/ It is written in Rust and aims to be 100% hot-reloadable.
- andrewmcwatters 6y agoTo be fair, Lua is already "100% hot-reloadable." Module definitions are just tables, so references can be redefined during runtime.
- anonymoushn 6y agoI'm not sure if a statically typed AOT compiled language with no fibers can be a successor to Lua.