diff -urN lua-4.0.1/Makefile lua-4.0.1-loadmodule/Makefile
--- lua-4.0.1/Makefile	2000-10-31 12:32:02.000000000 -0500
+++ lua-4.0.1-loadmodule/Makefile	2002-11-30 17:11:34.000000000 -0500
@@ -14,6 +14,8 @@
 	cd src/lib; $(MAKE) $@
 	cd src/lua; $(MAKE) $@
 
+clean: soclean dllclean
+
 # remove debug information from binaries
 strip:
 	strip bin/lua bin/luac
@@ -26,16 +28,44 @@
 	$(INSTALL_DATA) lib/lib* $(INSTALL_LIB)
 	$(INSTALL_DATA) doc/*.1 $(INSTALL_MAN)
 
+# shared libraries (for mingw)
+dll:
+#   Use the commented commands to create the .def files.
+#	DLLWRAP --output-def lib/liblua-$V.def --implib lib/liblua-$V.a src/*.o $(DLLWRAP_OPTS) -o lib/lua-$V.dll
+#	DLLWRAP --output-def lib/liblualib-$V.def --implib lib/liblualib-$V.a src/lib/*.o $(DLLWRAP_OPTS) -L$(LIB) -llua-$V -o lib/lualib-$V.dll
+	DLLWRAP --def lib/liblua-$V.def --implib lib/liblua-$V.a src/*.o $(DLLWRAP_OPTS) -o bin/lua-$V.dll
+	DLLWRAP --def lib/liblualib-$V.def --implib lib/liblualib-$V.a src/lib/*.o $(DLLWRAP_OPTS) -L$(LIB) -llua-$V -o bin/lualib-$V.dll
+
+dllbin:
+	rm -f bin/lua.exe
+	cd src/lua; $(MAKE)
+#	cd src/luac; $(MAKE)		-- this requieres additional exports
+
+# remove debug information from binaries
+dllstrip:
+	strip bin/lua-$V.dll bin/lualib-$V.dll bin/lua.exe bin/luac.exe
+
+# remove win32 dlls and binaries
+dllclean:
+	-rm bin/lua.exe bin/luac.exe bin/lua-$V.dll bin/lualib-$V.dll
+
 # shared libraries (for Linux)
-so:
-	ld -o lib/liblua.so.$V -shared src/*.o
-	ld -o lib/liblualib.so.$V -shared src/lib/*.o
-	cd lib; ln -s liblua.so.$V liblua.so; ln -s liblualib.so.$V liblualib.so
+so: all
+	ld -o lib/liblua-$V.so.$V -shared src/*.o
+	ld -o lib/liblualib-$V.so.$V -shared src/lib/*.o
+	cd lib; ln -s liblua-$V.so.$V liblua-$V.so; ln -s liblualib-$V.so.$V liblualib-$V.so
 
 # binaries using shared libraries
-sobin:
+sobin: so
 	rm -f bin/lua bin/luac
 	cd src/lua; $(MAKE)
 	cd src/luac; $(MAKE)
 
+# remove debug info from shared libraries
+sostrip:
+	strip lib/*.so
+
+soclean:
+	-rm lib/liblua-$V.so lib/liblualib-$V.so lib/liblua-$V.so.$V lib/liblualib-$V.so.$V
+
 # (end of Makefile)
diff -urN lua-4.0.1/config lua-4.0.1-loadmodule/config
--- lua-4.0.1/config	2000-11-06 15:28:20.000000000 -0500
+++ lua-4.0.1-loadmodule/config	2002-11-30 17:11:34.000000000 -0500
@@ -39,6 +39,11 @@
 #CC= cc
 #WARN= -Xc # -Dsparc
 
+# On MinGW you need this to build a dll.
+DLLWRAP=dllwrap.exe
+DLLWRAP_OPTS= --no-export-all-symbols --add-stdcall-alias
+
+
 # ------------------------------------------------------------------ C library
 
 # If your C library is not POSIX compliant, comment the following line.
@@ -57,6 +62,14 @@
 # or if you are using a modified interpreter that does not need them,
 # then comment the following line.
 EXTRA_LIBS= -lm
+# loadmodule patch: For Linux, added "-ldl" below:
+#EXTRA_LIBS= -lm -ldl
+
+# loadmodule patch: For Linux, added "-DDLFCN" below:
+#EXTRA_DEFS= -DDLFCN
+# Under windows, use this instead:
+EXTRA_DEFS= -D__NO_ISOCEXT -DWIN32
+
 
 # ------------------------------------------------------------------ librarian
 
@@ -91,7 +104,7 @@
 LIB= $(LUA)/lib
 
 INCS= -I$(INC) $(EXTRA_INCS)
-DEFS= $(COMPAT) $(NUMBER) $(OLD_ANSI) $(EXTRA_DEFS)
+DEFS= $(COMPAT) $(NUMBER) $(OLD_ANSI) $(EXTRA_DEFS) $(CUSTOM_DEFS)
 
 CFLAGS= -O2 $(WARN) $(INCS) $(DEFS)
 
diff -urN lua-4.0.1/etc/loadmodule.c lua-4.0.1-loadmodule/etc/loadmodule.c
--- lua-4.0.1/etc/loadmodule.c	1969-12-31 19:00:00.000000000 -0500
+++ lua-4.0.1-loadmodule/etc/loadmodule.c	2002-11-30 17:11:32.000000000 -0500
@@ -0,0 +1,247 @@
+/* loadmodule.c */
+
+/*
+   17 Nov 2002 - tu@tulrich.com
+
+   * Adapted from luselib.c.
+
+   * Changed to use "loadmodule" function name, instead of "use".  IMO
+   "use" is too generic a name for this functionality.
+
+   * renamed this file.  
+   
+   * Added return values in loadmodule.
+   
+   * Check version ignores revision number.
+   
+*/
+
+/* luselib.c - 30/01/2001 - Ignacio Castaño Aguado */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "lua.h"
+#include "lauxlib.h"
+
+
+#if DLFCN
+#include <dlfcn.h>
+
+typedef void *             LL_LIB;
+
+#define LL_LOADLIB(file)   dlopen(file, RTLD_LAZY)
+#define LL_UNLOADLIB(lib)  dlclose(lib)
+#define LL_BIND(lib,sym)   dlsym(lib,sym)
+#define LL_ERRORLIB()      dlerror()
+#define LL_LIB_PREFIX      "liblua"
+#define LL_LIB_SUFIX       ".so"
+#define LL_INVALIDLIB      NULL
+
+#elif WIN32
+#include <windows.h>
+
+typedef HMODULE			   LL_LIB;
+
+#define LL_LOADLIB(file)   LoadLibrary(file)
+#define LL_UNLOADLIB(lib)  FreeLibrary((HMODULE)lib)
+#define LL_BIND(lib,sym)   GetProcAddress(lib,sym)
+#define LL_ERRORLIB()      ""
+#define LL_LIB_PREFIX      "lua"
+#define LL_LIB_SUFIX       ".dll"
+#define LL_INVALIDLIB      NULL
+
+#else
+
+#error "dynamic linking not supported in this platform"
+
+#endif
+
+
+
+#define LL_LIBTABLE     "__libs"
+#define LL_LIBPATH      "LUA_LIBPATH"
+#define LL_LIBENTRY     "luaLM_import"
+#define LL_LIBVERSION   "luaLM_version"
+
+
+/* library struct */
+typedef struct LLHandle {
+  LL_LIB handle;
+  /* we could add here refcounts or debug info. */
+} LLHandle;
+
+
+
+/* tag for the libraries */
+int ll_libtag;
+
+
+
+/* this what the 'use' function does */
+int ll_loadlib (lua_State *L) {
+  int ltag;
+
+  /* check parameter type */
+  luaL_check_string (L, -1);
+
+  /* see if this lib is already loaded */
+  /* FIXME: use the registry instead? */
+  lua_getglobal (L, LL_LIBTABLE); /* get lib table */
+  lua_pushvalue (L, -2);          /* duplicate lib name */
+  lua_rawget (L, -2);             /* get lib from lib table */
+  ltag = lua_tag (L, -1);         /* get lib tag */
+
+  if (ltag==ll_libtag) {          /* already loaded */
+    lua_settop (L, -3);           /* leave libname on the stack */
+    lua_pushvalue (L, 1);         /* push true */
+    lua_insert (L, -2);           /* swap */
+  }
+  else {
+    const char * libname;
+    const char * path;
+    void * handle=LL_INVALIDLIB;
+    LLHandle * lib;
+
+    /* pop invalid lib value, leave: libname, libtable */
+    lua_pop (L, 1);
+
+    libname = lua_tostring(L, -2);
+      
+    lua_getglobal (L, LL_LIBPATH);              /* get lib path */
+    if (!lua_isstring (L, -1)) {                /* LL_LIBPATH not defined */
+      lua_pop(L, 1);                            /* pop invalid lib path value */
+	  lua_pushstring (L, getenv(LL_LIBPATH));   /* try environment variable */
+    }
+    path = lua_tostring (L, -1);
+	
+	/* stack: libname-3, libtable-2, libpath-1 */
+	
+    /* look first in custom path, to overwrite default search order */
+    if (path) {
+      char * fpath = (char *) malloc (strlen(path)+strlen(LL_LIB_PREFIX)+strlen(libname)+strlen(LL_LIB_SUFIX)+1);
+
+      /* create file path */
+      sprintf (fpath, "%s%s%s%s", path, LL_LIB_PREFIX, libname, LL_LIB_SUFIX);
+
+      handle = LL_LOADLIB (fpath);
+      free (fpath);
+    }
+
+	lua_pop (L, 1);                   /* pop libpath */
+	
+    if (handle==LL_INVALIDLIB) {
+      char * fname = (char *) malloc (strlen(LL_LIB_PREFIX)+strlen(libname)+strlen(LL_LIB_SUFIX)+1);
+
+      /* create file name */
+      sprintf( fname, "%s%s%s", LL_LIB_PREFIX, libname, LL_LIB_SUFIX);
+
+      handle = LL_LOADLIB (fname);
+      free (fname);
+    }
+
+    if (handle==LL_INVALIDLIB) {
+      char error[512]; /* fixed allocation */
+      sprintf (error, "cannot load module '%s':\n%s", lua_tostring (L, -2), LL_ERRORLIB() );
+      lua_pop (L, 2);
+      lua_pushnil (L);
+      lua_pushstring (L, error);
+    }
+	else {
+
+      const char * (*libver)() = (const char *(*)(void)) LL_BIND (handle, LL_LIBVERSION);
+      void (*regfunc)(lua_State *L) = (void(*)(lua_State *)) LL_BIND (handle, LL_LIBENTRY);
+
+      /* check entrypoints */
+      if( !libver || !regfunc ) {
+        char error[512]; /* fixed allocation */
+        LL_UNLOADLIB (handle);
+        sprintf (error, "invalid module '%s':\n%s", lua_tostring (L, -2), LL_ERRORLIB() );
+        lua_pop (L, 2);
+        lua_pushnil (L);
+        lua_pushstring (L, error);
+        return 2;
+      }
+
+      /* check lua version */
+      if( strcmp((*libver)(), LUA_VERSION)!=0 ) {
+        char error[512]; /* fixed allocation */
+        LL_UNLOADLIB (handle);
+        sprintf (error, "invalid lua version in module '%s':\n%s", lua_tostring (L, -2), LL_ERRORLIB() );
+        lua_pop (L, 2);
+        lua_pushnil (L);
+        lua_pushstring (L, error);
+        return 2;
+      }
+	
+      /* call module entry point. */
+      (*regfunc)(L);
+
+      /* if suceed add the handle to the lib table */
+      lib = (LLHandle *) malloc(sizeof(LLHandle));
+      lib->handle = handle;
+      lua_pushvalue (L, -2);           /* key: duplicate lib name */
+      lua_pushuserdata (L, lib);       /* value: push lib */
+      lua_settag (L, ll_libtag);       /* asign tag */
+      lua_rawset (L, -3);              /* store lib in the lib table */
+
+      lua_pop (L, 2);                  /* pop lib name and libtable */
+
+      lua_pushnumber( L, 1 );          /* push true */
+      lua_pushstring( L, libname );    /* push library name */
+    }
+  }
+  return 2;     /* always return two values: boolean, string */  
+}
+
+
+/* not used by now */
+int ll_closelib (lua_State *L) {
+  /*LL_UNLOADLIB (handle);*/
+  return 0;
+}
+
+
+/* gc tag methods for the library */
+int ll_libgc (lua_State *L) {
+  LLHandle * lib = lua_touserdata(L, -1);
+  LL_UNLOADLIB (lib->handle);
+  free (lib);
+  lua_pop(L, 1);
+  return 0;
+}
+
+
+/* creates the table where libraries are stored */
+void ll_registerlibtable (lua_State *L) {
+  lua_newtable (L);
+  lua_setglobal (L, LL_LIBTABLE);
+}
+
+
+/* create a new tag for the libraries */
+void ll_registertags (lua_State *L) {
+  ll_libtag = lua_newtag(L);
+  lua_pushcfunction (L, ll_libgc);
+  lua_settagmethod (L, ll_libtag, "gc");
+}
+
+
+/* functions to export */
+static const struct luaL_reg ll_lib[] = {
+  {"loadmodule",    ll_loadlib},
+/*  {"forget",   ll_closelib}*/
+};
+
+
+/* open 'loadmodule' library */
+LUALIB_API void lua_loadmoduleopen (lua_State *L) {
+  /* don't load the library twice. FIXME: use the registry? */
+  lua_getglobal (L, LL_LIBTABLE);
+  if (!lua_istable (L, -1)) {
+    luaL_openl(L, ll_lib);
+    ll_registertags (L);
+    ll_registerlibtable (L);
+  }
+}
+
diff -urN lua-4.0.1/lib/liblua-4.0.def lua-4.0.1-loadmodule/lib/liblua-4.0.def
--- lua-4.0.1/lib/liblua-4.0.def	1969-12-31 19:00:00.000000000 -0500
+++ lua-4.0.1-loadmodule/lib/liblua-4.0.def	2002-11-30 17:11:32.000000000 -0500
@@ -0,0 +1,68 @@
+; c:\Devel\Dev-Cpp\bin\dlltool --base-file C:\DOCUME~1\ADMINI~1\CONFIG~1\Temp/cca03684.base --output-exp lua.4.0.exp --dllname lua.4.0.dll --output-def lib/liblua.def --no-export-all-symbols --add-stdcall-alias --exclude-symbol=DllMainCRTStartup@12 --def C:\DOCUME~1\ADMINI~1\CONFIG~1\Temp/cca03684.def --output-lib lib/libluadll.4.0.a
+EXPORTS
+	lua_pushnil @ 1 ; 
+	lua_close @ 2 ; 
+	lua_concat @ 3 ; 
+	lua_copytagmethods @ 4 ; 
+	lua_dobuffer @ 5 ; 
+	lua_dofile @ 6 ; 
+	lua_dostring @ 7 ; 
+	lua_equal @ 8 ; 
+	lua_error @ 9 ; 
+	lua_getgccount @ 10 ; 
+	lua_getgcthreshold @ 11 ; 
+	lua_getglobal @ 12 ; 
+	lua_getglobals @ 13 ; 
+	lua_getinfo @ 14 ; 
+	lua_getlocal @ 15 ; 
+	lua_getn @ 16 ; 
+	lua_getref @ 17 ; 
+	lua_getstack @ 18 ; 
+	lua_gettable @ 19 ; 
+	lua_gettagmethod @ 20 ; 
+	lua_gettop @ 21 ; 
+	lua_insert @ 22 ; 
+	lua_iscfunction @ 23 ; 
+	lua_isnumber @ 24 ; 
+	lua_isstring @ 25 ; 
+	lua_lessthan @ 26 ; 
+	lua_newtable @ 27 ; 
+	lua_newtag @ 28 ; 
+	lua_newuserdata @ 29 ; 
+	lua_next @ 30 ; 
+	lua_open @ 31 ; 
+	lua_pushcclosure @ 32 ; 
+	lua_pushlstring @ 33 ; 
+	lua_call @ 34 ; 
+	lua_pushnumber @ 35 ; 
+	lua_pushstring @ 36 ; 
+	lua_pushusertag @ 37 ; 
+	lua_pushvalue @ 38 ; 
+	lua_rawcall @ 39 ; 
+	lua_rawget @ 40 ; 
+	lua_rawgeti @ 41 ; 
+	lua_rawset @ 42 ; 
+	lua_rawseti @ 43 ; 
+	lua_ref @ 44 ; 
+	lua_remove @ 45 ; 
+	lua_setcallhook @ 46 ; 
+	lua_setgcthreshold @ 47 ; 
+	lua_setglobal @ 48 ; 
+	lua_setglobals @ 49 ; 
+	lua_setlinehook @ 50 ; 
+	lua_setlocal @ 51 ; 
+	lua_settable @ 52 ; 
+	lua_settag @ 53 ; 
+	lua_settagmethod @ 54 ; 
+	lua_settop @ 55 ; 
+	lua_stackspace @ 56 ; 
+	lua_strlen @ 57 ; 
+	lua_tag @ 58 ; 
+	lua_tocfunction @ 59 ; 
+	lua_tonumber @ 60 ; 
+	lua_topointer @ 61 ; 
+	lua_tostring @ 62 ; 
+	lua_touserdata @ 63 ; 
+	lua_type @ 64 ; 
+	lua_typename @ 65 ; 
+	lua_unref @ 66 ; 
diff -urN lua-4.0.1/lib/liblualib-4.0.def lua-4.0.1-loadmodule/lib/liblualib-4.0.def
--- lua-4.0.1/lib/liblualib-4.0.def	1969-12-31 19:00:00.000000000 -0500
+++ lua-4.0.1-loadmodule/lib/liblualib-4.0.def	2002-11-30 17:11:32.000000000 -0500
@@ -0,0 +1,24 @@
+; c:\Devel\Dev-Cpp\bin\dlltool --base-file C:\DOCUME~1\ADMINI~1\CONFIG~1\Temp/cca03692.base --output-exp lualib.4.0.exp --dllname lualib.4.0.dll --output-def lib/liblualib.def --no-export-all-symbols --add-stdcall-alias --exclude-symbol=DllMainCRTStartup@12 --def C:\DOCUME~1\ADMINI~1\CONFIG~1\Temp/cca03692.def --output-lib lib/liblualibdll.4.0.a
+EXPORTS
+	luaL_openlib @ 1 ; 
+	luaL_addstring @ 2 ; 
+	luaL_addvalue @ 3 ; 
+	luaL_argerror @ 4 ; 
+	luaL_buffinit @ 5 ; 
+	luaL_check_lstr @ 6 ; 
+	luaL_check_number @ 7 ; 
+	luaL_checkany @ 8 ; 
+	luaL_checkstack @ 9 ; 
+	luaL_checktype @ 10 ; 
+	luaL_findstring @ 11 ; 
+	luaL_addlstring @ 12 ; 
+	luaL_opt_lstr @ 13 ; 
+	luaL_opt_number @ 14 ; 
+	luaL_prepbuffer @ 15 ; 
+	luaL_pushresult @ 16 ; 
+	luaL_verror @ 17 ; 
+	lua_baselibopen @ 18 ; 
+	lua_dblibopen @ 19 ; 
+	lua_iolibopen @ 20 ; 
+	lua_mathlibopen @ 21 ; 
+	lua_strlibopen @ 22 ; 
diff -urN lua-4.0.1/modules/README lua-4.0.1-loadmodule/modules/README
--- lua-4.0.1/modules/README	1969-12-31 19:00:00.000000000 -0500
+++ lua-4.0.1-loadmodule/modules/README	2002-11-30 17:11:34.000000000 -0500
@@ -0,0 +1 @@
+Place your modules in this folder.
\ No newline at end of file
diff -urN lua-4.0.1/src/Makefile lua-4.0.1-loadmodule/src/Makefile
--- lua-4.0.1/src/Makefile	2000-09-18 21:06:10.000000000 -0400
+++ lua-4.0.1-loadmodule/src/Makefile	2002-11-30 17:11:32.000000000 -0500
@@ -63,7 +63,7 @@
 	lvm.h \
 	lzio.h
 
-T= $(LIB)/liblua.a
+T= $(LIB)/liblua-$V.a
 
 all: $T
 
diff -urN lua-4.0.1/src/lib/Makefile lua-4.0.1-loadmodule/src/lib/Makefile
--- lua-4.0.1/src/lib/Makefile	2000-09-19 22:13:52.000000000 -0400
+++ lua-4.0.1-loadmodule/src/lib/Makefile	2002-11-30 17:11:32.000000000 -0500
@@ -5,12 +5,12 @@
 include $(LUA)/config
 
 # actually only used in liolib.c
-EXTRA_DEFS= $(POPEN)
+#EXTRA_DEFS= $(POPEN)
 
 OBJS= lauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o lstrlib.o
 SRCS= lauxlib.c lbaselib.c ldblib.c liolib.c lmathlib.c lstrlib.c
 
-T= $(LIB)/liblualib.a
+T= $(LIB)/liblualib-$V.a
 
 all: $T
 
diff -urN lua-4.0.1/src/lua/Makefile lua-4.0.1-loadmodule/src/lua/Makefile
--- lua-4.0.1/src/lua/Makefile	2000-03-31 08:52:56.000000000 -0500
+++ lua-4.0.1-loadmodule/src/lua/Makefile	2002-11-30 17:11:32.000000000 -0500
@@ -4,22 +4,22 @@
 
 include $(LUA)/config
 
-EXTRA_DEFS= $(POSIX)
+EXTRA_DEFS+= $(POSIX)
 
-OBJS= lua.o
+OBJS= lua.o $(LUA)/etc/loadmodule.o
 SRCS= lua.c
 
 T= $(BIN)/lua
 
 all: $T
 
-$T: $(OBJS) $(LIB)/liblua.a $(LIB)/liblualib.a
-	$(CC) -o $@ $(OBJS) -L$(LIB) -llua -llualib $(EXTRA_LIBS)
+$T: $(OBJS) $(LIB)/liblua-$V.a $(LIB)/liblualib-$V.a
+	$(CC) -o $@ $(OBJS) -L$(LIB) -llua-$V -llualib-$V $(EXTRA_LIBS)
 
-$(LIB)/liblua.a:
+$(LIB)/liblua-$V.a:
 	cd ..; $(MAKE)
 
-$(LIB)/liblualib.a:
+$(LIB)/liblualib-$V.a:
 	cd ../lib; $(MAKE)
 
 clean:
diff -urN lua-4.0.1/src/lua/lua.c lua-4.0.1-loadmodule/src/lua/lua.c
--- lua-4.0.1/src/lua/lua.c	2000-10-20 12:36:32.000000000 -0400
+++ lua-4.0.1-loadmodule/src/lua/lua.c	2002-11-30 17:11:32.000000000 -0500
@@ -15,6 +15,7 @@
 #include "luadebug.h"
 #include "lualib.h"
 
+extern void lua_loadmoduleopen (lua_State *L);   /* loadmodule patch */
 
 static lua_State *L = NULL;
 
@@ -55,6 +56,7 @@
   lua_mathlibopen(L);
   lua_dblibopen(L);
   /* add your libraries here */
+  lua_loadmoduleopen(L);  /* loadmodule patch */
 }
 
 
diff -urN lua-4.0.1/src/luac/Makefile lua-4.0.1-loadmodule/src/luac/Makefile
--- lua-4.0.1/src/luac/Makefile	2000-09-18 21:05:32.000000000 -0400
+++ lua-4.0.1-loadmodule/src/luac/Makefile	2002-11-30 17:11:32.000000000 -0500
@@ -13,7 +13,7 @@
 all: $T
 
 $T: $(OBJS) $(LIB)/liblua.a
-	$(CC) -o $@ $(OBJS) -L$(LIB) -llua
+	$(CC) -o $@ $(OBJS) -L$(LIB) -llua-$V
 
 $(LIB)/liblua.a:
 	cd ..; $(MAKE)
