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.
Love as Lua module
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Love as Lua module
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 True 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.
Re: Love as Lua module
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
This works for me if I copy liblove-11.2.so as love.so:
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:
And of course, you need to compile it dynamically, but that is the default (or grab a precompiled build).
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
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')
Last edited by pgimeno on Mon Dec 31, 2018 6:21 pm, edited 1 time in total.
Re: Love as Lua module
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
It needs Lua 5.1 or LuaJIT. Are you using LuaJIT to launch it?
Re: Love as Lua module
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.
- slime
- Solid Snayke
- Posts: 3162
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Love as Lua module
You'll probably need to use LUA_CPATH rather than LUA_PATH, since it's a C module.
Re: Love as Lua module
Thanks! I didn't know that one.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 1 guest