** 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. */
| 1004 | ** Leaves resulting module on the top. |
| 1005 | */ |
| 1006 | LUALIB_API void luaL_requiref (lua_State *L, const char *modname, |
| 1007 | lua_CFunction openf, int glb) { |
| 1008 | luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE); |
| 1009 | lua_getfield(L, -1, modname); /* LOADED[modname] */ |
| 1010 | if (!lua_toboolean(L, -1)) { /* package not already loaded? */ |
| 1011 | lua_pop(L, 1); /* remove field */ |
| 1012 | lua_pushcfunction(L, openf); |
| 1013 | lua_pushstring(L, modname); /* argument to open function */ |
| 1014 | lua_call(L, 1, 1); /* call 'openf' to open module */ |
| 1015 | lua_pushvalue(L, -1); /* make copy of module (call result) */ |
| 1016 | lua_setfield(L, -3, modname); /* LOADED[modname] = module */ |
| 1017 | } |
| 1018 | lua_remove(L, -2); /* remove LOADED table */ |
| 1019 | if (glb) { |
| 1020 | lua_pushvalue(L, -1); /* copy of module */ |
| 1021 | lua_setglobal(L, modname); /* _G[modname] = module */ |
| 1022 | } |
| 1023 | } |
| 1024 | |
| 1025 | |
| 1026 | LUALIB_API void luaL_addgsub (luaL_Buffer *b, const char *s, |
no test coverage detected