MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / luaI_openlib

Function luaI_openlib

deps/lua/src/lauxlib.c:242–268  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

240
241
242LUALIB_API void luaI_openlib (lua_State *L, const char *libname,
243 const luaL_Reg *l, int nup) {
244 if (libname) {
245 int size = libsize(l);
246 /* check whether lib already exists */
247 luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1);
248 lua_getfield(L, -1, libname); /* get _LOADED[libname] */
249 if (!lua_istable(L, -1)) { /* not found? */
250 lua_pop(L, 1); /* remove previous result */
251 /* try global variable (and create one if it does not exist) */
252 if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, size) != NULL)
253 luaL_error(L, "name conflict for module " LUA_QS, libname);
254 lua_pushvalue(L, -1);
255 lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */
256 }
257 lua_remove(L, -2); /* remove _LOADED table */
258 lua_insert(L, -(nup+1)); /* move library table to below upvalues */
259 }
260 for (; l->name; l++) {
261 int i;
262 for (i=0; i<nup; i++) /* copy upvalues to the top */
263 lua_pushvalue(L, -nup);
264 lua_pushcclosure(L, l->func, nup);
265 lua_setfield(L, -(nup+2), l->name);
266 }
267 lua_pop(L, nup); /* remove upvalues */
268}
269
270
271

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