[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: PATCH: Lua5.1-work3 loadlib cleanups
- From: Mike Pall <mikelu-0412@...>
- Date: Tue, 7 Dec 2004 08:50:03 +0100
the #ifdef logic in luaconf.h for loadlib support does not work properly
on a variety of systems. I think it's easier to reorder the tests and
just assume the availability of POSIX dlfcn unless we know otherwise
(i.e. only for Windows and Mac OS X (* see below for more)).
Now you need to explicitly disable loadlib support in the config file for
systems that do *not* have it. You'll probably need to modify the config file
for these kind of systems, anyway.
The intention is to reduce the number of modifications required for a
standard installation on the majority of systems to zero.
The other changes included in this patch are:
- Clean up the comments.
- Avoid the MYLDFLAGS redefinition pitfall.
- Create the C library and Lua library directories when installing.
- Stop echoing unused Makefile variables.
- Add simplified dependencies. Certainly better than no dependencies.
- Add a version define that allows for stuff like:
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 0x050100L
Note that prerelease ("work") versions need to be tagged with the release
version they are destined for ("5.1.0" -> 0x050100L).
NB: It needs to be a long constant to account for 16 bit systems.
- Correct the version number in the library paths.
- Add standard library paths for Windows.
- Set the proper directory separator for Windows.
- Got rid of the double TMPNAME define (who is using it anyway?).
- Modify the translation of module names to C function names. A module
"foo.bar.baz" previously had to provide luaopen_foobarbaz() and now
should use luaopen_foo_bar_baz().
(*) One open issue left is the loadlib support for Mac OS X:
AFAIK Mac OS X has two different mechanisms for dynamic libraries: dylibs
and bundles. The former is used for basic libraries while the latter is
used for framework components aka plugins.
One unpleasant fact is that dylibs cannot be unloaded (as noted in the
comments in loadlib.c) because they are not intended for this use.
However this is generally very desirable for Lua modules (e.g. level
loading/unloading in games). And (BTW) Lua-5.1-work3 includes support for
garbage collecting loaded C modules.
I am not a Mac OS X expert but the docs I've read more or less say that you
are supposed to use bundles whenever you need some kind of pluggable modules.
Since Lua modules are only useful when loaded by Lua there is no necessity
to make them dylibs. They are more like plugins, anyway.
Can any Mac OS X experts please confirm this? Should Lua C modules switch
from dylibs to bundles? If yes, can anyone provide the required modifications
diff -ur lua-5.1-work3/Makefile lua-5.1-work3-loadlib/Makefile
--- lua-5.1-work3/Makefile 2004-10-30 04:24:54.000000000 +0200
+++ lua-5.1-work3-loadlib/Makefile 2004-12-07 07:07:45.022635168 +0100
@@ -31,6 +31,7 @@
# official installation
install: all strip
mkdir -p $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN)
+ mkdir -p $(INSTALL_CLIB) $(INSTALL_LUALIB)
$(INSTALL_EXEC) bin/* $(INSTALL_BIN)
$(INSTALL_DATA) include/*.h $(INSTALL_INC)
$(INSTALL_DATA) lib/*.a $(INSTALL_LIB)
@@ -43,10 +44,6 @@
@echo "LOADLIB = $(LOADLIB)"
@echo "DLLIB = $(DLLIB)"
- @echo "NUMBER = $(NUMBER)"
- @echo "POPEN = $(POPEN)"
- @echo "TMPNAM = $(TMPNAM)"
- @echo "DEGREES = $(DEGREES)"
@echo "USERCONF = $(USERCONF)"
@echo "CC = $(CC)"
@echo "WARN = $(WARN)"
@@ -63,6 +60,8 @@
@echo "INSTALL_MAN = $(INSTALL_MAN)"
@echo "INSTALL_EXEC = $(INSTALL_EXEC)"
@echo "INSTALL_DATA = $(INSTALL_DATA)"
+ @echo "INSTALL_CLIB = $(INSTALL_CLIB)"
+ @echo "INSTALL_LUALIB = $(INSTALL_LUALIB)"
@echo "Edit $(LUA)/config if needed to suit your platform and then run make."
diff -ur lua-5.1-work3/config lua-5.1-work3-loadlib/config
--- lua-5.1-work3/config 2004-12-07 01:58:44.000000000 +0100
+++ lua-5.1-work3-loadlib/config 2004-12-07 07:11:30.503356888 +0100
@@ -13,28 +13,27 @@
# Support for dynamically loading C libraries for Lua is a very important
# feature, which we strongly recommend be enabled. By default, this support is
-# enabled on Windows systems (see below) but disabled on other systems because
-# it relies on system-dependent code that is not part of ANSI C. For more
-# information on dynamic loading, read the comments in src/lib/loadlib.c .
-# To enable support for dynamic loading on Unix systems that support the dlfcn
-# interface (e.g., Linux, Solaris, IRIX, BSD, AIX, HPUX, and probably others),
-# uncomment the next two lines. Also read the next paragraph.
+# enabled on all systems even though it relies on system-dependent code that
+# is not part of ANSI C. For more information on dynamic loading, read the
+# comments in src/lib/loadlib.c .
+# To disable support for dynamic loading, uncomment the next line.
+# To enable support for dynamic loading on POSIX 1003.1-2001 compliant systems
+# that support the dlfcn interface (e.g., Linux, Solaris, IRIX, BSD, AIX,
+# HP-UX, and probably others) in a separate library you may need the next
+# line. Also read the next paragraph.
-# In Linux with gcc, you should also uncomment the next definition for
+# On systems with gcc and ELF binaries, you will need the next definition for
# MYLDFLAGS, which passes -E (= -export-dynamic) to the linker. This option
-# allows dynamic libraries to link back to the `lua' program, so that they do
-# not need the Lua libraries. (Other systems may have an equivalent facility.)
+# allows dynamic libraries to link back to the `lua' program, so that they can
+# access the Lua core C API. (Other systems may have an equivalent facility.)
-# On Windows systems. support for dynamic loading is enabled by default.
-# To disable this support, uncomment the next line.
# --------------------------------------------------------------- Lua libraries
@@ -74,14 +73,13 @@
# Write here any options you may need for your C compiler.
# If you are using gcc, -O3 will get you a faster but larger code. You can
# also add -fomit-frame-pointer to get even faster code at the cost of losing
-# debug information. If you only want the shared libraries, you may want to
-# add -fPIC to MYCFLAGS.
+# debug information (this only makes sense on i386 though).
-#MYCFLAGS= -O3 -fomit-frame-pointer # -fPIC
+#MYCFLAGS= -O3 -fomit-frame-pointer
-# Write here any options you may need for your C linker.
+# Add here any options you may need for your C linker.
# ------------------------------------------------------------------ librarian
@@ -111,6 +109,8 @@
# You may prefer to use "install" instead of "cp" if you have it.
# If you use "install", you may also want to change the permissions after -m.
diff -ur lua-5.1-work3/src/Makefile lua-5.1-work3-loadlib/src/Makefile
--- lua-5.1-work3/src/Makefile 2003-12-10 10:32:15.000000000 +0100
+++ lua-5.1-work3-loadlib/src/Makefile 2004-12-07 08:10:12.152984768 +0100
@@ -81,3 +81,6 @@
rm -f $(SRCS)
+# Simplified dependencies
+$(OBJS): *.h $(INC)/*.h
diff -ur lua-5.1-work3/src/lib/Makefile lua-5.1-work3-loadlib/src/lib/Makefile
--- lua-5.1-work3/src/lib/Makefile 2004-07-22 22:53:45.000000000 +0200
+++ lua-5.1-work3-loadlib/src/lib/Makefile 2004-12-07 08:11:48.998262048 +0100
@@ -25,3 +25,6 @@
rm -f $(SRCS)
+# Simplified dependencies
diff -ur lua-5.1-work3/include/lua.h lua-5.1-work3-loadlib/include/lua.h
--- lua-5.1-work3/include/lua.h 2004-12-07 02:00:32.000000000 +0100
+++ lua-5.1-work3-loadlib/include/lua.h 2004-12-07 08:08:01.229888104 +0100
@@ -17,6 +17,7 @@
+#define LUA_VERSION_NUM 0x050100L
#define LUA_VERSION "Lua 5.1 (work3)"
#define LUA_COPYRIGHT "Copyright (C) 1994-2004 Tecgraf, PUC-Rio"
#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
diff -ur lua-5.1-work3/include/luaconf.h lua-5.1-work3-loadlib/include/luaconf.h
--- lua-5.1-work3/include/luaconf.h 2004-12-06 18:53:42.000000000 +0100
+++ lua-5.1-work3-loadlib/include/luaconf.h 2004-12-07 08:14:56.763717360 +0100
@@ -31,10 +31,17 @@
/* default path */
#define LUA_PATH_DEFAULT \
+ "?.lua;C:\\Program Files\\Lua51\\lua\\?.lua;C:\\Program Files\\Lua51\\lua\\?\\init.lua"
#define LUA_CPATH_DEFAULT \
+ "?.dll;C:\\Program Files\\Lua51\\dll\\?.dll"
+#define LUA_PATH_DEFAULT \
+#define LUA_CPATH_DEFAULT \
@@ -306,7 +313,11 @@
/* directory separator (for submodules) */
+#define LUA_DIRSEP "\\"
#define LUA_DIRSEP "/"
/* separator of templates in a path */
#define LUA_PATH_SEP ';'
@@ -332,12 +343,14 @@
** Configuration for loadlib
-#if defined(__linux) || defined(sun) || defined(sgi) || defined(BSD)
#elif defined(__APPLE__) && defined(__MACH__)
@@ -350,7 +363,5 @@
/* Local configuration */
-#define USE_TMPNAME 1
diff -ur lua-5.1-work3/src/lib/loadlib.c lua-5.1-work3-loadlib/src/lib/loadlib.c
--- lua-5.1-work3/src/lib/loadlib.c 2004-11-19 16:52:12.000000000 +0100
+++ lua-5.1-work3-loadlib/src/lib/loadlib.c 2004-12-07 07:49:43.613751120 +0100
@@ -267,7 +267,7 @@
luaL_error(L, "global _CPATH must be a string");
fname = luaL_searchpath(L, fname, path);
if (fname == NULL) return path; /* library not found in this path */
- funcname = luaL_gsub(L, name, ".", "");
+ funcname = luaL_gsub(L, name, ".", "_");
funcname = lua_pushfstring(L, "%s%s", LUA_POF, funcname);
if (loadlib(L, fname, funcname) != 0)
luaL_error(L, "error loading package `%s' (%s)", name, lua_tostring(L, -1));