Page 1 of 2
Possible to link .so (compiled) libraries with require("li")
Posted: Sat Sep 29, 2012 7:27 pm
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
Re: Possible to link .so (compiled) libraries with require("
Posted: Sat Sep 29, 2012 7:53 pm
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.
Re: Possible to link .so (compiled) libraries with require("
Posted: Sun Sep 30, 2012 9:22 am
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) )
Re: Possible to link .so (compiled) libraries with require("
Posted: Sun Sep 30, 2012 9:54 am
by Nixola
(Side note: print doesn't need tostring)
Re: Possible to link .so (compiled) libraries with require("
Posted: Sun Sep 30, 2012 9:54 am
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)
Re: Possible to link .so (compiled) libraries with require("
Posted: Sun Sep 30, 2012 9:56 am
by Nixola
(Right, my bad. Sorry for that ^^')
Re: Possible to link .so (compiled) libraries with require("
Posted: Sun Sep 30, 2012 12:13 pm
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)))
Re: Possible to link .so (compiled) libraries with require("
Posted: Sun Sep 30, 2012 12:26 pm
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.
Re: Possible to link .so (compiled) libraries with require("
Posted: Wed Oct 24, 2012 7:48 pm
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
Re: Possible to link .so (compiled) libraries with require("
Posted: Wed Oct 24, 2012 10:40 pm
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.