[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Packaging issue: standalone interpreter requires dynamic linking
- From: Norman Ramsey <nr@...>
- Date: Sat, 10 May 2008 15:28:13 -0400
> 2008/5/8 Norman Ramsey <nr@eecs.harvard.edu>:
> > This is really an issue for the Lua team, but I thought I would send to
> > the whole list to see how others are coping with this issue.
> >
> > I work on a broken Unix system (sometimes called 'GNU/Linux') in which
> > critically important tools such as gprof do not work properly in the
> > presence of dynamically linked libraries...
>
> You can make a simple modification of lua.c to make use of the
> package.preload table. First define a static array with all the
> modules you want to use:
>
> extern int luaopen_osbf3_core(lua_State *);
> extern int luaopen_fastmime(lua_State *);
>
> static struct luaL_Reg modules[] = {
> {"osbf3.core", luaopen_osbf3_core}, /* don't forget to replace the
> underscores in module names with dots */
> {"fastmime", luaopen_fastmime},
> {0, 0},
> };
>
> Then just after luaL_openlibs, add the following lines:
>
> lua_getglobal(L, "package");
> lua_getfield(L, -1, "preload");
> luaL_register(L, 0, modules);
> lua_pop(L, 2); /* pop package and package.preload */
>
> This will pre-register all your modules in one step. Then normal calls
> to 'register' from your scripts in Lua will call the entry points just
> like if they were loaded from a shared library.
You mean 'require' not 'register', right?
I like this suggestion for two reaons:
1. It is much cleaner than my solution.
2. If anybody is crazy enough to have side effects in the
module-loading code, they will occur at the proper time (the
first 'require' and not startup time.
However, the problem remains that I still have to edit the lua.c file.
Let me put forth a concrete suggestion to the Lua team:
1. The auxiliary library should be extended with a function
void luaL_openlibs_static(lua_State *L)
which does nothing.
2. This function should be called in lua.c immediately after
luaL_openlibs.
3. By defining my own .c file and linking the .o before -llua5.1
on the link line, I can override this function with the code
Jerome has suggested above.
With a change like this I could statically link my own libraries
without touching one line of distributed code.
Norman