How to print in to terminal console?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
ddabrahim
Party member
Posts: 182
Joined: Mon May 17, 2021 8:05 pm
Contact:

How to print in to terminal console?

Post by ddabrahim »

Hi everyone!

I would like to ask for some help with printing values in to terminal console on macOS.
I was searching the forums and look up the docs but nothing seems to be working and I have no idea why that is.

I have a conf.lua file with the following inside to allow printing to console

Code: Select all

function love.conf(t)
	t.console = true
end
In main.lua I have also included the following to allow printing to console at runtime so I can see values as the game is running

Code: Select all

io.stdout:setvbuf("no")
In the terminal I launch the project with the following command:

Code: Select all

open -a love project_folder
The project opens, but nothing is printed in to the terminal.

Could someone please tell me what am I doing wrong?

Here is a project I have setup and you can try:
terminal_test.zip
(1.1 KiB) Downloaded 81 times
Thank you.
User avatar
BrotSagtMist
Party member
Posts: 607
Joined: Fri Aug 06, 2021 10:30 pm

Re: How to print in to terminal console?

Post by BrotSagtMist »

Can any other programs use print?
I mean this should not be a löve problem seeing as the code for this print should be identical to any print of any other language.

Try running a hello world for luajit for example.
Also you could try io.stderr:write() in case someting is wrong with sdtout.
Or io.write instead print in case something is broken in print() but so far i am aware print is io.write under the hood.
obey
User avatar
keharriso
Citizen
Posts: 92
Joined: Fri Nov 16, 2012 9:34 pm

Re: How to print in to terminal console?

Post by keharriso »

The project works as expected for me (Windows 10, LOVE 11.4). Have you tried using lovec instead of love? Is that even an option on Mac?
LÖVE-Nuklear - a lightweight immediate mode GUI for LÖVE games
User avatar
ddabrahim
Party member
Posts: 182
Joined: Mon May 17, 2021 8:05 pm
Contact:

Re: How to print in to terminal console?

Post by ddabrahim »

No lovec doesn't seems to be available on macOS. Is it part of the standard installation?

The project works in ZeroBrane Studio, it does print to the IDE console. But it does not work if I run it from the terminal console.
io.stderr:write() did not work either.

Thank you for suggestions anyway.
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: How to print in to terminal console?

Post by pgimeno »

Setting c.console = true in the configuration doesn't work for me on Linux. I run 'love <dir>' from a terminal. Doesn't that work for you?

See https://love2d.org/wiki/Getting_Started#Mac_OS_X
User avatar
ddabrahim
Party member
Posts: 182
Joined: Mon May 17, 2021 8:05 pm
Contact:

Re: How to print in to terminal console?

Post by ddabrahim »

No it does not work for me. I am not aware of any run command on macOS but there is open to launch applications

I have tried to run it like this

open -a love project_folder
open -n -a love project_folder
open -n -a /Applications/love.app/Contents/MacOS/love ~/path/to/project_folder
open /Applications/love.app/Contents/MacOS/love ~/path/to/project_folder

None of them print to the console.
open /Applications/love.app/Contents/MacOS/love seems promising because it does open a separate console window just for love, but still could not get it print to this console window.
User avatar
slime
Solid Snayke
Posts: 3131
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: How to print in to terminal console?

Post by slime »

The 'open' command doesn't route stdout to the active command prompt. You can just run the love executable directly, instead of going through a separate command (there's no need to use 'open' at all):

Code: Select all

/Applications/love.app/Contents/MacOS/love ~/path/to/project_folder
User avatar
ddabrahim
Party member
Posts: 182
Joined: Mon May 17, 2021 8:05 pm
Contact:

Re: How to print in to terminal console?

Post by ddabrahim »

For some reason I remembered if I just run /Applications/love.app/Contents/MacOS/love I was getting an error for the directory does not exists. But It is working now. :D

Thanks a lot.
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: How to print in to terminal console?

Post by pgimeno »

I linked the Getting Started page for a reason.
On Mac OS X, a folder or .love file can be dropped onto the love application bundle. On the Mac Terminal (command line), you can use love like this (assuming it's installed to the Applications directory):

Code: Select all

open -n -a love "~/path/to/mygame"
However, the above method will not output printed text to the terminal window. To do that, you will need to execute the love binary inside the application bundle directly:

Code: Select all

/Applications/love.app/Contents/MacOS/love ~/path/to/mygame
Then it goes on to mention how to make a shortcut to make that easier.
User avatar
ddabrahim
Party member
Posts: 182
Joined: Mon May 17, 2021 8:05 pm
Contact:

Re: How to print in to terminal console?

Post by ddabrahim »

pgimeno wrote:I linked the Getting Started page for a reason.
I didn't know you can run Applications like that and I remembered (wrongly) /Applications/love.app/Contents/MacOS/love gives me an error so I was kind of ignoring the fact it does not mention to use open.

No idea what I was remembering not to work, I am getting lots of errors every day :D
But yes it is indeed working as the documentation described it. My bad.

Thank you.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 46 guests