MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / luaI_openlib

Function luaI_openlib

lua/lauxlib.c:290–316  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

288
289
290LUALIB_API void luaI_openlib (lua_State *L, const char *libname,
291 const luaL_Reg *l, int nup) {
292 if (libname) {
293 int size = libsize(l);
294 /* check whether lib already exists */
295 luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1);
296 lua_getfield(L, -1, libname); /* get _LOADED[libname] */
297 if (!lua_istable(L, -1)) { /* not found? */
298 lua_pop(L, 1); /* remove previous result */
299 /* try global variable (and create one if it does not exist) */
300 if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, size) != NULL)
301 luaL_error(L, "name conflict for module " LUA_QS, libname);
302 lua_pushvalue(L, -1);
303 lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */
304 }
305 lua_remove(L, -2); /* remove _LOADED table */
306 lua_insert(L, -(nup+1)); /* move library table to below upvalues */
307 }
308 for (; l->name; l++) {
309 int i;
310 for (i=0; i<nup; i++) /* copy upvalues to the top */
311 lua_pushvalue(L, -nup);
312 lua_pushcclosure(L, l->func, nup);
313 lua_setfield(L, -(nup+2), l->name);
314 }
315 lua_pop(L, nup); /* remove upvalues */
316}
317
318
319

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