MCPcopy Create free account
hub / github.com/ArduPilot/ardupilot / luaL_requiref

Function luaL_requiref

libraries/AP_Scripting/lua/src/lauxlib.c:976–993  ·  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

974** Leaves resulting module on the top.
975*/
976LUALIB_API void luaL_requiref (lua_State *L, const char *modname,
977 lua_CFunction openf, int glb) {
978 luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);
979 lua_getfield(L, -1, modname); /* LOADED[modname] */
980 if (!lua_toboolean(L, -1)) { /* package not already loaded? */
981 lua_pop(L, 1); /* remove field */
982 lua_pushcfunction(L, openf);
983 lua_pushstring(L, modname); /* argument to open function */
984 lua_call(L, 1, 1); /* call 'openf' to open module */
985 lua_pushvalue(L, -1); /* make copy of module (call result) */
986 lua_setfield(L, -3, modname); /* LOADED[modname] = module */
987 }
988 lua_remove(L, -2); /* remove LOADED table */
989 if (glb) {
990 lua_pushvalue(L, -1); /* copy of module */
991 lua_setglobal(L, modname); /* _G[modname] = module */
992 }
993}
994
995
996LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p,

Callers 1

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