Hacker News new | past | comments | ask | show | jobs | submit login

In my case, it was a couple of days. I read the free online version of the Programming in Lua[1] book and was basically set.

Lua feels like a simpler, cleaner Javascript.


You have lexical scope, anonymous and first class functions, and dynamic typing.

The parser is as simple as possible (LL(1), ie top down, without backtracking), and doesn't do any magic like declaration hoisting or semi-column insertion.

The only falsy objects are `false` and `nil`. `==` doesn't do any type conversion.

The addition `+` and concatenation `..` operators are different.

Some infix operators do automatic type conversion ( +, -, *, /, %, ..) between strings and numbers, but that's about it for weak typing. There's no octal to decimal conversion for strings with prepended zeros.

There's only one way to define objects. The `self` parameter is explicit for methods, but there's syntactic sugar to pass it automatically.

Scoping is similar: variables are global by default, which allows precise scoping for closures.


== Where the languages diverge:

You can do some magic with metatables and environments, but once again, the mental model is extremely simple.

The other major differences are coroutines (cooperative threads) and a "generic" `for` loop that allows to build custom idiomatic iterators.

At last, the array indexing starts at 1. This may sound like heresy to devout Dijkstra followers, but it's really not a big deal in practice.


[1]: http://www.lua.org/pil/ by Roberto Ierusalimschy, one of the author of the language.

I think the most compelling thing about Lua (to someone with no Lua experience), is that its appears (from examples, and what people have said) that its good for embedding inside another program (size wise and good FFI).

In a video I saw, by one of the designers of the languages stated that this was the original purpose (engineers using this instead of C, with the low level details done by programming team in C).

Indeed, C(++) interop is easy. The API is also described in the PiL Book linked above.

Furthermore, the VM binary weights 200k. It is extremely portable (it uses the common subset of C89 and C++), and its code is a pleasure to hack.

Just had a quick skim over some of that chapter, and it is very compelling, especially when I see how well its worked for AwesomeWM (my desktop environment of choice) and how many commercial games are using it for user scripting [1].

[1] http://en.wikipedia.org/wiki/Category:Lua-scripted_video_gam...

Wow - thanks for this summary. I hadn't heard a rundown like this before. That sounds great - I might give Lua a go!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact