r/lua • u/ItsJxJo_ • 3d ago
GNU Coreutils but re-implemented in pure Lua
A little while back i came up with the idea of rewriting gnu coreutils in a different language since i've seen it being rewritten in rust for newer versions of ubuntu and the fact that it's coming to windows (uutils). It uses luaposix to access the C posix functions in lua from these commands, some commands are not yet finished and others still need some tweaking to do. This isn't a direct replacement to GNU coreutils or anything like that but rather a hobby project i made simply for fun :3
https://github.com/JxJo1/lua-coreutils
Everything is a bit messy atm, i have very limited time to update the repo due to school catching up and other personal stuff. Feedback is much appreciated!
4
u/didntplaymysummercar 3d ago
Cool learning project for Lua, coreutils and POSIX.
I noticed some files contain trailing spaces and wrong/bad formatting.
Also some code is strange, like no need to
os.exit(0)intrue, insleepyou could use POSIX sleep functions if you use it, right, no need for busy loop, plus could iterate args normally withipairsor something, instead of for loop, and stuff likeif type(tonumber(arg[i])) == "number"could be justif tonumber(arg[i])sincenilis the only falsy thing.I didn't look further.
Lowercase i in readme is also a bit of an eyesore, and no need to say you won't package it or port to Windows, if it's just a learning project.
2
u/iEliteTester 3d ago
a very good idea for a learning project, keep at it
13
u/weregod 3d ago edited 3d ago
Your pwd is wrong. Try
with GNU pwd. You can use lfs.currentdir() instead of environment variables.
Your sleep is very inefficient.
Why are you using debug to get script name instead of arg[0]?
You require version with relative path ("src.version"). This will not work if you run script outside of your project directory.
You need a to require PROJECT_NAME.version and install it to LUA_PATH or better put version information in every script in install time to not open extra files on every run.
6
u/nadmaximus 3d ago
The idea is cool and an excellent exercise.
You might enjoy looking at something like Picotron - coreutils in lua in Picotron would be...pretty cool.
1
u/Ok-Captain-6460 1d ago
Your project will be good for shell script replacements.
1
u/SleepyGuyy 1d ago
This sounds awesome. I wish I had the drive to do something like this. Reimplement a library in like... Lua or Ruby or some other fun language.
I don't know C well enough to parse what the library does specifically though.