misc/liblua/loadlib.c
changeset 3697 d5b30d6373fc
parent 2812 0a24853de796
child 10017 de822cd3df3a
equal deleted inserted replaced
3695:c11abf387a7d 3697:d5b30d6373fc
   500 /*
   500 /*
   501 ** {======================================================
   501 ** {======================================================
   502 ** 'module' function
   502 ** 'module' function
   503 ** =======================================================
   503 ** =======================================================
   504 */
   504 */
   505   
   505 
   506 
   506 
   507 static void setfenv (lua_State *L) {
   507 static void setfenv (lua_State *L) {
   508   lua_Debug ar;
   508   lua_Debug ar;
   509   if (lua_getstack(L, 1, &ar) == 0 ||
   509   if (lua_getstack(L, 1, &ar) == 0 ||
   510       lua_getinfo(L, "f", &ar) == 0 ||  /* get calling function */
   510       lua_getinfo(L, "f", &ar) == 0 ||  /* get calling function */
   630   luaL_newmetatable(L, "_LOADLIB");
   630   luaL_newmetatable(L, "_LOADLIB");
   631   lua_pushcfunction(L, gctm);
   631   lua_pushcfunction(L, gctm);
   632   lua_setfield(L, -2, "__gc");
   632   lua_setfield(L, -2, "__gc");
   633   /* create `package' table */
   633   /* create `package' table */
   634   luaL_register(L, LUA_LOADLIBNAME, pk_funcs);
   634   luaL_register(L, LUA_LOADLIBNAME, pk_funcs);
   635 #if defined(LUA_COMPAT_LOADLIB) 
   635 #if defined(LUA_COMPAT_LOADLIB)
   636   lua_getfield(L, -1, "loadlib");
   636   lua_getfield(L, -1, "loadlib");
   637   lua_setfield(L, LUA_GLOBALSINDEX, "loadlib");
   637   lua_setfield(L, LUA_GLOBALSINDEX, "loadlib");
   638 #endif
   638 #endif
   639   lua_pushvalue(L, -1);
   639   lua_pushvalue(L, -1);
   640   lua_replace(L, LUA_ENVIRONINDEX);
   640   lua_replace(L, LUA_ENVIRONINDEX);