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

Method ReadImageFile

src/lua/LuaCallOuts.cpp:1037–1063  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1035
1036
1037int LuaCallOuts::ReadImageFile(lua_State* L) {
1038 const char* path = luaL_checkstring(L, 1);
1039
1040 std::string modes = L2ES(L)->vfsModes->readDefault;
1041 bool infoOnly = false;
1042 if (!lua_israwstring(L, 2)) {
1043 infoOnly = lua_isboolean(L, 2) && lua_tobool(L, 2);
1044 }
1045 else {
1046 modes = lua_tostring(L, 2); // wanted
1047 modes = BzVFS::allowModes(modes, L2ES(L)->vfsModes->readAllowed);
1048 infoOnly = lua_isboolean(L, 3) && lua_tobool(L, 3);
1049 }
1050
1051 std::string data;
1052 if (!bzVFS.readFile(path, modes, data)) {
1053 return luaL_pushnil(L);
1054 }
1055
1056 std::istringstream iss(data);
1057 PNGImageFile image(&iss);
1058
1059 if (infoOnly) {
1060 return PushImageInfo(L, image);
1061 }
1062 return PushImageData(L, image);
1063}
1064
1065
1066//============================================================================//

Callers

nothing calls this directly

Calls 7

L2ESFunction · 0.85
lua_israwstringFunction · 0.85
lua_toboolFunction · 0.85
luaL_pushnilFunction · 0.85
PushImageInfoFunction · 0.85
PushImageDataFunction · 0.85
readFileMethod · 0.45

Tested by

no test coverage detected