Page 1 of 1

Lua cannot load Love modules

Posted: Sun Oct 04, 2020 11:23 pm
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.

Re: Lua cannot load Love modules

Posted: Mon Oct 05, 2020 3:56 am
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...

Re: Lua cannot load Love modules

Posted: Mon Oct 05, 2020 6:14 am
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)

Re: Lua cannot load Love modules

Posted: Mon Oct 05, 2020 9:38 am
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.

Re: Lua cannot load Love modules

Posted: Tue Oct 06, 2020 11:39 pm
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!