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

General discussion about LÖVE, Lua, game development, puns, and unicorns.
magus_vageta_fusion
Prole
Posts: 6
Joined: Fri Mar 03, 2023 12:13 am

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

Post 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.
Last edited by magus_vageta_fusion on Fri Mar 03, 2023 2:52 pm, edited 2 times in total.
User avatar
BrotSagtMist
Party member
Posts: 657
Joined: Fri Aug 06, 2021 10:30 pm

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

Post by BrotSagtMist »

Please dont.
Why the heck do you use sudo in there?
This is super dangerous and totally ill advised.
obey
magus_vageta_fusion
Prole
Posts: 6
Joined: Fri Mar 03, 2023 12:13 am

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

Post 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?
User avatar
knorke
Party member
Posts: 274
Joined: Wed Jul 14, 2010 7:06 pm
Contact:

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

Post 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)
User avatar
BrotSagtMist
Party member
Posts: 657
Joined: Fri Aug 06, 2021 10:30 pm

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

Post 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"
obey
Andlac028
Party member
Posts: 174
Joined: Fri Dec 14, 2018 2:27 pm
Location: Slovakia

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

Post 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.
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

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

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
magus_vageta_fusion
Prole
Posts: 6
Joined: Fri Mar 03, 2023 12:13 am

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

Post 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 ^^ .
User avatar
BrotSagtMist
Party member
Posts: 657
Joined: Fri Aug 06, 2021 10:30 pm

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

Post 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?
obey
magus_vageta_fusion
Prole
Posts: 6
Joined: Fri Mar 03, 2023 12:13 am

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

Post 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.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 1 guest