r/lua • u/Bright-Historian-216 • Mar 27 '25
lua feels high and low level at the same time
thinking about it for the past hour. no pointers to screw you up, yet nearly zero standard library as well. every time i need a very basic function (like checking if a table contains a value, iirc even C++ has that in the standard library!) i try and look it up, only to realise that i am on my own. it's nothing difficult most of the time, annoying at worst. yet... it feels like zen. the purity i've felt while writing stuff in 6502 assembly in an online emulator, except in lua... everything actually works. it all makes sense. every piece of code makes sense. there are frustrating points as well, like not having the continue keyword (what a shame!)... but it's a small price for such soulful feeling.
oh GODDAMMIT i have to write deepcopy again
3
u/thewrench56 Mar 28 '25
I haven't really seen the point of pure Lua ever. I think it's first and main goal was to provide a scripting language with arguably the best interop with C. They succeeded and made this amazing language. For me, batteries are C function calls from Lua. So I don't really mind.
2
u/esuvii Mar 28 '25 edited Mar 28 '25
Lua does not have
continuebut you can emulate it using agoto, available in Lua 5.2 onwards.For example:
I know a lot of people despise using goto/jump statements (even though they are everywhere in assembly), but this is an option. Personally I think using them to
continueis a very reasonable way to use them, versus the more esoteric use cases of jumping all over a codebase. If you look at compiled C++ code you will see that all loops and continues are essentially just conditions and jump instructions anyways.My example of course is harder to follow than if it was simply
if i % 2 ~= 0without thegotobut it was more for demonstration purposes. If you can think of a time that acontinuewould be useful then this is a way to do it.22
u/AtoneBC Mar 27 '25
I'd say more "batteries not included" than low level. Lua sure doesn't feel low level when I'm making tables of tables of arbitrary data including more tables with no regard for how it's all represented in memory. But I get what you mean. The minimalism is a blessing and a curse, but it does give the language a certain zen quality. And I like that the feeling kind of extends to projects like Löve.
6
u/appgurueu Mar 27 '25
You have to write (deep)copies again in most languages, because it is far from obvious how a deepcopy should work in general - which parts of objects are to be copied and which ones are to be left alone.
5
u/[deleted] Mar 28 '25
https://github.com/lua-stdlib/lua-stdlib
4
u/gamlettte Mar 27 '25
Zen word here has a lot to it. Lua, due to its simplicity, does not make me think about how it works at any moment during writing the code. It just... writes itself. You need a function, you find a nice place for it, you write it with one breathe, you use it, it works. 90% of the time, that is my workflow. I cannot imagine going the same way with C, for example.
3
u/[deleted] Mar 28 '25
If you want a standard library in Lua, use Penlight, it's the best:
https://stevedonovan.github.io/Penlight/api/index.html
for deepcopy, it offers pl.tablex.deepcopy
for checking if a list contains a value, use pl.List.contains
2
u/could_b Mar 27 '25
Lua is light weight, batteries not included, not to be compared to Python,etc. However a 'standard library ', would make a massive difference. Luarocks and various stuff found in the net is ok. They miss assurance, multiple versions of stuff takes ages to find what works and is understandable.
1
u/burij Mar 27 '25
The concept is to put everything you need often in your own reusable module(s). And it works pretty well IMHO. Bright sight: you can have your own syntax. Love it.
1
u/weregod Apr 02 '25
Penlight library has a lots of useful utility functions including deepcopy. For filesystem interaction Lua File System (lfs) is my goto tool for high level stuff like is file X exists. If you want low level API there is luaposix.
There are some others batteries included libraries but they usualy do weird stuff like poluting global variables.
Other than that you mostly can write C library bindings or write your own code.
1
u/Difficult-Value-3145 Mar 28 '25
Ya low level coding in assembly for instance is like jmp 16 20 add 20 0 it's rather non speech like not the way huma s write while Lua is more high level ya can read a function almost like a sentence sometimes it's more high level bear bones light which is what I love about it include what ya need nothing further it can be a pain sometimes where python the function ya need is there but Lua ya may have to write it yourself or may just need to find it but I like the bare bones simplicity's
0
u/[deleted] Mar 27 '25
[deleted] — view deleted comment