r/lua • u/kayinfire • Nov 01 '25
Does anyone else use lua as their main language for system automation and shell scripting?
it's no secret that Lua is heavily underrated. ironically, i used to be against lua until i understood how nifty it is as a language. i formerly thought that one had to use index or metatable to create objects, only to find out that i could do this
```
function NameOfObject(instanceVariable1, instanceVariable2)
return{
method1 = function(self)
end,
method2 = function(self)
end,
method3 = function(self)
end,
}
end
```
and just like that it overtook the appreciation i had for how objects can be created in other languages.
in a less subjective sense, however, given how ridiculuously fast lua is compared to the bulk of languages that are interpreted, i committed to it for all my scripting needs.
lua has now become my premier choice for automating anything related to my environment: my file system, my window manager, and even my system settings. it also greatly helps that i can automate repetitive and tedious text editing in neovim with lua as well.
i formerly used python for my scripting needs, and in retrospect, it's rather comical to me how poor python is as a scripting language compared to lua; it's a night and day difference. i can always trust lua for a startup time that is as good as instantaneous, whereas such a thing would be a fool's game in python.
granted, python does have all the abstractions one can hope for, but for system tasks, it's just outright overkill. one does not need a gazillian abstractions for system admin or shell scripting needs
anyways, i've rambled long enough. is there anyone else that uses lua for shell scripting needs and system automation, as opposed to roblox, C programming, game dev, and other low level tasks?
22
u/Quixventure Nov 01 '25
I use Lua everyday to define risk controls for financial services. Lua is amazing, simple and freakishly fast! A few years ago I built an entire margin lending calculator Lua and it’s been rock solid ever since. I also maintain python and C#…. But Lua is my favourite.
13
u/rz2000 Nov 01 '25
Among macOS users willing to customize the OS's behavior explicitly, Hammerspoon is pretty popular. Lua is the language for any user-defined actions.
8
u/RiverBard Nov 01 '25 edited Nov 01 '25
I've been teaching and using Python for a few years now but just started learning Lua. It has absolutely taken over for writing shell and system scripts and I'm excited to learn more and use it more.
os.execute()is my new best friend.I didn't know you could define a class as you posted, I'll have to play around with that!
3
u/[deleted] Nov 01 '25 edited Nov 01 '25
I'm finishing a moon course. I want to dedicate myself to doing more projects with her. I wanted to use it as a replacement for shell script. I also felt a difference in relation to Python and Javascript. I found it much simpler. And the performance compared to shell scripting is absurd.
3
u/ElhamAryanpur Nov 01 '25
Yes! Although we're using a runtime we built called Astra since we needed functionalities in a single place and easy to deploy
2
u/[deleted] Nov 01 '25
I’ve wanted to seriously learn Lua to do this sort of thing for a while … anyone have a book or series recommendation? I’m no newcomer to programming, I’m professional with python and familiar with C/rust, and I’ve used basic lua to configure neovim.
2
u/vitelaSensei Nov 01 '25
The downside of this approach is that if you have 10 instances of the object you’ll have 30 functions in memory instead of just 3 if they shared a metatable
2
u/TheOmegaCarrot Nov 01 '25
My go-to scripting language is Bash
If Bash is too unwieldy, or if the script grows too much, then I tend to reach for Lua (or Fennel) to implement either the whole script, or to just implement a part of it
2
u/xoner2 Nov 01 '25
Anything more than a simple sequence of commands should be done in a proper scripting language. Shell/batch is just too painful and ugly once you need conditionals, loops, functions.
A decade or so ago I used PHP for shell scripts. Startup is very fast too (unnoticeable at least compared to batch file) and huge standard library. I then learned Python but never considered it for replacing shell scripts since startup is indeed slow.
Now I've transitioned to Lua and built up enough of a personal library I don't miss the PHP stdlib any more.
My incremental backup system is in Lua. Also build system for C/C++. Inkjet printers get clogged nozzles when unused so I have scheduled task in Lua to periodically print. Etc...
1
u/GrainTamale Nov 01 '25
Lots of hate on Python's speed in this sub, and I just want to share my dose of reality that just yesterday
pytestran 130 tests in 0.4 seconds. Not a record, but fast enough for my needs.1
u/ynotvim Nov 01 '25
I'm curious: what about your alternative method for creating objects do you prefer? Or to put this the other way around, what don't you like about using metatables? (To be clear, I'm not criticizing or disagreeing even. I'm just curious.)
I tend to reach for Python or Go once a task outgrows scripting (in length or complexity). I love Lua as a language, but I do miss the abstractions of Python's subprocess or Go's ox/exec.
tl;dr - I love writing (and reading) Lua, but I miss the batteries from other languages. So I tend to use it mostly when it's embedded in something (e.g., Neovim or Wezterm).
1
u/antara33 Nov 02 '25
I have a probably dumb question, but how do you setup a lua interpreter?
I used lua multiple times, but always embeded into another app as a scripting/extension language, never used it as its own thing.
Is there a lua interpreter that you can download and use like with python?
1
u/SortMyself Nov 04 '25
Great post, thank you for it. Could you elaborate on how you have configured it as your main language for system automation?
2
u/disperso Nov 01 '25
For people who use it for shell-like programming: do you use any libraries? I find very frustrating that the core Lua experience is able to open a file or fork a process, but not list the content of a directory. For simple, typical UNIX things, I find it misses just a bit more of file system functionality. Of course, there are libraries. But it would be ideal (for me) if that came built-in.
2
u/didntplaymysummercar Nov 03 '25
As much as I like Lua as a language and for using in my C or C++ games/programs if I need scripting, I still use Python for standalone scripting.
The built-in libraries, forward compatibility and string handling are just too much of an edge over Lua. Plus it can run programs inside zip files and is often pre-installed on Linux.
At last job I wrote tons of scripts and tools using just built-in libraries, targeting 3.8 (since that's what Ubuntu 20.04 LTS has), too.
1
u/PressburgerSVK Nov 01 '25
I dropped lua for inconsistent ecosystem. Also the performance LuaJit was missing on more recent language versions. Lua may had some chance to become data science tool. Just recall the torch, but that opportunity has been lost.
1
u/deepdropper Jan 01 '26
not really, I tried but quickly realized the standard library is just to barebone and I mostly needed additional libraries where for python this wasnt needed. I like Lua alot but mostly when I need to script something on my dev machine, but not when it needs to be distributed.
0
u/SkyyySi Nov 01 '25 edited Nov 01 '25
While you certainly can do this, I don't really see why you would use Lua for systems automation instead of a programming language designed for it, like PowerShell (which is open-source and cross-platform btw) or Bash. Things like file and text processing or command orchestration are much easier in those compared to Lua, partially because they're designed for that purpose and also partially because Lua needs 3rd-party libraries to even be able to do some of that at all (
os.execute()just spawns your system shell and doing any sort of data passing is a nightmare).-2
u/AutoModerator Nov 01 '25
Hi! It looks like you're posting about Roblox. Here at /r/Lua we get a lot of questions that would be answered better at /r/RobloxGameDev, scriptinghelpers.org, or the Roblox Developer Forum so it might be better to start there. However, we still encourage you to post here if your question is related to a Roblox project but the question is about the Lua language specifically, including but not limited to: syntax, language idioms, best practices, particular language features such as coroutines and metatables, Lua libraries and ecosystem, etc. Bear in mind that Roblox implements its own API (application programming interface) and most of the functions you'll use when developing a Roblox script will exist within Roblox but not within the broader Lua ecosystem.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.