diff -urN lua-5.0-beta/config lua-5.0-beta-loadmodule/config
--- lua-5.0-beta/config	Thu Sep  5 05:33:00 2002
+++ lua-5.0-beta-loadmodule/config	Wed Dec 18 21:18:10 2002
@@ -73,6 +73,14 @@
 #USERCONF=-DLUA_USERCONFIG='"$(LUA)/etc/config.c"' -DUSE_READLINE -DUSE_LOADLIB
 #EXTRA_LIBS= -lm -lreadline -ldl # -lhistory -lcurses -lncurses
 
+# loadmodule patch
+# on linux:
+USERCONF=-DLUA_USERCONFIG='"$(LUA)/etc/config.c"' -DUSE_LOADMODULE -DDLFCN
+EXTRA_LIBS= -lm -ldl
+# on win32 (mingw):
+#USERCONF=-D__NO_ISOCEXT -DLUA_USERCONFIG='"$(LUA)/etc/config.c"' -DUSE_LOADMODULE -DWIN32
+
+
 # ------------------------------------------------------------------ librarian
 
 # This should work in all Unix systems.
@@ -83,6 +91,9 @@
 RANLIB= ranlib
 #RANLIB= ar s
 #RANLIB= true
+
+DLLWRAP=dllwrap.exe
+DLLWRAP_OPTS= --no-export-all-symbols --add-stdcall-alias
 
 # ------------------------------------------------------------------ stripper
 
diff -urN lua-5.0-beta/etc/config.c lua-5.0-beta-loadmodule/etc/config.c
--- lua-5.0-beta/etc/config.c	Thu Oct 31 04:33:11 2002
+++ lua-5.0-beta-loadmodule/etc/config.c	Wed Dec 18 18:52:18 2002
@@ -21,3 +21,6 @@
 #include "readline.c"
 #endif
 
+#ifdef USE_LOADMODULE
+#include "loadmodule.c"
+#endif
diff -urN lua-5.0-beta/etc/loadmodule.c lua-5.0-beta-loadmodule/etc/loadmodule.c
--- lua-5.0-beta/etc/loadmodule.c	Thu Jan  1 01:00:00 1970
+++ lua-5.0-beta-loadmodule/etc/loadmodule.c	Wed Dec 18 21:13:47 2002
@@ -0,0 +1,270 @@
+/* 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.  
+  
+   ?? Nov 2002 - castanyo@yahoo.es
+   
+   * Added return values in loadmodule.
+   
+   * Check version ignores revision number.
+
+   18 Dic 2002 - castanyo@yahoo.es
+   
+   * Updated for lua-5.0
+*/
+
+#define LUA_EXTRALIBS	{"loadmodule", register_loadmodule},
+
+#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()      "Unknown error.\n"
+#define LL_LIB_PREFIX      "lua"
+#define LL_LIB_SUFIX       ".dll"
+#define LL_INVALIDLIB      NULL
+
+#else
+
+#error "dynamic linking not supported in this platform. Make sure DLFCN or WIN32 are defined."
+
+#endif
+
+
+#define LL_NAMESPACE	"module"
+#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;
+
+
+
+/* compare the lua version ignoring the patch or revision number */
+static int check_version( const char * ver ) {
+  int i, p;
+  i = p = 0;
+  while( ver[i] && LUA_VERSION[i] && p<2 ) {
+    if( ver[i] != LUA_VERSION[i] ) return 0;
+    else if( ver[i] == '.' ) p++;
+    i++;
+  }
+  return 1;
+}
+
+
+/* this what the 'use' function does */
+static int ll_loadlib (lua_State *L) {
+
+  /* check parameter type */
+  luaL_checkstring (L, -1);
+
+  /* see if this lib is already loaded */
+  lua_pushstring (L, LL_LIBTABLE);
+  lua_gettable (L, LUA_GLOBALSINDEX);  /* get lib table */
+  lua_pushvalue (L, -2);               /* duplicate lib name */
+  lua_rawget (L, -2);                  /* get lib from lib table */
+  lua_getmetatable (L, -1);
+
+  /* compare libtable and metatable */
+  if (lua_getmetatable (L, -1) && lua_equal (L, -1, -3)) {
+    lua_settop (L, -4);                /* leave only libname on the stack */
+    lua_pushboolean (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 and metatable, leave: libname, libtable */
+    lua_pop (L, 1);
+
+    libname = lua_tostring(L, -2);
+    
+	lua_pushstring (L, LL_LIBPATH);
+    lua_gettable (L, LUA_GLOBALSINDEX);         /* 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) {
+      lua_pop (L, 1);              /* pop libtable */
+      lua_pushboolean (L, 0);
+	  lua_pushfstring (L, "cannot load module '%s':\n%s", libname, LL_ERRORLIB() );
+	  lua_remove (L, -3);          /* remove libname */
+    }
+    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 ) {
+        LL_UNLOADLIB (handle);
+        lua_pop (L, 1);              /* pop libtable */
+        lua_pushboolean (L, 0);
+		lua_pushfstring (L, "invalid module '%s':\n%s", libname, LL_ERRORLIB() );
+		lua_remove (L, -3);          /* remove libname */
+		return 2;
+      }
+
+      /* check lua version */
+      if( check_version( (*libver)() )==0 ) {
+        LL_UNLOADLIB (handle);
+        lua_pop (L, 1);              /* pop libtable */
+        lua_pushboolean (L, 0);
+        lua_pushfstring (L, "invalid lua version in module '%s'.", libname );
+		lua_remove (L, -3);          /* remove libname */
+		return 2;
+      }
+
+      /* call module entry point. */
+      (*regfunc)(L);
+
+      /* if suceed add the handle to the lib table */
+      lua_pushvalue (L, -2);                                    /* key: duplicate lib name */
+	  lib = (LLHandle *) lua_newuserdata (L, sizeof(LLHandle)); /* value: push lib */
+      lib->handle = handle;
+
+	  lua_pushvalue (L, -2);           /* dup libtable */
+      lua_setmetatable (L, -2);        /* set libtable as metatable and pop it */
+	  
+      lua_rawset (L, -3);              /* store lib in the lib table */
+
+      lua_pop (L, 1);                  /* pop lib libtable */
+
+      lua_pushnumber( L, 1 );          /* push true */
+	  lua_insert (L, -2);              /* swap */
+    }
+  }
+  return 2;     /* always return two values: boolean, string */  
+}
+
+
+/* not used by now */
+static int ll_closelib (lua_State *L) {
+  luaL_checkstring (L, -1);
+ 
+  lua_pushstring (L, LL_LIBTABLE);		/* libname, "__libs" */
+  lua_gettable (L, LUA_GLOBALSINDEX);	/* libname, libtable */
+
+  lua_insert (L, -2);					/* libtable, libname */
+  lua_pushnil (L);						/* libtable, libname, nil */
+  lua_settable (L, -3);					/* libtable */
+  lua_pop (L, 1);
+  return 0;
+}
+
+
+/* gc tag methods for the library */
+static 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 */
+static void ll_registerlibtable (lua_State *L) {
+  lua_pushstring (L, LL_LIBTABLE);
+  lua_newtable (L);
+  lua_settable (L, LUA_GLOBALSINDEX);
+}
+
+
+/* create a new tag for the libraries */
+static void ll_registertags (lua_State *L) {
+  lua_pushstring (L, LL_LIBTABLE);
+  lua_gettable (L, LUA_GLOBALSINDEX);
+  lua_pushstring (L, "__gc");
+  lua_pushcfunction (L, ll_libgc);
+  lua_settable (L, -3);
+  lua_pop (L, 1);
+}
+
+
+/* functions to export */
+static const struct luaL_reg ll_lib[] = {
+  {"load",    ll_loadlib},
+/*  {"unload",   ll_closelib}*/
+  {NULL, NULL}
+};
+
+
+/* open 'loadmodule' library */
+static int register_loadmodule (lua_State *L) {
+  /* don't load the library twice. */
+  lua_pushstring (L, LL_LIBTABLE);
+  lua_gettable (L, LUA_GLOBALSINDEX);
+  if (!lua_istable (L, -1)) {
+    luaL_openlib (L, LL_NAMESPACE, ll_lib, 0);
+    ll_registerlibtable (L);
+    ll_registertags (L);
+  }
+  lua_pop (L, 1);
+  return 0;
+}
+
+
