News for hackers. Stuff that matters.
Re:Why I chose Lua for this blog by behnamoh on Thursday October 02, 2025 @03:01PM (#45453912)
I don't know man, every time I tried to learn Lua (to write nvim plugins and HammerSpoon spoons) I disliked the ergonomics of the language. I don't understand why people say it's an easy language—

    easy ≠ simple
Re:Why I chose Lua for this blog by vardump on Thursday October 02, 2025 @03:08PM (#45453997)
Perhaps people's tastes vary? I find Lua an easy to use language. Easy to embed into C/C++ projects for scripting purposes. Also great when you can only spare 100 kB or so for an interpreter. (Arguably that was more important in the past.)
Re:Why I chose Lua for this blog by fullstop on Thursday October 02, 2025 @03:24PM (#45454217)
For me it is a much easier language than, say, Erlang.
Re:Why I chose Lua for this blog by dev_l1x_be on Thursday October 02, 2025 @04:50PM (#45455389)
Erlang has multiple higher level barrier of entries than other languages. For starting, its syntax.
Re:Why I chose Lua for this blog by behnamoh on Thursday October 02, 2025 @06:02PM (#45456138)
but Erlang isn't a scripting language, it's a full-blown language with a rich ecosystem and framework (BEAM).
Re:Why I chose Lua for this blog by fullstop on Thursday October 02, 2025 @06:08PM (#45456203)
Lua is also a full blown language, with an ecosystem as well.

Perhaps the road block that you've run into is because you've been treating it as just a scripting language.

Re:Why I chose Lua for this blog by SoftTalker on Friday October 03, 2025 @12:14AM (#45458907)
Again, tastes. I found Erlang to be one of the easiest languages I ever used. I just immediately "got" it. Unfortunately I've had very few professional opportunities to use it.
Re:Why I chose Lua for this blog by cheriot on Thursday October 02, 2025 @04:07PM (#45454865)
Agree, I find it a PITA. I think the good reviews are in contrast to C++ and vimscript. Fine for a small embedded script, but I hope WASM or some better language ecosystem starts to fill this niche.
Re:Why I chose Lua for this blog by pmarreck on Thursday October 02, 2025 @03:36PM (#45454417)
There are languages that compile to Lua. Have you investigated those? For example, you can use a TypeScript syntax and pick up free typechecking along the way: https://typescripttolua.github.io/

There's also the venerable MoonScript: https://moonscript.org/

And YueScript, a personal fave: https://yuescript.org/doc/

A whole list: https://github.com/hengestone/lua-languages

Re:Why I chose Lua for this blog by gorjusborg on Thursday October 02, 2025 @03:55PM (#45454696)
Don't forget Fennel, if you are a Lisp lover!
Re:Why I chose Lua for this blog by fullstop on Thursday October 02, 2025 @03:26PM (#45454248)
I would suggest using it to add scripting functionality to your own C or C++ project. That's when it really clicked for me.

When you're doing stuff in nvim or HammerSpoon, you're dealing with someone else's interface and the decisions that they've made.

Re:Why I chose Lua for this blog by vyskocilm on Thursday October 02, 2025 @03:37PM (#45454431)
It really depends. I learned Lua in order to contribute to kulala plugin for neovim and found the language nice and easy to learn.

Of course it has its warts, but given the topic, almost everything is better than a vimscript imho.

Re:Why I chose Lua for this blog by electroglyph on Thursday October 02, 2025 @04:21PM (#45455054)
it's easy, but the 1 indexes and global by default suck
Re:Why I chose Lua for this blog by WolfeReader on Thursday October 02, 2025 @04:26PM (#45455101)
The 1 indexes are only a difference from what you're used to. Lua was made by mathematicians, who of course wanted to address the first element as 1, the second element as 2, etc.

0-indexing makes sense in the context of C where the index operator is syntactic sugar for pointer arithmetic. In higher-level languages like C# and Python and others, it's pretty much just a leftover habit from C devs that we all got used to.

Global by default is a perpetual issue, agreed.

Re:Why I chose Lua for this blog by DavidVoid on Thursday October 02, 2025 @05:31PM (#45455844)
And a lot of the time it makes the syntax more compact than it would be with 0-indexing.

  for i=1,#arr do
    foo(arr[i])
  end
I don't feel that strongly for or against either way of indexing though, they both have their pros and cons.
Re:Why I chose Lua for this blog by kqr on Friday October 03, 2025 @12:06AM (#45458856)
Perl is usually used with the first element being zero and the same loop would be

    for (0..$#arr) {
        foo(arr[$_])
    }
Whatever you're feeling is not in starting at one.
Re:Why I chose Lua for this blog by gautamcgoel on Friday October 03, 2025 @12:43AM (#45459065)
You are correct that 1-based indexing is the norm among mathematicians, but none of the creators of Lua is a mathematician, AFAIK. You can read about the early history of Lua here:

https://www.lua.org/history.html

Re:Why I chose Lua for this blog by themafia on Friday October 03, 2025 @04:11AM (#45460340)
> The 1 indexes are only a difference from what you're used to

The left handed scissors are only a difference from what you're used to.

> Lua was made by mathematicians

The default value is nil and using nil as an index on a table returns nil. Yet nil + number is not valid and results in a runtime error.

> it's pretty much just a leftover habit from C devs

It's reflective of the fact that these languages are either intended to work with C APIs or are implemented in C itself. This makes writing FFI and extensions _far_ easier than it would be otherwise.

Re:Why I chose Lua for this blog by badosu on Thursday October 02, 2025 @09:49PM (#45457926)
Lua is the scripting language of [Recoil]. I've been writing some fairly complex game code on it for a few years now, I lost a lot of prejudice over time on 1-indexing.

In fact, at least for this application I've come to enjoy its practicality!

Recoil: https://beyond-all-reason.github.io/RecoilEngine

Re:Why I chose Lua for this blog by pansa2 on Thursday October 02, 2025 @09:55PM (#45457979)
Lua 5.5 will change the way global variables work: AFAICT you’ll be able to opt out of global-by-default
Re:Why I chose Lua for this blog by Rohansi on Thursday October 02, 2025 @11:41PM (#45458717)
Too bad the Lua ecosystem is split between 5.4 and 5.1 due to LuaJIT.
Re:Why I chose Lua for this blog by soapdog on Friday October 03, 2025 @07:00AM (#45461438)
I wrote about this in:

https://andregarzia.com/2021/01/lua-a-misunderstood-language...

I like 1 based indexes and the globals don't hurt me on my projects. It is like JS, it has its own bits that are different than other languages, once you learn them you see that it is mostly fine.

Re:Why I chose Lua for this blog by NuclearPM on Thursday October 02, 2025 @07:54PM (#45457032)
I absolutely love Lua. It’s like scheme without the ((())((((()(((())))( noise.
Re:Why I chose Lua for this blog by bowsamic on Thursday October 02, 2025 @11:12PM (#45458541)
I’ve never understood what people like about it
Re:Why I chose Lua for this blog by scuff3d on Friday October 03, 2025 @12:47AM (#45459079)
The thing that always sticks out to me with Lua is the and/or operators. It's such a minor thing but the way they are used drives me absolutely nuts.
Re:Why I chose Lua for this blog by soapdog on Friday October 03, 2025 @06:58AM (#45461422)
It all depends on what you been exposed to in the past, right? I find Lua simple because it is a minimalist language in which there are very few things to learn. You can buy "Programming in Lua" for the version you want to use and with a single book you learn about basically all of the language and its internals. That is not the same with some other languages.
Re:Why I chose Lua for this blog by pansa2 on Friday October 03, 2025 @08:20AM (#45462104)
>> I don't understand why people say it's an easy language

> I find Lua simple

The comment you've replied to is correct: "easy ≠ simple". Lua is indeed simple, but it chooses simplicity over ease-of-use. For example, even printing the contents of a table requires explicit logic.

OTOH Python, for example, prioritises ease-of-use: `l = [1, 2, 3]; print(l)` does what you'd expect. But Python only achieves this ease at the expense of simplicity: not only does the implementation of `print` need to be more complex, its output can be complex and unpredictable as well - for example, in the case where `l` refers to itself.