aboutsummaryrefslogtreecommitdiff
path: root/src/lib_package.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lib_package.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/lib_package.c b/src/lib_package.c
index b6917121..752b23b4 100644
--- a/src/lib_package.c
+++ b/src/lib_package.c
@@ -425,7 +425,7 @@ static int lj_cf_package_loader_preload(lua_State *L)
425 425
426/* ------------------------------------------------------------------------ */ 426/* ------------------------------------------------------------------------ */
427 427
428#define sentinel ((void *)0x4004) 428#define KEY_SENTINEL (U64x(80000000,00000000)|'s')
429 429
430static int lj_cf_package_require(lua_State *L) 430static int lj_cf_package_require(lua_State *L)
431{ 431{
@@ -435,7 +435,7 @@ static int lj_cf_package_require(lua_State *L)
435 lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); 435 lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
436 lua_getfield(L, 2, name); 436 lua_getfield(L, 2, name);
437 if (lua_toboolean(L, -1)) { /* is it there? */ 437 if (lua_toboolean(L, -1)) { /* is it there? */
438 if (lua_touserdata(L, -1) == sentinel) /* check loops */ 438 if ((L->top-1)->u64 == KEY_SENTINEL) /* check loops */
439 luaL_error(L, "loop or previous error loading module " LUA_QS, name); 439 luaL_error(L, "loop or previous error loading module " LUA_QS, name);
440 return 1; /* package is already loaded */ 440 return 1; /* package is already loaded */
441 } 441 }
@@ -458,14 +458,14 @@ static int lj_cf_package_require(lua_State *L)
458 else 458 else
459 lua_pop(L, 1); 459 lua_pop(L, 1);
460 } 460 }
461 lua_pushlightuserdata(L, sentinel); 461 (L->top++)->u64 = KEY_SENTINEL;
462 lua_setfield(L, 2, name); /* _LOADED[name] = sentinel */ 462 lua_setfield(L, 2, name); /* _LOADED[name] = sentinel */
463 lua_pushstring(L, name); /* pass name as argument to module */ 463 lua_pushstring(L, name); /* pass name as argument to module */
464 lua_call(L, 1, 1); /* run loaded module */ 464 lua_call(L, 1, 1); /* run loaded module */
465 if (!lua_isnil(L, -1)) /* non-nil return? */ 465 if (!lua_isnil(L, -1)) /* non-nil return? */
466 lua_setfield(L, 2, name); /* _LOADED[name] = returned value */ 466 lua_setfield(L, 2, name); /* _LOADED[name] = returned value */
467 lua_getfield(L, 2, name); 467 lua_getfield(L, 2, name);
468 if (lua_touserdata(L, -1) == sentinel) { /* module did not set a value? */ 468 if ((L->top-1)->u64 == KEY_SENTINEL) { /* module did not set a value? */
469 lua_pushboolean(L, 1); /* use true as result */ 469 lua_pushboolean(L, 1); /* use true as result */
470 lua_pushvalue(L, -1); /* extra copy to be returned */ 470 lua_pushvalue(L, -1); /* extra copy to be returned */
471 lua_setfield(L, 2, name); /* _LOADED[name] = true */ 471 lua_setfield(L, 2, name); /* _LOADED[name] = true */