Noob trying to execute a "Hello World" from the Command Line

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
Eccles19
Prole
Posts: 1
Joined: Thu Jan 16, 2014 10:30 pm

Noob trying to execute a "Hello World" from the Command Line

Post by Eccles19 »

So, I haven't been programming for very long but I'm trying to use the command line.

I would like to know how to open a main.lua (it's just a "Hello World") in Löve from the command line.

I'm using Mac OS X (Mavericks). My knowledge of the Terminal doesn't extend beyond some basic commands (cd, ls, mkdir) and a bit of Vim. the Getting started page mentioned something about .bash_profile but I need some help understanding this.

Thank you for your patience.
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Noob trying to execute a "Hello World" from the Command

Post by Jasoco »

Basically it's simple. Kind of.

Basically you're going to launch the "love" binary with the .love file as its first argument. The "love" binary is inside the love.app package. You can find it by right-clicking on the .app and "Show Contents". Then navigate to /Contents/MacOS. The love binary is in that folder.

ALTERNATIVELY: Assuming the love.app is in /Applications/, the path to the love binary below will be /Applications/love.app/Contents/MacOS/love.

Open a Terminal window and do two things. First drag the love binary to the Terminal window. Then drag the .love. The command should appear something like this:

Code: Select all

/Path/to/love.app/Contents/MacOS/love /Path/to/project.love
Press Enter/Return and it will launch. All "print()" calls will also print to this window as a bonus for debugging.

I created a run.command file to handle this for me. Basically you'd create a new plain text file and use this as the contents:

Code: Select all

#!/bin/bash
~/Documents/Projects/LÖVE/Apps/love.app/Contents/MacOS/love "${0%/*}"
Then rename it to run.command, place it in the same directory as your main.lua and make it Executable by using this command:

Code: Select all

chmod +x /path/to/run.command
The strange string above with the $ and {} characters simply means it will pass the current folder (That the .command file is in) as the argument.

Don't worry if you think something might screw something up, these commands are safe. And you couldn't destroy anything without using sudo anyway.

Remember to replace /Path/to/ with the actual path. (Dragging and dropping is the easiest way to put a file path into a Terminal window without typing. Also see ALTERNATIVELY above.)

Now you can just double-click the .command file or assign it to a hotkey with a program or put it in your Dock and launch your project easily complete with debugging console. I set mine to Command+Shift+R.

Also: I'm not sure if the chmod program requires Xcode to be installed or not. If it does, there are probably other ways to make it executable.
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Noob trying to execute a "Hello World" from the Command

Post by micha »

If you don't have a .love-file, but the main.lua, then you can call it directly. Go to the folder that contains the main.lua and run

Code: Select all

love .
Mind the dot.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Noob trying to execute a "Hello World" from the Command

Post by kikito »

I have an alias in my .zshrc file (I think it will work the same in a .bashrc file):

Code: Select all

alias love="/Applications/love.app/Contents/MacOS/love"
Once that line is added to the file, open a new terminal (so it reloads .bashrc/.zshrc) and try executing:

Code: Select all

$ love
If you see the baby inspector, then that means you are set up. Then you can do this:

Code: Select all

$ cd path/to/your/game/folder
$ love .
Notice the dot on the second line.
When I write def I mean function.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 6 guests