Lua cannot load Love modules

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
dcjdcjdcj
Prole
Posts: 2
Joined: Sun Oct 04, 2020 11:16 pm

Lua cannot load Love modules

Post by dcjdcjdcj »

I'm trying to learn Love, and I am attempting to use the interactive REPL that is outlined here: https://gitlab.com/alexjgriffith/min-lo ... ree/master

When I try to run `love .` in an inferior REPL in emacs, nothing happens. As best I can tell, this is because Lua cannot import the `love.event` module:

Code: Select all

❯ lua
Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> require("love.event")
stdin:1: module 'love.event' not found:
	no field package.preload['love.event']
	no file '/usr/local/share/lua/5.3/love/event.lua'
	no file '/usr/local/share/lua/5.3/love/event/init.lua'
	no file '/usr/local/lib/lua/5.3/love/event.lua'
	no file '/usr/local/lib/lua/5.3/love/event/init.lua'
	no file '/usr/share/lua/5.3/love/event.lua'
	no file '/usr/share/lua/5.3/love/event/init.lua'
	no file './love/event.lua'
	no file './love/event/init.lua'
	etc...
stack traceback:
	[C]: in function 'require'
	stdin:1: in main chunk
	[C]: ?
I am not very experienced with Lua, so I don't know if I need to set some env var that will point to the right libraries or what. I am running into this on Ubuntu 18.04; I've tried with both Lua 5.3 and Lua 5.1.

If I run `love .` from the root of my game directory, the game runs as expected. I would like to interactively develop, however, so I would... love... to make Lua/Fennel able to load love as a module. Any help would be much appreciated.
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Lua cannot load Love modules

Post by zorg »

Just as a side-observation, it's interesting how a Lua 5.1.5 interpreter tries to search for deps in lua 5.3 folders...
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.
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Lua cannot load Love modules

Post by ivan »

Not sure what you're trying to do here.
if I need to set some env var that will point to the right libraries or what.
The "require" function searches from a list/string of specific paths defined in package.path.
You can add additional paths to package.path, but it's hacky and you shouldn't do it unless you are 100% sure:

Code: Select all

package.path = package.path .. ";../?.lua"
Alternatively you could use dofile(path)
User avatar
pgimeno
Party member
Posts: 3550
Joined: Sun Oct 18, 2015 2:58 pm

Re: Lua cannot load Love modules

Post by pgimeno »

dcjdcjdcj wrote: Sun Oct 04, 2020 11:23 pm When I try to run `love .` in an inferior REPL in emacs, nothing happens. As best I can tell, this is because Lua cannot import the `love.event` module:

Code: Select all

> lua
You don't run Lua, you run Löve, which comes with its own embedded LuaJIT. When you run Löve, it is able to find all of its modules, and pre-requires them (or the ones configured in conf.lua) for you. If it weren't able, it should spit an error just like Lua does.

When you say nothing happens, do you mean you get a black window, a no game window, or no window at all? What happens if you run it from the command line?

And yeah, something in your Lua installation is screwed up as zorg noted (maybe an environment variable that should not be set? maybe it was set by Emacs?). I don't think that should affect Löve programs. It's very unusual to find Löve programs that require external modules from the user's installation; it's more common that Löve programs are self-contained. But there's a chance that some environment variable is interfering with Löve's method for finding modules.
dcjdcjdcj
Prole
Posts: 2
Joined: Sun Oct 04, 2020 11:16 pm

Re: Lua cannot load Love modules

Post by dcjdcjdcj »

So, I found out what the issue was; my emacs config was wrong. I had it invoking Lua (well, a fennel repl) rather than love as an inferior process, and so Lua was failing to load Love. When I ran love as the inferior repl, things started working.

There was also some nastiness in my LUA_PATH that I cleaned up.

Anyway, I am happily hacking away with hot reloading of lua files now. Thanks all!
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 222 guests