Browse Source

Cleaned up love.graphics.newShader's wrapper code a bit.

--HG--
branch : minor
Alex Szpakowski 8 years ago
parent
commit
17cf7bba83

+ 1 - 1
src/modules/filesystem/physfs/File.cpp

@@ -190,7 +190,7 @@ bool File::write(const void *data, int64 size)
 	// Manually flush the buffer in BUFFER_LINE mode if we find a newline.
 	if (bufferMode == BUFFER_LINE && bufferSize > size)
 	{
-		if (memchr(data, '\n', (size_t) size) != NULL)
+		if (memchr(data, '\n', (size_t) size) != nullptr)
 			flush();
 	}
 

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

@@ -366,7 +366,7 @@ int w_read(lua_State *L)
 	const char *filename = luaL_checkstring(L, 1);
 	int64 len = (int64) luaL_optinteger(L, 2, File::ALL);
 
-	Data *data = 0;
+	Data *data = nullptr;
 	try
 	{
 		data = instance()->read(filename, len);
@@ -376,7 +376,7 @@ int w_read(lua_State *L)
 		return luax_ioError(L, "%s", e.what());
 	}
 
-	if (data == 0)
+	if (data == nullptr)
 		return luax_ioError(L, "File could not be read.");
 
 	// Push the string.
@@ -395,7 +395,7 @@ static int w_write_or_append(lua_State *L, File::Mode mode)
 {
 	const char *filename = luaL_checkstring(L, 1);
 
-	const char *input = 0;
+	const char *input = nullptr;
 	size_t len = 0;
 
 	if (luax_istype(L, 2, love::Data::type))

+ 13 - 14
src/modules/graphics/wrap_Graphics.cpp

@@ -24,6 +24,7 @@
 #include "image/ImageData.h"
 #include "image/Image.h"
 #include "font/Rasterizer.h"
+#include "filesystem/Filesystem.h"
 #include "filesystem/wrap_Filesystem.h"
 #include "video/VideoStream.h"
 #include "image/wrap_Image.h"
@@ -1190,34 +1191,32 @@ static int w_getShaderSource(lua_State *L, int startidx, bool gles, Shader::Shad
 {
 	luax_checkgraphicscreated(L);
 
+	auto fs = Module::getInstance<filesystem::Filesystem>(Module::M_FILESYSTEM);
+
 	// read any filepath arguments
 	for (int i = startidx; i < startidx + 2; i++)
 	{
 		if (!lua_isstring(L, i))
 			continue;
 
-		// call love.filesystem.isFile(arg_i)
-		luax_getfunction(L, "filesystem", "isFile");
-		lua_pushvalue(L, i);
-		lua_call(L, 1, 1);
-
-		bool isFile = luax_toboolean(L, -1);
-		lua_pop(L, 1);
+		size_t slen = 0;
+		const char *str = lua_tolstring(L, i, &slen);
 
-		if (isFile)
+		if (fs != nullptr && fs->isFile(str))
 		{
-			luax_getfunction(L, "filesystem", "read");
-			lua_pushvalue(L, i);
-			lua_call(L, 1, 1);
+			filesystem::FileData *fd = nullptr;
+			luax_catchexcept(L, [&](){ fd = fs->read(str); });
+
+			lua_pushlstring(L, (const char *) fd->getData(), fd->getSize());
+			fd->release();
+
 			lua_replace(L, i);
 		}
 		else
 		{
 			// Check if the argument looks like a filepath - we want a nicer
 			// error for misspelled filepath arguments.
-			size_t slen = 0;
-			const char *str = lua_tolstring(L, i, &slen);
-			if (slen > 0 && slen < 256 && !strchr(str, '\n'))
+			if (slen > 0 && slen < 64 && !strchr(str, '\n'))
 			{
 				const char *ext = strchr(str, '.');
 				if (ext != nullptr && !strchr(ext, ';') && !strchr(ext, ' '))