r/lua • • Jan 01 '26

What are some of your problems with lua?

Love2d and other libraries are welcome but just say what library your talking about

23 Upvotes

64 comments sorted by

View all comments

Show parent comment

1

u/no_brains101 Jan 02 '26 edited Jan 02 '26

You can use newproxy in Lua 5.1 and LuaJIT

Yeah I know and I've had to. Still don't really want to make a proxy object for it XD

They should probably be 2 separate types, however the tables should still have the array shorthand lol because being able to mix table and array syntax like that is actually kinda nice, just not when you want the thing to actually be an array lol

Its like python's keyword args when you take a table as argument lol and that is a nice feature of lua tables. Its just not as nice when you actually want a list XD

1

u/didntplaymysummercar Jan 02 '26

They could keep it and add [] to mean arrays, just like Python. Implementation already account for metatables and indexing non-tables, so it's just an extra branch in those places.

Its like python's keyword args

It's not a keyword, the name is just a convention, only * or ** matters, and yes, I know how tables can achieve same args + keyword args in Lua and (rarely) use it.

1

u/no_brains101 Jan 02 '26

They could keep it and add [] to mean arrays, just like Python

Can they? [[this is a string]] which obviously has some conflict with an array of arrays

1

u/didntplaymysummercar Jan 02 '26

Sure, just require spaces there, there's already some precedent in many programming languages, even in Lua -- is a comment and - - is a double negation.

1

u/no_brains101 Jan 02 '26 edited Jan 02 '26

Do we REALLY need more "needs a space" tho?

Like[ [[thisisindexing]] ]

IDK.

I would like an array type, but all the syntaxes you could use for it feel so meh and theres a lot of code out there already...

Also it wouldn't make it into luajit...

I love and hate luajit. Why must it be frozen... But also the fact that it is frozen also makes it more stable for things to be built on it... and its so fast... grrrrr.....

Personally, if I could redo lua, I would give it arrays, I would remove [[these strings]] but keep [=[these ones]=] and I would make arrays use [].

But I can't so, meh. I mean, I could, but noone would use it and I probably wouldn't manage to make it quite as fast as luaJIT lol (I could definitely make it as fast as 5.4 tho)

Slightly annoyed fennel didnt take the opportunity to fix list/array iteration.... They have an actual dynamic array type (kinda, or at least a reader macro sorta thing for them) they just needed to go a liiiiiiittle farther with it and make it compile to a proxy table with a new __ipairs and __pairs and stuff XD

1

u/didntplaymysummercar Jan 02 '26

IMO requiring spaces for nested arrays wouldn't be that bad and it'd break no code. Plus Lua minor versions sometimes do break code, so removing [[ would also work and be within that.

Same for adding != - Lua already added a few binary data operators and a floor division operator, and ~= looks confusing, like Bash's or Perl's regex match, is harder to type on keyboards with dead key on tilde, etc. Lua also already allows semicolons instead of commas in table constructor (I never seen this used, everyone uses commas) so having alternative 100x more common inequality operator spelling would be nice. Python used two inequality operators in the past too (it had <> from Pascal in addition to !=) but since version 3 kept only != other than if you import a __future__ Easter egg that bans != and requires <>

As for LuaJIT - the 5.2 environments and 5.3 numbers are probably such big changes it'd be hard to adapt, and break a lot of code out there that uses 5.1 version of the language. I first touched 5.2 (latest that just came out when I first picked up Lua) but went to 5.1 then, so if I want I have LuaJIT option. I like that the language is frozen and will never break any code for me (just like C won't and C++ will very rarely do). Lua 5.1 is good enough, I prefer how environments work in 5.1, I don't care for goto or __gc on tables, I'm familiar with the codebase and made some tiny improvements, etc.

That minor versions are potential breaks (sometimes very gratuitous ones, like renames of functions) is a big downside to Lua ecosystem. In Python for years at work I targeted Ubuntu 20.04 which had Python 3.8 and never had problems running the same code on newer versions, but with Lua it'd require a bit (not much but not zero) effort.

1

u/no_brains101 Jan 02 '26 edited Jan 02 '26

Oh, another change I would make

local a, b, c = 1, 2, 3

returns 1, 2, 3

Assignment as expression. This should probably also apply for __newindex Although that interaction is probably part of why we don't have this.

This probably also screws with fennel just, like, really hard if they wanted to add that feature, but maybe Im just uncreative and/or forgetting how fennel assignment works.

Unfortunately if else end as expression doesn't work as nicely in lua.... But thats OK cause or and and cover that

1

u/didntplaymysummercar Jan 02 '26

Real ternary would be nice too, since abusing a and b or c has one edge case if b is falsy. As for assignments being expressions - it's not that big of a deal in Lua. It's a feature in C and C++ but rarely used, many don't even realize it works like that. OTOH Python's new := operator can be useful and it's nice it's a new distinct operator to make it clear.

1

u/no_brains101 Jan 02 '26 edited Jan 02 '26

Well, I'm personally a fan of assignment as expression, but I would be ok with it being a separate operator, although I really don't see the need for it to be one, it isn't ambiguous. You couldn't use it at all in that context prior anyway, and it's ok to return into nothing

The only ambiguity is raw for loops, and that's probably more consistent with assignment as expression anyway, not less lol