Lua load path for shared objects

I am using lua 5.3beta under Kubuntu 12.04. I wrapped a c extension using swig and gcc4.9 for compilation and linking. If I put mylib.so in the same directory, my lua script is in:

require "mylib"

      

works great. But if mylib.so is not in the same directory then I get the error

module 'mylib' not found 

      

I added the path to mylib in LD_LIBRARY_PATH and pasted

package.path  = package.path .. ';' .. path2mylib .. '/?

      

in script. Through

package.path  = package.path .. ';' .. path2mylib .. '/?.so

      

error message:

mylib.so:1: unexpected symbol near '<\127>

      

I think lua is trying to load mylib.so, assuming it's a lua-script. It seems that lua only looks for shared objects within certain standard paths, including. / and all paths added to package.path are treated as paths to lua files.

Is there a way to make lua load my c extension without putting it in one of the standard library paths?

+3


source to share


1 answer


The variable path that tells the Lua, where to find a library written in the C, package.cpath

.



package.path

intended for libraries written in Lua.

+2


source







All Articles