Possible to link .so (compiled) libraries with require("li")

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
nodepond
Prole
Posts: 8
Joined: Wed Sep 19, 2012 3:16 pm
Location: Cologne, Germany
Contact:

Possible to link .so (compiled) libraries with require("li")

Post by nodepond »

Hi there. I am sitting here, preparing a projection mapping with love2d (no really, will post about the project later). For that, I want to embed a OSC (OpenSoundControl) lib into my setup. I got everything done and the OSC-lib works fine when using Lua directly from the console/Terminal. The lib I used is compiled, resulting in a .so-file. -> https://github.com/grrrwaaa/luaosc

Now I try to do the same thing in a Love2D-project. But Love won't find the lib. "error module osc not found". Even when I try to put the .so file into the paths, that Love tolds it would search - no lock (like i.e. ./osc.so or my user folder). Now my question: is it possible to load compiled libs (.so) with Love2D?

regards and keep the lua-spirit alive ;)
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Possible to link .so (compiled) libraries with require("

Post by bartbes »

It should load them, yeah.
Love looks for them in the base write directory (so probably ~/.local/share/love), and lua looks for them in the default paths. That said, if it fails to load because of another reason (i.e. it can't find its dependencies) it usually looks the same as it not finding it at all.
User avatar
qaisjp
Party member
Posts: 490
Joined: Tue Sep 04, 2012 10:49 am
Location: United Kingdom
Contact:

Re: Possible to link .so (compiled) libraries with require("

Post by qaisjp »

try this code, tell us what appears in the console

Code: Select all

local success, error = pcall(require, "li")
print("SUCCESS: " .. tostring(success) .. "    ; ERROR: " .. tostring(error) )
Lua is not an acronym.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Possible to link .so (compiled) libraries with require("

Post by Nixola »

(Side note: print doesn't need tostring)
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
qaisjp
Party member
Posts: 490
Joined: Tue Sep 04, 2012 10:49 am
Location: United Kingdom
Contact:

Re: Possible to link .so (compiled) libraries with require("

Post by qaisjp »

Nixola wrote:(Side note: print doesn't need tostring)
(Side side note: concatenating does need tostring otherwise you get an error like cannot concatenate a userdata value or whatever)
Lua is not an acronym.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Possible to link .so (compiled) libraries with require("

Post by Nixola »

(Right, my bad. Sorry for that ^^')
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Possible to link .so (compiled) libraries with require("

Post by kikito »

Lua coerces numbers into string, so concatenating a value which you are sure is a number works just fine:

Code: Select all

print("The number " .. 3) -- works
Other types, like tables, functions or nil values, are not coerced and need the tostring call.

That said, print takes a variable number of arguments, and invokes tostring on each. So you could also do this:

Code: Select all

local success, error = pcall(require, "li")
print("SUCCESS: ", success,  "ERROR: ", error)
That however will put "tabs" between each parameter, which might not be desired in some cases. But it's just fine for debugging.

For interpolating more than 1 value in a string while fine-tunning the spacing, I usually prefer string.format:

Code: Select all

print(("SUCCESS: %s  ;ERROR: %s"):format(tostring(success), tostring(error)))
When I write def I mean function.
User avatar
qaisjp
Party member
Posts: 490
Joined: Tue Sep 04, 2012 10:49 am
Location: United Kingdom
Contact:

Re: Possible to link .so (compiled) libraries with require("

Post by qaisjp »

Snip quoting the above:

Yeah, I forgot print takes multiple values without need for tostringing it.
I do use strformat but when debugging i forget these things.
Lua is not an acronym.
User avatar
nodepond
Prole
Posts: 8
Joined: Wed Sep 19, 2012 3:16 pm
Location: Cologne, Germany
Contact:

Re: Possible to link .so (compiled) libraries with require("

Post by nodepond »

Hi there. It's been a while, since I have had the time to fiddle around with this code again.

By coincidence I came across a linux vs. osx topic. I heard, that .so (shared objects) work in Linux and Windows-Systems, but not on OS-X. There I need to compile it to a .dylib file format. Could this the reason that linking to the lib did now worked for me? Maybe I'll try it later this evening and report about my .dylib-test.

Meanwhile, here is some footage from our little party installation made with Love2d: http://www.nodepond.com/blog/383-projec ... 12-cologne
User avatar
slime
Solid Snayke
Posts: 3170
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Possible to link .so (compiled) libraries with require("

Post by slime »

OSX dynamic libraries normally have the .dylib extension, however Lua libraries have the .so extension on both OSX and Linux. I believe (but I'm not positive) that you do need to compile them separately on OSX and Linux.
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests