Add some more changes and extensions from Lua 5.2.

Contributed by François Perrad.
This commit is contained in:
Mike Pall
2017-03-30 12:43:21 +02:00
parent dc320ca70f
commit de97b9d52b
5 changed files with 64 additions and 40 deletions

View File

@@ -489,29 +489,19 @@ static void modinit(lua_State *L, const char *modname)
static int lj_cf_package_module(lua_State *L)
{
const char *modname = luaL_checkstring(L, 1);
int loaded = lua_gettop(L) + 1; /* index of _LOADED table */
lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
lua_getfield(L, loaded, modname); /* get _LOADED[modname] */
if (!lua_istable(L, -1)) { /* not found? */
lua_pop(L, 1); /* remove previous result */
/* try global variable (and create one if it does not exist) */
if (luaL_findtable(L, LUA_GLOBALSINDEX, modname, 1) != NULL)
lj_err_callerv(L, LJ_ERR_BADMODN, modname);
lua_pushvalue(L, -1);
lua_setfield(L, loaded, modname); /* _LOADED[modname] = new table */
}
/* check whether table already has a _NAME field */
int lastarg = (int)(L->top - L->base);
luaL_pushmodule(L, modname, 1);
lua_getfield(L, -1, "_NAME");
if (!lua_isnil(L, -1)) { /* is table an initialized module? */
if (!lua_isnil(L, -1)) { /* Module already initialized? */
lua_pop(L, 1);
} else { /* no; initialize it */
} else {
lua_pop(L, 1);
modinit(L, modname);
}
lua_pushvalue(L, -1);
setfenv(L);
dooptions(L, loaded - 1);
return 0;
dooptions(L, lastarg);
return LJ_52;
}
static int lj_cf_package_seeall(lua_State *L)