MCPcopy Create free account
hub / github.com/Achain-Dev/Achain / luaL_requiref

Function luaL_requiref

src/Chain/libraries/glua/lauxlib.cpp:2973–2990  ·  view source on GitHub ↗

** Stripped-down 'require': After checking "loaded" table, calls 'openf' ** to open a module, registers the result in 'package.loaded' table and, ** if 'glb' is true, also registers the result in the global table. ** Leaves resulting module on the top. */

Source from the content-addressed store, hash-verified

2971** Leaves resulting module on the top.
2972*/
2973LUALIB_API void luaL_requiref(lua_State *L, const char *modname,
2974 lua_CFunction openf, int glb) {
2975 luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED");
2976 lua_getfield(L, -1, modname); /* _LOADED[modname] */
2977 if (!lua_toboolean(L, -1)) { /* package not already loaded? */
2978 lua_pop(L, 1); /* remove field */
2979 lua_pushcfunction(L, openf);
2980 lua_pushstring(L, modname); /* argument to open function */
2981 lua_call(L, 1, 1); /* call 'openf' to open module */
2982 lua_pushvalue(L, -1); /* make copy of module (call result) */
2983 lua_setfield(L, -3, modname); /* _LOADED[modname] = module */
2984 }
2985 lua_remove(L, -2); /* remove _LOADED table */
2986 if (glb) {
2987 lua_pushvalue(L, -1); /* copy of module */
2988 lua_setglobal(L, modname); /* _G[modname] = module */
2989 }
2990}
2991
2992
2993LUALIB_API const char *luaL_gsub(lua_State *L, const char *s, const char *p,

Callers 2

register_moduleFunction · 0.85
luaL_openlibsFunction · 0.85

Calls 7

luaL_getsubtableFunction · 0.85
lua_getfieldFunction · 0.85
lua_tobooleanFunction · 0.85
lua_pushstringFunction · 0.85
lua_pushvalueFunction · 0.85
lua_setfieldFunction · 0.85
lua_setglobalFunction · 0.85

Tested by

no test coverage detected