r/lua • • 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!

44 Upvotes

10 comments sorted by

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) in true, in sleep you could use POSIX sleep functions if you use it, right, no need for busy loop, plus could iterate args normally with ipairs or something, instead of for loop, and stuff like if type(tonumber(arg[i])) == "number" could be just if tonumber(arg[i]) since nil is 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.

1

u/ItsJxJo_ 3d ago

thank you! right now everything is a mess especially the code XD

2

u/didntplaymysummercar 3d ago

You can use auto formatter or if you don't want to (I also don't use one for Haskell and C in VSC for example, but do for Python in VSC and C++ in VS, and lately consider using one for Lua in VSC but I'm unsure) or at least turn on whitespace rendering and trailing whitespace stripping in your code editor to spot this kind of stuff quickly.

1

u/ItsJxJo_ 2d ago

tbh i feel like using the for loop through the arguments is much easier imo, i could try different looping methods but this one will do for now

about the readme, i still need to polish up some things in it, as well as the install and build instructions

2

u/iEliteTester 3d ago

a very good idea for a learning project, keep at it

1

u/ItsJxJo_ 2d ago

thank you!!!

13

u/weregod 3d ago edited 3d ago

Your pwd is wrong. Try

PWD=/bad_dir  pwd

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.