MCPcopy Create free account
hub / github.com/RomanKubiak/ctrlr / luaI_openlib

Function luaI_openlib

Source/Misc/lua/src/lua.c:10454–10480  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10452
10453
10454LUALIB_API void luaI_openlib (lua_State *L, const char *libname,
10455const luaL_Reg *l, int nup) {
10456if (libname) {
10457int size = libsize(l);
10458/* check whether lib already exists */
10459luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1);
10460lua_getfield(L, -1, libname); /* get _LOADED[libname] */
10461if (!lua_istable(L, -1)) { /* not found? */
10462lua_pop(L, 1); /* remove previous result */
10463/* try global variable (and create one if it does not exist) */
10464if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, size) != NULL)
10465luaL_error(L, "name conflict for module " LUA_QS, libname);
10466lua_pushvalue(L, -1);
10467lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */
10468}
10469lua_remove(L, -2); /* remove _LOADED table */
10470lua_insert(L, -(nup+1)); /* move library table to below upvalues */
10471}
10472for (; l->name; l++) {
10473int i;
10474for (i=0; i<nup; i++) /* copy upvalues to the top */
10475lua_pushvalue(L, -nup);
10476lua_pushcclosure(L, l->func, nup);
10477lua_setfield(L, -(nup+2), l->name);
10478}
10479lua_pop(L, nup); /* remove upvalues */
10480}
10481
10482
10483

Callers 1

void (luaL_register)Function · 0.85

Calls 9

libsizeFunction · 0.85
luaL_findtableFunction · 0.85
lua_getfieldFunction · 0.85
luaL_errorFunction · 0.85
lua_pushvalueFunction · 0.85
lua_setfieldFunction · 0.85
lua_removeFunction · 0.85
lua_insertFunction · 0.85
lua_pushcclosureFunction · 0.85

Tested by

no test coverage detected