| 557 | |
| 558 | |
| 559 | static int ll_module (lua_State *L) { |
| 560 | const char *modname = luaL_checkstring(L, 1); |
| 561 | int loaded = lua_gettop(L) + 1; /* index of _LOADED table */ |
| 562 | lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); |
| 563 | lua_getfield(L, loaded, modname); /* get _LOADED[modname] */ |
| 564 | if (!lua_istable(L, -1)) { /* not found? */ |
| 565 | lua_pop(L, 1); /* remove previous result */ |
| 566 | /* try global variable (and create one if it does not exist) */ |
| 567 | if (luaL_findtable(L, LUA_GLOBALSINDEX, modname, 1) != NULL) |
| 568 | return luaL_error(L, "name conflict for module " LUA_QS, modname); |
| 569 | lua_pushvalue(L, -1); |
| 570 | lua_setfield(L, loaded, modname); /* _LOADED[modname] = new table */ |
| 571 | } |
| 572 | /* check whether table already has a _NAME field */ |
| 573 | lua_getfield(L, -1, "_NAME"); |
| 574 | if (!lua_isnil(L, -1)) /* is table an initialized module? */ |
| 575 | lua_pop(L, 1); |
| 576 | else { /* no; initialize it */ |
| 577 | lua_pop(L, 1); |
| 578 | modinit(L, modname); |
| 579 | } |
| 580 | lua_pushvalue(L, -1); |
| 581 | setfenv(L); |
| 582 | dooptions(L, loaded - 1); |
| 583 | return 0; |
| 584 | } |
| 585 | |
| 586 | |
| 587 | static int ll_seeall (lua_State *L) { |
nothing calls this directly
no test coverage detected