MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / ll_require

Function ll_require

modules/engine/lua/src/build.skr_lua.cpp:102–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100static const int sentinel_ = 0;
101#define sentinel ((void *)&sentinel_)
102static int ll_require (lua_State *L) {
103 const char *name = luaL_checkstring(L, 1);
104 lua_settop(L, 1); /* _LOADED table will be at index 2 */
105 lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
106 lua_getfield(L, 2, name);
107 if (lua_toboolean(L, -1)) { /* is it there? */
108 if (lua_touserdata(L, -1) == sentinel) /* check loops */
109 luaL_error(L, "loop or previous error loading module " LUA_QS, name);
110 return 1; /* package is already loaded */
111 }
112 skr_load_file(L);
113 lua_pushlightuserdata(L, sentinel);
114 lua_setfield(L, 2, name); /* _LOADED[name] = sentinel */
115 lua_pushstring(L, name); /* pass name as argument to module */
116 lua_call(L, 1, 1); /* run loaded module */
117 if (!lua_isnil(L, -1)) /* non-nil return? */
118 lua_setfield(L, 2, name); /* _LOADED[name] = returned value */
119 lua_getfield(L, 2, name);
120 if (lua_touserdata(L, -1) == sentinel) { /* module did not set a value? */
121 lua_pushboolean(L, 1); /* use true as result */
122 lua_pushvalue(L, -1); /* extra copy to be returned */
123 lua_setfield(L, 2, name); /* _LOADED[name] = true */
124 }
125 return 1;
126}
127
128static const luaL_Reg ll_funcs[] = {
129 {"require", ll_require},

Callers

nothing calls this directly

Calls 12

luaL_errorFunction · 0.85
skr_load_fileFunction · 0.85
lua_pushlightuserdataFunction · 0.85
lua_callFunction · 0.85
lua_settopFunction · 0.50
lua_getfieldFunction · 0.50
lua_tobooleanFunction · 0.50
lua_touserdataFunction · 0.50
lua_setfieldFunction · 0.50
lua_pushstringFunction · 0.50
lua_pushbooleanFunction · 0.50
lua_pushvalueFunction · 0.50

Tested by

no test coverage detected