Sharing lua library have resources (image)

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
zaher
Prole
Posts: 6
Joined: Sat Nov 05, 2016 10:28 pm
Location: Syria, Damascus
Contact:

Sharing lua library have resources (image)

Post by zaher »

I have Lua library for Love2D (let assume it is kind of framework),
If I want to share it between my Love2D projects, I will put it in folder and point LUA_PATH to this folder.
It is works fine until now, but what if I have an image or sound file inside this lib that I want to load it from my project? In my first tries it failed to load.

the best way to slove it to put this lib in the same folder of my project, but that will make it hard to share it between my projects.

Any Idea?

Thanks
User avatar
Beelz
Party member
Posts: 234
Joined: Thu Sep 24, 2015 1:05 pm
Location: New York, USA
Contact:

Re: Sharing lua library have resources (image)

Post by Beelz »

AFAIK you can put whatever you want in the folder with the LOVE exe and it will be included in every project you make, so long as you require it. I'd avoid this though because when/if you want to share your creations, you'd have to copy the files into your project directory before you zip it up or nobody could play it.

Code: Select all

if self:hasBeer() then self:drink()
else self:getBeer() end
GitHub -- Website
User avatar
airstruck
Party member
Posts: 650
Joined: Thu Jun 04, 2015 7:11 pm
Location: Not being time thief.

Re: Sharing lua library have resources (image)

Post by airstruck »

Why not just symlink it into your project? Love follows symlinks by default; zip should also (info-zip does, at least).
User avatar
peterrust
Prole
Posts: 42
Joined: Thu Dec 29, 2016 8:49 pm
Location: Bellingham, WA, USA
Contact:

Re: Sharing lua library have resources (image)

Post by peterrust »

zaher: Often, when developing a shared library like this, versioning becomes important. Imagine, for example, that you develop two projects simultaneously that both depend on the same shared library. You lose interested in one of the projects and focus exclusively on the other -- pretty soon you're making changes only to this project and the shared library, and those changes break compatibility with the first project (either unintentionally or intentionally and you just don't have time to keep the other project updated).

Then a year later you go back and try to run the first project and of course it doesn't run because of the incompatible changes made to the library.

Package managers (like LuaRocks) were invented to deal with this kind of problem -- so that multiple projects can rely on different versions of the shared dependency. If there is a high likelihood that you'll run into this kind of problem, you may want to use LuaRocks to manage your dependency and keep it updated.

That said, doing development this way can be a pain -- you have to make the changes to the library, increase the version number and then make the one project depend on the higher version number and use LuaRocks to update it. Using symlinking, as airstruck suggested, is much easier -- I would use it as long as possible, until the projects diverge. Or just make copies of the dependency and throw a simple version number (like `v2`) in the folder name, and explicitly copy it back & forth when you need to bring the updates to the other project.
User avatar
zaher
Prole
Posts: 6
Joined: Sat Nov 05, 2016 10:28 pm
Location: Syria, Damascus
Contact:

Re: Sharing lua library have resources (image)

Post by zaher »

Thank you all, but
All answers depends on putting my library inside the game directory. so let me explain my project,

I am building environment close to my old BASIC environment MSX/ZX/Commodore to teach kids programming Lua, (I like to finish it before this summer)
For temporary I called it BASIC (i need new name)

https://github.com/parmaja/lua-basic/

My problem is how to tell my kid to put "basic" library in him for each project folder, I meant, I want to make it more easy just to make one lua file everywhere, then run it.

BTW, I will go to with putting "basic" into project folder but that will make "demos" folder be the as root directory, it is confused me.
Post Reply

Who is online

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