How to import a library like this one ?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
Phlimy
Prole
Posts: 7
Joined: Sat Mar 19, 2016 6:02 pm
Contact:

How to import a library like this one ?

Post by Phlimy »

Hi, I would like to use a function that is only in Lua 5.3, string.pack(), and I found a library that implements this function in Lua 5.2 : http://www.inf.puc-rio.br/~roberto/struct/

The problem is that I have absolutely no idea where to put the files and how to import it with Löve, can someone enlighten me ?
Don't panic and never forget your towel.
User avatar
Pixelwar
Prole
Posts: 7
Joined: Sun May 10, 2015 10:48 am
Contact:

Re: How to import a library like this one ?

Post by Pixelwar »

you can check out the teststruct.lua file, there are some examples including how to import.

Code: Select all

local lib = require"struct"
@pixelwar_studio on twitter
User avatar
Phlimy
Prole
Posts: 7
Joined: Sat Mar 19, 2016 6:02 pm
Contact:

Re: How to import a library like this one ?

Post by Phlimy »

Thanks! But where do I put the files ? I tried to put them in the LOVE folder and it says it can't find 'struct'.
Don't panic and never forget your towel.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: How to import a library like this one ?

Post by raidho36 »

Not sure why would you need this, the FFI module already does that.

You need to build the C file (C source code) using supplied makefile with a "make" autotool. Then you put resulting dynamically loaded library binary and the accompanying .lua file in the same folder, because latter imports former. Note that because that would be an external library, you won't be able to use it from within zipped .love file, you'd need to export it to physical filesystem first.
User avatar
Davidobot
Party member
Posts: 1226
Joined: Sat Mar 31, 2012 5:18 am
Location: Oxford, UK
Contact:

Re: How to import a library like this one ?

Post by Davidobot »

Phlimy wrote:Thanks! But where do I put the files ? I tried to put them in the LOVE folder and it says it can't find 'struct'.
You put it into your project folder - i.e in the directory where your main.lua is located.
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: How to import a library like this one ?

Post by Positive07 »

Nope, you compile the C file as the makefile indicates using Lua header files, then that should generate a .dll or .so depending on your OS, that file needs to be somewhere LÖVE can find it, if on Windows then that should be next to love.exe. Then you put struct.lua (not the .dll) inside of your .love file.

Using binary libraries is a pain so I don't recommend it, you should look for a way to use this feature without compiling anything.
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
User avatar
Phlimy
Prole
Posts: 7
Joined: Sat Mar 19, 2016 6:02 pm
Contact:

Re: How to import a library like this one ?

Post by Phlimy »

Thanks for these answers!
I managed to do what I wanted to do without it, but thank you very much anyway!
If I need anything like this again I'll know how to use it now.
Don't panic and never forget your towel.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], slime and 2 guests