Page 1 of 2

(Linux) Making a shell script to launch main.lua will gain you access to the print() function.

Posted: Fri Mar 03, 2023 1:01 am
by magus_vageta_fusion
I wanted to make a .sh launcher for main.lua on Linux Mint. I worked out the script, then learned that print functions can be seen in the terminal window. I figured that this would be useful to share, since I had happened to catch on to it myself.

The bash script is below. It will open love, pointing it to the path of the .sh file. This means it must be with "main.lua". Just create a launcher that launches this script with the terminal window enabled. This script can have any name.

Code: Select all

#!/bin/bash

love "$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
sleep 3
This gets me thinking that there would be a command to get lua files to open with love directly by opening them with a custom command. I don't know enough about bash scripting to figure out how this would be done, if it is possible.
EDIT: script corrections.

Re: (Linux) Making a shell script to launch main.lua will gain you access to the print() function.

Posted: Fri Mar 03, 2023 4:01 am
by BrotSagtMist
Please dont.
Why the heck do you use sudo in there?
This is super dangerous and totally ill advised.

Re: (Linux) Making a shell script to launch main.lua will gain you access to the print() function.

Posted: Fri Mar 03, 2023 6:41 am
by magus_vageta_fusion
then what's the proper way to make the bash script file? It works if you know and trust the OS and programs you are running, and I am open to better alternatives for the script... or perhaps your suggesting that the shell script file is the problem?

Re: (Linux) Making a shell script to launch main.lua will gain you access to the print() function.

Posted: Fri Mar 03, 2023 6:48 am
by knorke
I am unsure if I understand what the script is meant to do.
Do you want to see output of print() in terminal?
For me that shows when I just do
love helloworld
(helloworld being the folder of a love-project)

Re: (Linux) Making a shell script to launch main.lua will gain you access to the print() function.

Posted: Fri Mar 03, 2023 7:01 am
by BrotSagtMist
It is absolute unclear to what this is supposed to perform.
The thing here is purely that you give instructions to use sudo for something that clearly does not need sudo.
Thats simply a dangerous ill advise and on strict linux forums such post would likely get delete by a mod instantly.
On a coding forum it needs at least a warning "dont do this"

Re: (Linux) Making a shell script to launch main.lua will gain you access to the print() function.

Posted: Fri Mar 03, 2023 7:04 am
by Andlac028
If you have problem with outout not appearing instantly, but only after the program exited, disable outout buffering in the beginning of your conf.lua or main.lua:

Code: Select all

io.stdout:setvbuf("no")
I just launch the love from code editor using build system executing love . (or love /path/to/folder) and output is being printed in the output panel.

Re: (Linux) Making a shell script to launch main.lua will gain you access to the print() function.

Posted: Fri Mar 03, 2023 8:48 am
by zorg
I mean, that's the point; print prints stuff to the console/terminal. Not sure why that's suprising.
On the other hand, if you want a script to run löve with a project, you do it similarly to what you did, but probably without sudo in there.

And yes, on windows, i also have batch files that run my projects, that's not suprising either.

Re: (Linux) Making a shell script to launch main.lua will gain you access to the print() function.

Posted: Fri Mar 03, 2023 2:50 pm
by magus_vageta_fusion
The reason i thought you needed sudo is because just calling love doesnt work. it says "unknown sequence number while processing queue". My guess is that the terminal closes before love has a chance to stop it. This is because I removed sudo, then added "sleep 30" to have time to copy the error text, but then it started working. Even after 30 seconds, the terminal stays open. This is probably a more proper way to do it. I'll edit the first post accordingly. Now if only I could launch lua files with love, and with a custom command, instead of a launch script. That'd be cool ^^ .

Re: (Linux) Making a shell script to launch main.lua will gain you access to the print() function.

Posted: Fri Mar 03, 2023 3:54 pm
by BrotSagtMist
Again, i still have no idea what you are trying to perform here. WHAT is this thing supposed to do?
My guess is youre inventing a problem that doesnt even exist and that is too off track for me to get.
Like explain step by step, what are you clicking and what do you want it to perform?

Re: (Linux) Making a shell script to launch main.lua will gain you access to the print() function.

Posted: Fri Mar 03, 2023 4:18 pm
by magus_vageta_fusion
I was just showing how to make a project launcher using a bash script. After being set up, it is the easiest way to launch a unpackaged love project. The script was then corrected with the direction of you helpful folks.

However, the script i posted is only good for a bash script file. In Linux Mint, when you right click on "main.lua", you can go to "open with" > "open with other application..." > "Use a custom command". There is probably a command that can directly open a lua file with love. Love wants the directory, not the lua file. If i could filter that out somehow, it would enable me to skip the launch script all together, at least for launching the project. (The terminal may not be visible if this was pulled off.) It is just a thing of convenience though. I don't mind if this cannot be done.