Love as Lua module

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
vincentg
Prole
Posts: 15
Joined: Wed Apr 18, 2018 3:26 pm

Love as Lua module

Post 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.
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Love as Lua module

Post 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.
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.
Kimapr
Prole
Posts: 2
Joined: Wed Dec 19, 2018 1:14 pm

Re: Love as Lua module

Post 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.
User avatar
pgimeno
Party member
Posts: 3673
Joined: Sun Oct 18, 2015 2:58 pm

Re: Love as Lua module

Post 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).
Last edited by pgimeno on Mon Dec 31, 2018 6:21 pm, edited 1 time in total.
vincentg
Prole
Posts: 15
Joined: Wed Apr 18, 2018 3:26 pm

Re: Love as Lua module

Post 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.
User avatar
pgimeno
Party member
Posts: 3673
Joined: Sun Oct 18, 2015 2:58 pm

Re: Love as Lua module

Post by pgimeno »

It needs Lua 5.1 or LuaJIT. Are you using LuaJIT to launch it?
vincentg
Prole
Posts: 15
Joined: Wed Apr 18, 2018 3:26 pm

Re: Love as Lua module

Post 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.
User avatar
slime
Solid Snayke
Posts: 3166
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Love as Lua module

Post by slime »

You'll probably need to use LUA_CPATH rather than LUA_PATH, since it's a C module.
vincentg
Prole
Posts: 15
Joined: Wed Apr 18, 2018 3:26 pm

Re: Love as Lua module

Post by vincentg »

Thanks! I didn't know that one.
Post Reply

Who is online

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