summaryrefslogtreecommitdiff
path: root/src/loadlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/loadlib.c')
-rw-r--r--src/loadlib.c18
1 files changed, 4 insertions, 14 deletions
diff --git a/src/loadlib.c b/src/loadlib.c
index 42cfb869..3e5eaecf 100644
--- a/src/loadlib.c
+++ b/src/loadlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: loadlib.c,v 1.92 2010/10/29 14:35:09 roberto Exp $
+** $Id: loadlib.c,v 1.94 2010/11/10 20:00:04 roberto Exp $
** Dynamic library loader for Lua
** See Copyright Notice in lua.h
**
@@ -239,8 +239,7 @@ static void **ll_register (lua_State *L, const char *path) {
lua_pop(L, 1); /* remove result from gettable */
plib = (void **)lua_newuserdata(L, sizeof(const void *));
*plib = NULL;
- luaL_getmetatable(L, "_LOADLIB");
- lua_setmetatable(L, -2);
+ luaL_setmetatable(L, "_LOADLIB");
lua_pushfstring(L, "%s%s", LIBPREFIX, path);
lua_pushvalue(L, -2);
lua_settable(L, LUA_REGISTRYINDEX);
@@ -435,21 +434,14 @@ static int loader_preload (lua_State *L) {
}
-static const int sentinel_ = 0;
-#define sentinel ((void *)&sentinel_)
-
-
static int ll_require (lua_State *L) {
const char *name = luaL_checkstring(L, 1);
int i;
lua_settop(L, 1); /* _LOADED table will be at index 2 */
lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
lua_getfield(L, 2, name);
- if (lua_toboolean(L, -1)) { /* is it there? */
- if (lua_touserdata(L, -1) == sentinel) /* check loops */
- luaL_error(L, "loop or previous error loading module " LUA_QS, name);
+ if (lua_toboolean(L, -1)) /* is it there? */
return 1; /* package is already loaded */
- }
/* else must load it; iterate over available loaders */
lua_getfield(L, lua_upvalueindex(1), "loaders");
if (!lua_istable(L, -1))
@@ -469,14 +461,12 @@ static int ll_require (lua_State *L) {
else
lua_pop(L, 1);
}
- lua_pushlightuserdata(L, sentinel);
- lua_setfield(L, 2, name); /* _LOADED[name] = sentinel */
lua_pushstring(L, name); /* pass name as argument to module */
lua_call(L, 1, 1); /* run loaded module */
if (!lua_isnil(L, -1)) /* non-nil return? */
lua_setfield(L, 2, name); /* _LOADED[name] = returned value */
lua_getfield(L, 2, name);
- if (lua_touserdata(L, -1) == sentinel) { /* module did not set a value? */
+ if (lua_isnil(L, -1)) { /* module did not set a value? */
lua_pushboolean(L, 1); /* use true as result */
lua_pushvalue(L, -1); /* extra copy to be returned */
lua_setfield(L, 2, name); /* _LOADED[name] = true */