Browse Source

Properly export love modules to lua, package.loaded is correct now

Bart van Strien 13 years ago
parent
commit
e0b420c988

+ 4 - 3
src/common/runtime.cpp

@@ -187,10 +187,11 @@ namespace love
 			for (const lua_CFunction * t = m.types; *t != 0; t++)
 				(*t)(L);
 
-		lua_setfield(L, -2, m.name); // love.graphics = table
-		lua_pop(L, 1); // love
+		lua_pushvalue(L, -1);
+		lua_setfield(L, -3, m.name); // love.graphics = table
+		lua_remove(L, -2); // love
 
-		return 0;
+		return 1;
 	}
 
 	int luax_preload(lua_State * L, lua_CFunction f, const char * name)

+ 1 - 3
src/love.cpp

@@ -125,8 +125,6 @@ extern "C" LOVE_EXPORT int luaopen_love(lua_State * L)
 
 	lua_setfield(L, -2, "_version_compat");
 
-	lua_pop(L, 1); // love
-
 #ifdef LOVE_BUILD_STANDALONE
 
 	// Preload module loaders.
@@ -139,7 +137,7 @@ extern "C" LOVE_EXPORT int luaopen_love(lua_State * L)
 
 #endif // LOVE_BUILD_STANDALONE
 
-	return 0;
+	return 1;
 }
 
 #ifdef LOVE_LEGENDARY_UTF8_ARGV_HACK

+ 2 - 2
src/modules/audio/wrap_Audio.cpp

@@ -327,12 +327,12 @@ namespace audio
 		w.functions = functions;
 		w.types = types;
 
-		luax_register_module(L, w);
+		int n = luax_register_module(L, w);
 
 		if (luaL_loadbuffer(L, (const char *)audio_lua, sizeof(audio_lua), "audio.lua") == 0)
 			lua_call(L, 0, 0);
 
-		return 0;
+		return n;
 	}
 
 } // audio

+ 2 - 2
src/modules/graphics/opengl/wrap_Graphics.cpp

@@ -1300,12 +1300,12 @@ namespace opengl
 		w.functions = functions;
 		w.types = types;
 
-		luax_register_module(L, w);
+		int n = luax_register_module(L, w);
 
 		if (luaL_loadbuffer(L, (const char *)graphics_lua, sizeof(graphics_lua), "graphics.lua") == 0)
 			lua_call(L, 0, 0);
 
-		return 0;
+		return n;
 	}
 
 } // opengl