From 217552b5ff40db88ac563a44d545b7cd7f06f4d2 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Tue, 1 Aug 2017 18:35:35 -0300 Subject: [PATCH] love.graphics.newShader can accept File and FileData arguments (resolves issue #1308). --HG-- branch : minor --- src/modules/graphics/wrap_Graphics.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/modules/graphics/wrap_Graphics.cpp b/src/modules/graphics/wrap_Graphics.cpp index 489a7925f..5ea26ee5b 100644 --- a/src/modules/graphics/wrap_Graphics.cpp +++ b/src/modules/graphics/wrap_Graphics.cpp @@ -1189,22 +1189,36 @@ int w_newCanvas(lua_State *L) static int w_getShaderSource(lua_State *L, int startidx, bool gles, Shader::ShaderSource &source) { + using namespace love::filesystem; + luax_checkgraphicscreated(L); - auto fs = Module::getInstance(Module::M_FILESYSTEM); + auto fs = Module::getInstance(Module::M_FILESYSTEM); // read any filepath arguments for (int i = startidx; i < startidx + 2; i++) { if (!lua_isstring(L, i)) + { + if (luax_cangetfiledata(L, i)) + { + FileData *fd = luax_getfiledata(L, i); + + lua_pushlstring(L, (const char *) fd->getData(), fd->getSize()); + fd->release(); + + lua_replace(L, i); + } + continue; + } size_t slen = 0; const char *str = lua_tolstring(L, i, &slen); if (fs != nullptr && fs->isFile(str)) { - filesystem::FileData *fd = nullptr; + FileData *fd = nullptr; luax_catchexcept(L, [&](){ fd = fs->read(str); }); lua_pushlstring(L, (const char *) fd->getData(), fd->getSize());