Live data from Hacker News

Learn Lua in 15 Minutes

tylerneylon.com

41–50 of 99 posts

Re: Learn Lua in 15 Minutes

#41
I learned to love lua when writing basic sysadmin scripts for OpenWRT based systems. I had previously used perl for sysadmin stuff, but perl (even microperl) took too much space on OpenWRT boxes with 4MB flash drives. Lua to the rescue. Now I chafe when I have to go pack to perl.

I do wish someone had handed me this on the first day I realized I needed lua.

Re: Learn Lua in 15 Minutes

#42
post #6

This is awesome. I will take [a single huge list of self-explanatory example snippets (with a few short comments here and there) for 95% of use cases] over [detailed walls-of-text docs pages spread across a hierarchy of topics] any day.

Thanks. My goal was to write the tutorial I wish I had when I started. Your description also matches my own preferred learning style.

Were you inspired by http://www.stavros.io/tutorials/python/, by any chance?

Re: Learn Lua in 15 Minutes

#43
This is very cool, the only way I can see this could be improved upon is by adding unit tests somehow (so that you can catch behavior changes when upgrading to a newer version of lua).

Re: Learn Lua in 15 Minutes

#44
post #16
post #9

Earlier quoted context omitted.

Well, it helps a lot that Lua is by design a very small language :) Python is actually much bigger nowadays -- I would challenge someone to come up with something this simple that doesn't leave out a lot of stuff you will encounter in real code. The extra features ("bloat") do matter. I like the idea of Lua a lot, but when I started programming in it, it unfortunately felt like a less capable Python to me.

Lua and Javascript are quite similar in that way: nice little languages that fall apart really quickly when you try building anything reasonably large or complex. I don't really understand the attraction, except in certain niches like Lua as an embedded scripting engine, when you really need something that can be trivially sandboxed.

> [...] except in certain niches like Lua as an embedded scripting engine, when you really need something that can be trivially sandboxed.

Isn't that exactly the reason JavaScript exists in the first place (i.e.: an embedded scripting engine for browsers) ?

Re: Learn Lua in 15 Minutes

#45
This is a good start, but there's also some deeper ideas in Lua. It has a good implementation of coroutines, for example; if you're familiar with continuations from Scheme, they fit most of the same uses. (They're like generators from Python or fibers from Ruby, but with less edge cases.)

The C interop is also a Big Deal. Lua seems like a cute little language, like a cleaner Javascript, but it's a LOT more useful if you're also proficient in C. Also, Lua will run anywhere you have an ANSI C compiler and a modest amount of space.

Re: Learn Lua in 15 Minutes

#46
post #22

Having a font size of 25.33pt makes the website impossible to read without zooming out 3 steps. I would be happy if people stopped using tiny and huge default font sizes.

You can zoom in/out as much as you'd like, as you already know, so there is no need to force your personal taste on everyone else.

Re: Learn Lua in 15 Minutes

#47
post #6

This is awesome. I will take [a single huge list of self-explanatory example snippets (with a few short comments here and there) for 95% of use cases] over [detailed walls-of-text docs pages spread across a hierarchy of topics] any day.

I'm glad this comment sits at the top of this thread. I do hope that more and more learning resources come to us in this form, which is a very good thing to give you an idea of wether you would like to jump into a language (or maybe even a framework/platform?). OP did a very good job.

That said, Lua is quite the special case, as it does not require much time to get up and running with it. This is one of the reasons why it is the scripting language of Redis by the way (Antirez even wrote Total time require to master it enough? 5 minutes.[1] regarding building scripts for Redis).

[1]:http://oldblog.antirez.com/post/scripting-branch-released.ht...

Re: Learn Lua in 15 Minutes

#48
post #25

This is awesome. On that note, I don't understand all the javascript craze. Lua has been around for quite some time, and it's small, with well-defined semantics, a nice set of features, the interpreter is small and very fast, you can get even faster with LuaJIT, etc. Browsers should have adopted that ages ago.

Maybe when it supports unicode

Unicode is not included because currently they target ANSI C. Pure ANSI C.

Not POSIX.

Plain old C.

Until C11, unicode didn't exist in C. And it will be a long time before C11 is the default. Hell, there's lots of places where C99 is the exotic interloper.

Re: Learn Lua in 15 Minutes

#49
post #33
post #12

Earlier quoted context omitted.

Yeah, I see Lua in many ways as "JavaScript done right". I also found it considerably easier to integrate than something like V8, and it appears to be easier to use for non-programmers. It definitely deserves to be more popular.

Javascript being used by non programmers is 95% of the problems with javascript.. care to explain your problems with js and maybe expand on how lua is done right?

Lua is a much smaller language and overall it is much more consistent and has less corner cases than Javascript since the language had the opportunity to evolve over the years instead of needing to retain backwards compatibility with browsers from 1995. For example:

* Lua has proper lexical scoping instead of the confusing "function scoping" of Javascript (so there is no need to use the IIFEs hack).

* Lua has a Python-style lexicaly scoped self instead of the error prone dynamically scoped "this". No need to use `var taht = this` if you have nested functions.

* The metatable system is much more flexible than the simple JS prototypal inheritance system (you can sort of implement "method missing" instead of being forced to only delegate to a concrete table.

* You can use anything as a Lua table key. In JS all keys are converted to strigns. Lua also supports weak references.

* Coroutines! Its sort of like ES6 generators and is super awesome. Async programming is infinitely more pleasant in Lua than it currently is in JS because you don't need to convert code to continuation passing style.

Post reply on HN