Browse Source

Switched global thread to love._curthread and made love.thread.getThread() return that

[email protected] 15 years ago
parent
commit
051f6f6eaa
2 changed files with 16 additions and 1 deletions
  1. 3 1
      src/modules/thread/sdl/Thread.cpp
  2. 13 0
      src/modules/thread/sdl/wrap_Thread.cpp

+ 3 - 1
src/modules/thread/sdl/Thread.cpp

@@ -44,7 +44,9 @@ namespace sdl
 		luaopen_love_thread(L);
 		lua_pushstring(L, comm->getName());
 		luax_convobj(L, lua_gettop(L), "thread", "getThread");
-		lua_setglobal(L, "thread");
+		lua_getglobal(L, "love");
+		lua_pushvalue(L, -2);
+		lua_setfield(L, -2, "_curthread");
 		if(luaL_dostring(L, comm->getCode()) == 1)
 		{
 			ThreadVariant *v = new ThreadVariant(lua_tostring(L, -1));

+ 13 - 0
src/modules/thread/sdl/wrap_Thread.cpp

@@ -276,6 +276,12 @@ namespace sdl
 
 	int w_getThread(lua_State *L)
 	{
+		if (lua_isnoneornil(L, 1))
+		{
+			lua_getglobal(L, "love");
+			lua_getfield(L, -1, "_curthread");
+			return 1;
+		}
 		std::string name = luaL_checkstring(L, 1);
 		Thread *t = instance->getThread(name);
 		if (t)
@@ -311,6 +317,13 @@ namespace sdl
 			try
 			{
 				instance = new ThreadModule();
+				lua_getglobal(L, "love");
+				Thread *curthread = instance->getThread("main");
+				curthread->lock();
+				curthread->retain();
+				curthread->unlock();
+				luax_newtype(L, "Thread", THREAD_THREAD_T, (void*)curthread);
+				lua_setfield(L, -2, "_curthread");
 			}
 			catch(Exception & e)
 			{