MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / luaI_openlib

Function luaI_openlib

other_src/lua/src/lauxlib.cpp:267–293  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

265
266
267LUALIB_API void luaI_openlib (lua_State *L, const char *libname,
268 const luaL_Reg *l, int nup) {
269 if (libname) {
270 int size = libsize(l);
271 /* check whether lib already exists */
272 luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1);
273 lua_getfield(L, -1, libname); /* get _LOADED[libname] */
274 if (!lua_istable(L, -1)) { /* not found? */
275 lua_pop(L, 1); /* remove previous result */
276 /* try global variable (and create one if it does not exist) */
277 if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, size) != NULL)
278 luaL_error(L, "name conflict for module " LUA_QS, libname);
279 lua_pushvalue(L, -1);
280 lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */
281 }
282 lua_remove(L, -2); /* remove _LOADED table */
283 lua_insert(L, -(nup+1)); /* move library table to below upvalues */
284 }
285 for (; l->name; l++) {
286 int i;
287 for (i=0; i<nup; i++) /* copy upvalues to the top */
288 lua_pushvalue(L, -nup);
289 lua_pushcclosure(L, l->func, nup);
290 lua_setfield(L, -(nup+2), l->name);
291 }
292 lua_pop(L, nup); /* remove upvalues */
293}
294
295
296

Callers 1

void (luaL_register)Function · 0.70

Calls 9

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

Tested by

no test coverage detected