[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Embedding Lua twice?
- From: Sean Conner <sean@...>
- Date: Thu, 27 Nov 2014 22:46:46 -0500
It was thus said that the Great Thiago L. once stated:
>
> On 27/11/14 06:24 PM, Luiz Henrique de Figueiredo wrote:
> >>Hi! Is there any way to have Lua 5.1 (actually LuaJIT) and Lua 5.2
> >>(LuaJIT doesn't support _ENV) on the same program?
> >I don't know about LuaJIT but you can have two versions of Lua in the
> >same program by building custom versions using one.c and a header file
> >that redefines all external symbols to have a different prefix, such
> >as lua51 and lua52. You'll need to compile your program modules with
> >the header files for each version. See this:
> > http://lua-users.org/lists/lua-l/2014-07/msg00164.html
> >
> Uhh so if I have some Lua .so's I can't dlopen them?
Here's the issue: you have foo.so, a Lua module. You have your magic Lua
interpreter that manages to include both LuaJIT and Lua 5.2. foo.so wants
to call the function lua_load(). LuaJIT, being compatible with Lua 5.1, has
lua_load() defined as:
int lua_load(
lua_State *L,
lua_Reader reader,
void *data,
const char *source
);
Whereas Lua 5.2 defines lua_load() as:
int lua_load(
lua_State *L,
lua_Reader reader,
void *data,
const char *source,
const char *mode
);
The call to dlsym() is:
void *dlsym(void *handle,const char *symbol);
(where handle is the result of dlopen()). All that dlsym is given is
"lua_load". That's it. No other information (return type, parameters, etc)
is given, just the name "lua_load". dlsym() will have to pick one, and
given the way linking works [1] (and assuming you get a program to link with
two different versions of the same function, which isn't impossible [2]) you
only stand a 50/50% chance of getting the right version of the function (or
a 50/50% chance of a core dump depending upon your outlook).
-spc (And notice that I gave no indication of which Lua version foo.so was
compiled against ... )
[1] For way more than you probably wanted to know about linking:
http://www.iecc.com/linker/
[2] The ELF executable format, used by most modern Unix systems, do
allow for multiple versions of the same function, but there's some
deep compiler and linker magic [1] required to get it working, and
foo.so would need to be recompiled using said compiler and linker
magic to even have a hope of working.