Page 1 of 1

How to import a library like this one ?

Posted: Sun Nov 27, 2016 5:13 pm
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 ?

Re: How to import a library like this one ?

Posted: Sun Nov 27, 2016 5:24 pm
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"

Re: How to import a library like this one ?

Posted: Sun Nov 27, 2016 6:01 pm
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'.

Re: How to import a library like this one ?

Posted: Sun Nov 27, 2016 9:36 pm
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.

Re: How to import a library like this one ?

Posted: Sun Nov 27, 2016 10:32 pm
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.

Re: How to import a library like this one ?

Posted: Sun Nov 27, 2016 11:14 pm
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.

Re: How to import a library like this one ?

Posted: Wed Nov 30, 2016 12:29 pm
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.