I am trying to pass data (arrays) between python and lua and I want to manipulate the data in lua using the Torch7 framework. I figured this can best be done through C, sin
On Linux Lua modules don't link to the Lua library directly but instead expect to find the Lua API functions already loaded. This is usually done by exporting them from the interpreter using the -Wl,-E
linker flag. This flag only works for symbols in executables, not shared libraries. For shared libraries there exists something similar: the RTLD_GLOBAL
flag for the dlopen
function. By default all shared libraries listed on the compiler command line are loaded using RTLD_LOCAL
instead, but fortunately Linux reuses already opened library handles. So you can either:
Preload the Lua(JIT) library using RTLD_GLOBAL
before it gets loaded automatically (which happens when you load libcluaf.so
):
from ctypes import byref, cdll, c_int
import ctypes
lualib = ctypes.CDLL("libluajit-5.1.so", mode=ctypes.RTLD_GLOBAL)
l = cdll.LoadLibrary('absolute_path_to_so/libcluaf.so')
# ...
Or change the flags of the Lua(JIT) library handle afterwards using the RTLD_NOLOAD
flag for dlopen
. This flag is not in POSIX though, and you probably have to use C to do so. See e.g. here.