| 1035 | |
| 1036 | |
| 1037 | int 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 | //============================================================================// |
nothing calls this directly
no test coverage detected