MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / Include

Method Include

src/lua/LuaVFS.cpp:266–307  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

264//============================================================================//
265
266int LuaVFS::Include(lua_State* L) {
267 lua_settop(L, 3);
268
269 const char* path = luaL_checkstring(L, 1);
270 std::string modes = luaL_optstring(L, 2, GetReadFilter(path, L));
271 modes = BzVFS::allowModes(modes, L2ES(L)->vfsModes->readAllowed);
272
273 std::string code;
274 if (!bzVFS.readFile(path, modes, code)) {
275 luaL_error(L, "file not found");
276 }
277
278 // compile the code
279 int error = luaL_loadbuffer(L, code.data(), code.size(), path);
280 if (error != 0) {
281 lua_error(L);
282 }
283 const int funcIndex = 4;
284
285 // setup the function's environment
286 if (lua_istable(L, 3)) {
287 lua_pushvalue(L, 3);
288 }
289 else if (lua_isnil(L, 3)) {
290 LuaUtils::PushCurrentFuncEnv(L, "Include");
291 }
292 else {
293 luaL_error(L, "bad fenv parameter");
294 }
295
296 if (lua_setfenv(L, -2) == 0) {
297 luaL_error(L, "Include: error with setfenv");
298 }
299
300 // execute the code
301 error = lua_pcall(L, 0, LUA_MULTRET, 0);
302 if (error != 0) {
303 lua_error(L);
304 }
305
306 return lua_gettop(L) - (funcIndex - 1);
307}
308
309
310//============================================================================//

Callers

nothing calls this directly

Calls 13

GetReadFilterFunction · 0.85
L2ESFunction · 0.85
lua_settopFunction · 0.50
luaL_errorFunction · 0.50
luaL_loadbufferFunction · 0.50
lua_errorFunction · 0.50
lua_pushvalueFunction · 0.50
lua_setfenvFunction · 0.50
lua_pcallFunction · 0.50
lua_gettopFunction · 0.50
readFileMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected