** 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. */
| 2897 | ** the module table. |
| 2898 | */ |
| 2899 | LUALIB_API void luaL_pushmodule(lua_State *L, const char *modname, |
| 2900 | int sizehint) { |
| 2901 | luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1); /* get _LOADED table */ |
| 2902 | if (lua_getfield(L, -1, modname) != LUA_TTABLE) { /* no _LOADED[modname]? */ |
| 2903 | lua_pop(L, 1); /* remove previous result */ |
| 2904 | /* try global variable (and create one if it does not exist) */ |
| 2905 | lua_pushglobaltable(L); |
| 2906 | if (luaL_findtable(L, 0, modname, sizehint) != nullptr) |
| 2907 | luaL_error(L, "name conflict for module '%s'", modname); |
| 2908 | lua_pushvalue(L, -1); |
| 2909 | lua_setfield(L, -3, modname); /* _LOADED[modname] = new table */ |
| 2910 | } |
| 2911 | lua_remove(L, -2); /* remove _LOADED table */ |
| 2912 | } |
| 2913 | |
| 2914 | |
| 2915 | LUALIB_API void luaL_openlib(lua_State *L, const char *libname, |
no test coverage detected