Browse Source

Fix the Data-returning variant of love.filesystem.read/File:read to return the size that was read. Now it's consistent with the string-returning variant.

Alex Szpakowski 6 years ago
parent
commit
459d31db7e
2 changed files with 6 additions and 20 deletions
  1. 3 10
      src/modules/filesystem/wrap_File.cpp
  2. 3 10
      src/modules/filesystem/wrap_Filesystem.cpp

+ 3 - 10
src/modules/filesystem/wrap_File.cpp

@@ -132,21 +132,14 @@ int w_File_read(lua_State *L)
 		return luax_ioError(L, "%s", e.what());
 		return luax_ioError(L, "%s", e.what());
 	}
 	}
 
 
-	int nret = 0;
-
 	if (ctype == love::data::CONTAINER_DATA)
 	if (ctype == love::data::CONTAINER_DATA)
-	{
 		luax_pushtype(L, d.get());
 		luax_pushtype(L, d.get());
-		nret = 1;
-	}
 	else
 	else
-	{
 		lua_pushlstring(L, (const char *) d->getData(), d->getSize());
 		lua_pushlstring(L, (const char *) d->getData(), d->getSize());
-		lua_pushinteger(L, d->getSize());
-		nret = 2;
-	}
 
 
-	return nret;
+	lua_pushinteger(L, d->getSize());
+
+	return 2;
 }
 }
 
 
 int w_File_write(lua_State *L)
 int w_File_write(lua_State *L)

+ 3 - 10
src/modules/filesystem/wrap_Filesystem.cpp

@@ -488,24 +488,17 @@ int w_read(lua_State *L)
 	if (data == nullptr)
 	if (data == nullptr)
 		return luax_ioError(L, "File could not be read.");
 		return luax_ioError(L, "File could not be read.");
 
 
-	int nret = 0;
-
 	if (ctype == love::data::CONTAINER_DATA)
 	if (ctype == love::data::CONTAINER_DATA)
-	{
 		luax_pushtype(L, data);
 		luax_pushtype(L, data);
-		nret = 1;
-	}
 	else
 	else
-	{
 		lua_pushlstring(L, (const char *) data->getData(), data->getSize());
 		lua_pushlstring(L, (const char *) data->getData(), data->getSize());
-		lua_pushinteger(L, data->getSize());
-		nret = 2;
-	}
+
+	lua_pushinteger(L, data->getSize());
 
 
 	// Lua has a copy now, so we can free it.
 	// Lua has a copy now, so we can free it.
 	data->release();
 	data->release();
 
 
-	return nret;
+	return 2;
 }
 }
 
 
 static int w_write_or_append(lua_State *L, File::Mode mode)
 static int w_write_or_append(lua_State *L, File::Mode mode)