Page 1 of 1

Love as Lua module

Posted: Thu Dec 20, 2018 4:45 pm
by vincentg
Is there a way to use Love as a regular Lua module in a standalone Lua application?
Something like require('love')? I would see some useful features we could use outside a game like image batch processing where love window/game loop is not needed.

Re: Love as Lua module

Posted: Thu Dec 20, 2018 5:11 pm
by zorg
You can set love.window to false if you have a conf.lua defined, and you can redefine love.run yourself so that it doesn't loop at all; although if you write your main.lua to simply exit at the end, that can also work.

Re: Love as Lua module

Posted: Thu Dec 20, 2018 6:03 pm
by Kimapr
zorg wrote: Thu Dec 20, 2018 5:11 pm You can set love.window to false if you have a conf.lua defined, and you can redefine love.run yourself so that it doesn't loop at all; although if you write your main.lua to simply exit at the end, that can also work.
Yes, but this way you don't use LOVE as a module - your scripts still run under LOVE. Maybe it's possible to use LOVE as a library, but there is only one way to figure it out, try to do it by yourself. The problem is that it's hard.

Re: Love as Lua module

Posted: Thu Dec 20, 2018 6:53 pm
by pgimeno
This works for me if I copy liblove-11.2.so as love.so:

Code: Select all

require 'love'
require 'love.filesystem'
require 'love.window'
require 'love.graphics'
love.filesystem.init('.')
love.window.setMode(800, 600)
for i = 1, 100 do
  love.graphics.clear()
  love.graphics.rectangle("fill", 300,250,200,100)
  love.graphics.present()
end
For some reason,trying to use the font module resulted in a segfault at exit, though. I haven't dug into why. EDIT: It seems require('love.font') must be placed BEFORE require('love.window'), otherwise you get the segfault.

You can put this line at the top if you want more flexibility with the name of the LÖVE library:

Code: Select all

package.preload.love = package.loadlib('/path/to/liblove-11.2.so', 'luaopen_love')
And of course, you need to compile it dynamically, but that is the default (or grab a precompiled build).

Re: Love as Lua module

Posted: Sat Dec 22, 2018 1:22 am
by vincentg
Thanks for the reply. It didn't work for me to use liblove-11.2.so. Maybe a incompatibility of versions, I will investiguate.

Re: Love as Lua module

Posted: Sat Dec 22, 2018 1:44 am
by pgimeno
It needs Lua 5.1 or LuaJIT. Are you using LuaJIT to launch it?

Re: Love as Lua module

Posted: Mon Dec 31, 2018 4:02 pm
by vincentg
Yes I'm using LuaJIT 2.0.5 from my system. Actually it seems to work more or less with package.loadlib but not with the env variable LUA_PATH that's working with other modules.

Re: Love as Lua module

Posted: Mon Dec 31, 2018 4:28 pm
by slime
You'll probably need to use LUA_CPATH rather than LUA_PATH, since it's a C module.

Re: Love as Lua module

Posted: Tue Jan 01, 2019 11:33 am
by vincentg
Thanks! I didn't know that one.