I'm trying to use love2d as an optional dependency in a project that is not a game.
Love requires that I put all of my dependencies inside of it (which is a major pain) and run my application from `main.lua`. This is not what I want, but I can most likely make it work.
Ideally, I'd like to `require 'love2d'`, do the initialization and override the callbacks and then run it.
My questions are:
Has anyone done this already?
Can someone estimate the level of pain I'm in for if I decide to try to hack Love2D into submission?
If this sounds like a Bad Idea and you think that you understand what I'm going for, I'm open to suggestions.
I think that the alternative would be to set Love's require path to `"../?.lua;../?/init.lua"` and make the `main.lua` load my test file... or something.
I don't want to over-complicate this, but right now, things are overcomplicated. Thank you in advance for your help!
[SOLVED] Love as a dependancy or require 'love2d'?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
[SOLVED] Love as a dependancy or require 'love2d'?
Last edited by pancreas on Sun Jan 17, 2016 8:15 pm, edited 1 time in total.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Love as a dependancy or require 'love2d'?
It is definitely possible, it's just fairly tricky to pull off. The easiest way might be to set package.preload.love to the result of calling package.loadlib on the love so/dll with "luaopen_love", and then requiring love. This loads love, but that probably isn't all. The next step, probably, is to require love.filesystem, then immediately call love.filesystem.init with the program's argv0. After that, if everything works, you should be able to require all the modules and use them as normal.
Note that unless you require love.boot and run the result, you don't have the normal initialisation done for you, like whatever's set from conf.lua. If you do run that, it starts the normal "boot sequence" and tries to load your main.lua etc.
Note that unless you require love.boot and run the result, you don't have the normal initialisation done for you, like whatever's set from conf.lua. If you do run that, it starts the normal "boot sequence" and tries to load your main.lua etc.
Re: Love as a dependancy or require 'love2d'?
Wow, it actually works!
EDIT: see below for a much simpler approach
It needs to disable the love.filesystem.init() call in boot.lua (this one is from 0.9.2 which is the only one I have that is compiled dynamically; I've compiled all others as static):
The only problem in this case is that the library name is OS-dependent.
(Edited to change lua to luajit)
EDIT: see below for a much simpler approach
Code: Select all
#!/usr/bin/env luajit
package.preload.love = package.loadlib('./liblove.so.0', 'luaopen_love')
require('love')
require('love.filesystem')
love.filesystem.init(arg[0])
require('boot')()
Code: Select all
$ diff -u ../../compile/love-hg/src/scripts/boot.lua .
--- ../../compile/love-hg/src/scripts/boot.lua 2016-01-06 19:20:05.000000000 +0100
+++ ./boot.lua 2016-01-06 19:25:57.000000000 +0100
@@ -247,7 +247,7 @@
local o = love.arg.options
local arg0 = love.arg.getLow(arg)
- love.filesystem.init(arg0)
+-- love.filesystem.init(arg0)
-- Is this one of those fancy "fused" games?
local can_has_game = pcall(love.filesystem.setSource, arg0)
Code: Select all
chmod +x love.lua
./love.lua /path/to/game.love
The only problem in this case is that the library name is OS-dependent.
(Edited to change lua to luajit)
Last edited by pgimeno on Wed Jan 06, 2016 10:55 pm, edited 1 time in total.
Re: Love as a dependancy or require 'love2d'?
Woah. Much love to you all. Thank you! It will be a day before I can try this out, but I wanted to thank you both for your help and for trying this out.
- slime
- Solid Snayke
- Posts: 3162
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Love as a dependancy or require 'love2d'?
You shouldn't need to do that if you avoid calling love.filesystem.init or any other love.filesystem functions before calling love.boot (i.e. if you let love.boot initialize love.filesystem).pgimeno wrote:It needs to disable the love.filesystem.init() call in boot.lua
Re: Love as a dependancy or require 'love2d'?
I didn't get that to work earlier. I think it's because I followed bartbes' recipe and then forgot to re-add the call to love.filesystem.init to boot.lua. But yes, this works just as well:slime wrote:You shouldn't need to do that if you avoid calling love.filesystem.init or any other love.filesystem functions before calling love.boot (i.e. if you let love.boot initialize love.filesystem).pgimeno wrote:It needs to disable the love.filesystem.init() call in boot.lua
Code: Select all
#!/usr/bin/env luajit
package.preload.love = package.loadlib('./liblove.so.0', 'luaopen_love')
require('boot')()
Re: [SOLVED] Love as a dependancy or require 'love2d'?
Hello people!
I am rather new to Love2d. I was actually also trying to 'require 'love2d'' and by searching around I bumped into this thread. I am on Windows, so I am trying to load love.dll with the following command:
When I do this I get the following error:
Does anybody have an idea as to what the problem might be? I have no problems running Love2d the 'normal way', just if I try to load the library from lua in this way. I have bumped my head around it quite a lot, this is not strictly necessary for my project but now I am curious to know how the problem could be solved. I am using the compiled Love2d binaries from the main page and Lua 5.1.4 at the moment.
I am rather new to Love2d. I was actually also trying to 'require 'love2d'' and by searching around I bumped into this thread. I am on Windows, so I am trying to load love.dll with the following command:
Code: Select all
package.preload.love = package.loadlib('./love.dll', 'luaopen_love')
Code: Select all
%1 is not a valid Win32 application.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: [SOLVED] Love as a dependancy or require 'love2d'?
Are you trying to load a 64-bit love using 32-bit lua, or the other way around, perhaps?
Re: [SOLVED] Love as a dependancy or require 'love2d'?
Thanks, it changed by installing Love2d 32 bit, so I guess that was the issue!
-
- Prole
- Posts: 1
- Joined: Wed Jun 01, 2016 1:24 pm
Re: [SOLVED] Love as a dependancy or require 'love2d'?
I am also trying to require love2d as a dependency but I cannot figure out how to build liblove.so.0
I am using MacOS.
First I downloaded the MacOS SDK and put the framework files in Libraries/Framework
Then I downloaded the sources and opened liblove.xcodeproj (in subfolder platform/xcode) with XCode.
Build is successful but generates a love.framework thing.
I can't get Xcode to build what I want, which is liblove.so.0
Would someone mind explaining how to achieve this (step-by-step if not too much trouble)?
Many thanks
I am using MacOS.
First I downloaded the MacOS SDK and put the framework files in Libraries/Framework
Then I downloaded the sources and opened liblove.xcodeproj (in subfolder platform/xcode) with XCode.
Build is successful but generates a love.framework thing.
I can't get Xcode to build what I want, which is liblove.so.0
Would someone mind explaining how to achieve this (step-by-step if not too much trouble)?
Many thanks
Who is online
Users browsing this forum: Bing [Bot] and 7 guests