** Find or create a module table with a given name. The function ** first looks at the LOADED table and, if that fails, try a ** global variable with that name. In any case, leaves on the stack ** the module table. */
| 895 | ** the module table. |
| 896 | */ |
| 897 | LUALIB_API void luaL_pushmodule (lua_State *L, const char *modname, |
| 898 | int sizehint) { |
| 899 | luaL_findtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE, 1); |
| 900 | if (lua_getfield(L, -1, modname) != LUA_TTABLE) { /* no LOADED[modname]? */ |
| 901 | lua_pop(L, 1); /* remove previous result */ |
| 902 | /* try global variable (and create one if it does not exist) */ |
| 903 | lua_pushglobaltable(L); |
| 904 | if (luaL_findtable(L, 0, modname, sizehint) != NULL) |
| 905 | luaL_error(L, "name conflict for module '%s'", modname); |
| 906 | lua_pushvalue(L, -1); |
| 907 | lua_setfield(L, -3, modname); /* LOADED[modname] = new table */ |
| 908 | } |
| 909 | lua_remove(L, -2); /* remove LOADED table */ |
| 910 | } |
| 911 | |
| 912 | |
| 913 | LUALIB_API void luaL_openlib (lua_State *L, const char *libname, |
no test coverage detected