lua and love2d via terminal like in tutorial

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
flaschenzug
Prole
Posts: 7
Joined: Tue Dec 20, 2022 8:56 pm

lua and love2d via terminal like in tutorial

Post by flaschenzug »

Hey there,

I just started to learn lua and like to work with it on a mac.
I installed Lua using Brew and can execute the files via terminal.

And now I like to work with Love2d like the guy in this (i think great) tutorial.
https://youtu.be/I549C6SmUnk?t=7020
In the section "Setup and LUD basics" (after 1 hour 57 minutes) he is installing love2d.
I downloaded löve for mac and can start it via the app (to see the balloon that is flying).

But I like to use it with the terminal, like in the video. So I use:

Code: Select all

_G.love = require("love")
When I run the main.lua file via terminal, I get the following error:
lua: main.lua:1: module 'love' not found:
no field package.preload['love']
no file '/usr/local/share/lua/5.4/love.lua'
no file '/usr/local/share/lua/5.4/love/init.lua'
no file '/usr/local/lib/lua/5.4/love.lua'
no file '/usr/local/lib/lua/5.4/love/init.lua'
no file './love.lua'
no file './love/init.lua'
no file '/usr/local/lib/lua/5.4/love.so'
no file '/usr/local/lib/lua/5.4/loadall.so'
no file './love.so'
stack traceback:
[C]: in function 'require'
main.lua:1: in main chunk
[C]: in ?
What am I missing?
How can I tell lua where to find love (or the other way arount)?

I know I could start the app using the description here:
https://love2d.org/wiki/Getting_Started
But I would like to understand, what (and how) he is doing it.

Thank you so much :-)
User avatar
Hugues Ross
Party member
Posts: 110
Joined: Fri Oct 22, 2021 9:18 pm
Location: Quebec
Contact:

Re: lua and love2d via terminal like in tutorial

Post by Hugues Ross »

Typically you shouldn't need to include that line at all, love provides its API already...

I'm not experienced enough with love to say if this has some use-case I'm not aware of or not, but the only reason I could think to do this would be as some kinda weird hack to trick the linter into recognizing it I guess? Normally you can just configure it to do that though, so unless there's another reason that line is entirely superfluous.

EDIT: To answer your second question in more detail
How can I tell lua where to find love (or the other way arount)?
Generally, scriptable applications have the opportunity to set up the environment in which their code runs. A program like love can inject all of its modules into the environment the lua is running in beforehand, so the answer to part one of the question is that love already told lua about itself. As for part 2, it's simple:

Code: Select all

love .
...is what's doing this, '.' represents the current working directory so love runs the main lua script located in there.
User avatar
BrotSagtMist
Party member
Posts: 657
Joined: Fri Aug 06, 2021 10:30 pm

Re: lua and love2d via terminal like in tutorial

Post by BrotSagtMist »

Also youre trying to use Lua but Löve doesnt use Lua. Its Luajit. Its a complete different piece of software that just happens to be modeled after Lua.
Especially the version you have there , 5.4, has a lot incompatibles, you should follow older tutorials if you want to use Löve.
obey
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

Re: lua and love2d via terminal like in tutorial

Post by pgimeno »

This used to work:

viewtopic.php?p=193199#p193199

It doesn't work anymore, though; I guess you need some adjustments to boot.lua as that's what's causing trouble. But you can require love if you preload it as in that post (adjusting the library name as appropriate).

Last time I tried, it only worked with Lua 5.1 or LuaJIT, though - no later versions.
User avatar
flaschenzug
Prole
Posts: 7
Joined: Tue Dec 20, 2022 8:56 pm

Re: lua and love2d via terminal like in tutorial

Post by flaschenzug »

Thank you all for your replies.

I found a way ... its described here: https://love2d.org/wiki/Getting_Started
the solution was simple. Just add the path to love to the ~/.bash_profile (OS X)

open the .bash_profile file

Code: Select all

open -a TextEdit ~/.bash_profile
write this code ...

Code: Select all

# alias to love
alias love="/Applications/love.app/Contents/MacOS/love"
execute in termina:

Code: Select all

love ~/path/to/mygame
OR just: love . (if you are in the right folder)
User avatar
flaschenzug
Prole
Posts: 7
Joined: Tue Dec 20, 2022 8:56 pm

Re: lua and love2d via terminal like in tutorial

Post by flaschenzug »

Especially the version you have there , 5.4, has a lot incompatibles, you should follow older tutorials if you want to use Löve.
Lua 5.4 has incompatibles wit löve ?

How do you develope games in löve, if you don't use lua but luajt?

And have you ever published a game / app on the google playstore / apple app store ?
How does that work with Löve ?
I found this: https://github.com/love2d/love-android

Are there other ways ? And do people have to install löve or ist that included in the packages?
User avatar
GVovkiv
Party member
Posts: 685
Joined: Fri Jan 15, 2021 7:29 am

Re: lua and love2d via terminal like in tutorial

Post by GVovkiv »

Lua 5.4 has incompatibles wit löve ?
Love is interprier on itself. It build on luajit, which on itself compatible with lua 5.1 (so using vanilla lua 5.1 instead of luajit is possible without hassle)
It possible to include love in vanilla lua by some *hacks*, which pgimeno showed in links.
Lua 5.2 and newer included some big changes, that might break something that love relies on, since love was build with luajit/lua5.1 in mind, so hacking together lua 5.2 and newer versions with love might not always works without headaches.
How do you develope games in löve, if you don't use lua but luajt?
by using love
And have you ever published a game / app on the google playstore / apple app store ?
How does that work with Löve ?
By using android studio to build love for android and some manual reading https://github.com/love2d/love-android/ ... -Packaging
(Also not relevant, but i kinda like that dev of love for android used Scootaloo in sandwich as example image for changing icons, lol)
Are there other ways ? And do people have to install löve or ist that included in the packages?
They install love or build from source, if they feel brave enough.
On linux they install via their package managers, maybe via flatpak or appimage.
On windows they use installer.
On mac, i guess, they use something similliar to appimage.
For other os and platforms they summon Kraken from the depths, idk
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

Re: lua and love2d via terminal like in tutorial

Post by pgimeno »

Thanks to slime's help on IRC, here's the updated version of the "inside out" runner for recent Löve (load Löve from the running Lua instead of the other way around):

Code: Select all

#!/usr/bin/env luajit
package.preload.love = package.loadlib('./libliblove.so', 'luaopen_love')
local mainloop = coroutine.wrap(require('boot'))
repeat
  local ret = mainloop()
until ret ~= nil
Again, replace with the appropriate library path and name. Again, 5.1 only, but you can use either PUC Lua or LuaJIT. Don't expect love.event.quit("restart") to work with this method, though; I'm not sure if that can be made to work with this way.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 3 guests