love.filesystem is now loaded by default in threads (see issue #1040.)

This commit is contained in:
Alex Szpakowski
2015-05-01 21:20:23 -03:00
parent 34bf847913
commit eee1fbac79
4 changed files with 42 additions and 11 deletions
+20 -6
View File
@@ -25,7 +25,6 @@
#ifdef LOVE_BUILD_STANDALONE
extern "C" int luaopen_love(lua_State * L);
#endif // LOVE_BUILD_STANDALONE
extern "C" int luaopen_love_thread(lua_State *L);
namespace love
{
@@ -34,7 +33,7 @@ namespace thread
LuaThread::LuaThread(const std::string &name, love::Data *code)
: code(code)
, name(name)
, args(0)
, args(nullptr)
, nargs(0)
{
threadName = name;
@@ -52,13 +51,25 @@ void LuaThread::threadFunction()
{
this->retain();
error.clear();
lua_State *L = luaL_newstate();
luaL_openlibs(L);
#ifdef LOVE_BUILD_STANDALONE
love::luax_preload(L, luaopen_love, "love");
luaopen_love(L);
luax_preload(L, luaopen_love, "love");
luax_require(L, "love");
lua_pop(L, 1);
#endif // LOVE_BUILD_STANDALONE
luaopen_love_thread(L);
luax_require(L, "love.thread");
lua_pop(L, 1);
// We load love.filesystem by default, since require still exists without it
// but won't load files from the proper paths. love.filesystem also must be
// loaded before using any love function that can take a filepath argument.
luax_require(L, "love.filesystem");
lua_pop(L, 1);
if (luaL_loadbuffer(L, (const char *) code->getData(), code->getSize(), name.c_str()) != 0)
error = luax_tostring(L, -1);
else
@@ -72,14 +83,17 @@ void LuaThread::threadFunction()
// Set both args and nargs to nil, prevents the deconstructor from
// accessing it again.
nargs = 0;
args = 0;
args = nullptr;
if (lua_pcall(L, pushedargs, 0, 0) != 0)
error = luax_tostring(L, -1);
}
lua_close(L);
if (!error.empty())
onError();
this->release();
}