Browse Source

Modules now reside in Lua and are treated (almost) like normal objects.
Also added a way of getting a pointer to abstract module instances internally.

rude 16 years ago
parent
commit
623e701549

+ 0 - 1
configure.in

@@ -22,7 +22,6 @@ AC_SEARCH_LIBS(
 	AC_MSG_ERROR([Can't LÖVE without Lua])
 	AC_MSG_ERROR([Can't LÖVE without Lua])
 )
 )
 AC_SEARCH_LIBS([ilInit], [IL], [], AC_MSG_ERROR([Can't LÖVE without DevIL]))
 AC_SEARCH_LIBS([ilInit], [IL], [], AC_MSG_ERROR([Can't LÖVE without DevIL]))
-AC_SEARCH_LIBS([iluInit], [ILU], [], AC_MSG_ERROR([Can't LÖVE without ILU]))
 AC_SEARCH_LIBS([mng_initialize], [mng], [], AC_MSG_ERROR([DevIL needs MNG]))
 AC_SEARCH_LIBS([mng_initialize], [mng], [], AC_MSG_ERROR([DevIL needs MNG]))
 AC_SEARCH_LIBS([TIFFOpen], [tiff], [], AC_MSG_ERROR([DevIL needs TIFF]))
 AC_SEARCH_LIBS([TIFFOpen], [tiff], [], AC_MSG_ERROR([DevIL needs TIFF]))
 AC_SEARCH_LIBS([FT_Load_Glyph], [freetype], [], AC_MSG_ERROR([Can't LÖVE without FreeType]))
 AC_SEARCH_LIBS([FT_Load_Glyph], [freetype], [], AC_MSG_ERROR([Can't LÖVE without FreeType]))

+ 2 - 3
src/common/Module.h

@@ -24,15 +24,14 @@
 // LOVE
 // LOVE
 #include "runtime.h"
 #include "runtime.h"
 #include "Exception.h"
 #include "Exception.h"
+#include "Object.h"
 
 
 namespace love
 namespace love
 {
 {
 	/**
 	/**
 	* Abstract superclass for all modules. 
 	* Abstract superclass for all modules. 
-	*
-	* @author Anders Ruud
 	**/
 	**/
-	class Module
+	class Module : public Object
 	{
 	{
 	public:
 	public:
 
 

+ 30 - 39
src/common/runtime.cpp

@@ -37,23 +37,12 @@ namespace love
 	**/
 	**/
 	static int w__gc(lua_State * L)
 	static int w__gc(lua_State * L)
 	{
 	{
-		UserData * u = (UserData *)lua_touserdata(L, 1);
+		Proxy * u = (Proxy *)lua_touserdata(L, 1);
 		Object * t = (Object *)u->data;
 		Object * t = (Object *)u->data;
 		t->release();
 		t->release();
 		return 0;
 		return 0;
 	}
 	}
 
 
-	/**
-	* Special garbage collector for Modules.
-	**/
-	static int w__Module_gc(lua_State * L)
-	{
-		UserData * u = (UserData *)lua_touserdata(L, 1);
-		Module * t = (Module *)u->data;
-		delete t;
-		return 0;
-	}
-
 	Reference * luax_refif(lua_State * L, int type)
 	Reference * luax_refif(lua_State * L, int type)
 	{
 	{
 		Reference * r = 0;
 		Reference * r = 0;
@@ -115,38 +104,36 @@ namespace love
 		return 0;
 		return 0;
 	}
 	}
 
 
-	int luax_register_gc(lua_State * L, Module * m)
+	int luax_register_module(lua_State * L, const WrappedModule & m)
 	{
 	{
-		luax_getregistry(L, REGISTRY_GC);
+		// Put a reference to the C++ module in Lua.
+		luax_getregistry(L, REGISTRY_MODULES);
 
 
-		UserData * u = (UserData *)lua_newuserdata(L, sizeof(UserData));
-		u->own = true;
-		u->data = m;
+		Proxy * p = (Proxy *)lua_newuserdata(L, sizeof(Proxy));
+		p->own = true;
+		p->data = m.module;
+		p->flags = m.flags;
 
 
-		luaL_newmetatable(L, m->getName());
-		lua_pushcfunction(L, w__Module_gc);
+		luaL_newmetatable(L, m.module->getName());
+		lua_pushvalue(L, -1);
+		lua_setfield(L, -2, "__index");
+		lua_pushcfunction(L, w__gc);
 		lua_setfield(L, -2, "__gc");
 		lua_setfield(L, -2, "__gc");
-		lua_setmetatable(L, -2);
-
-		lua_setfield(L, -2, m->getName());
 
 
-		lua_pop(L, 1); // Registry
-
-		return 0;
-	}
+		lua_setmetatable(L, -2);
+		lua_setfield(L, -2, m.name); // _modules[name] = proxy
+		lua_pop(L, 1);
 
 
-	int luax_register_module(lua_State * L, const luaL_Reg * fn, const lua_CFunction * types, const LuaConstant * constants, const char * name)
-	{
 		// Gets the love table.
 		// Gets the love table.
 		luax_insistglobal(L, "love");
 		luax_insistglobal(L, "love");
 
 
 		// Install constants.
 		// Install constants.
-		if(constants != 0)
+		if(m.constants != 0)
 		{
 		{
-			for(int i = 0; constants[i].name != 0; i++)
+			for(int i = 0; m.constants[i].name != 0; i++)
 			{
 			{
-				lua_pushinteger(L, constants[i].value);
-				lua_setfield(L, -2, constants[i].name);
+				lua_pushinteger(L, m.constants[i].value);
+				lua_setfield(L, -2, m.constants[i].name);
 			}
 			}
 		}
 		}
 
 
@@ -154,14 +141,14 @@ namespace love
 		lua_newtable(L);
 		lua_newtable(L);
 
 
 		// Register all the functions.
 		// Register all the functions.
-		luaL_register(L, 0, fn);
+		luaL_register(L, 0, m.functions);
 
 
 		// Register types.
 		// Register types.
-		if(types != 0)
-			for(const lua_CFunction * t = types; *t != 0; t++)
+		if(m.types != 0)
+			for(const lua_CFunction * t = m.types; *t != 0; t++)
 				(*t)(L);
 				(*t)(L);
 
 
-		lua_setfield(L, -2, name); // love.graphics = table
+		lua_setfield(L, -2, m.name); // love.graphics = table
 		lua_pop(L, 1); // love
 		lua_pop(L, 1); // love
 
 
 		return 0;
 		return 0;
@@ -189,7 +176,9 @@ namespace love
 		lua_pushcfunction(L, w__gc);
 		lua_pushcfunction(L, w__gc);
 		lua_setfield(L, -2, "__gc");
 		lua_setfield(L, -2, "__gc");
 
 
-		luaL_register(L, 0, f);
+		if(f != 0)
+			luaL_register(L, 0, f);
+
 		lua_pop(L, 1); // Pops metatable.
 		lua_pop(L, 1); // Pops metatable.
 		return 0;
 		return 0;
 	}
 	}
@@ -217,7 +206,7 @@ namespace love
 
 
 	void luax_newtype(lua_State * L, const char * name, bits flags, void * data, bool own)
 	void luax_newtype(lua_State * L, const char * name, bits flags, void * data, bool own)
 	{
 	{
-		UserData * u = (UserData *)lua_newuserdata(L, sizeof(UserData));
+		Proxy * u = (Proxy *)lua_newuserdata(L, sizeof(Proxy));
 
 
 		u->data = data;
 		u->data = data;
 		u->flags = flags;
 		u->flags = flags;
@@ -232,7 +221,7 @@ namespace love
 		if(lua_isuserdata(L, idx) == 0)
 		if(lua_isuserdata(L, idx) == 0)
 			return false;
 			return false;
 
 
-		return ((((UserData *)lua_touserdata(L, idx))->flags & type) == type);
+		return ((((Proxy *)lua_touserdata(L, idx))->flags & type) == type);
 	}
 	}
 
 
 	int luax_getfunction(lua_State * L, const char * mod, const char * fn)
 	int luax_getfunction(lua_State * L, const char * mod, const char * fn)
@@ -318,6 +307,8 @@ namespace love
 		{
 		{
 		case REGISTRY_GC:
 		case REGISTRY_GC:
 			return luax_insistlove(L, "_gc");
 			return luax_insistlove(L, "_gc");
+		case REGISTRY_MODULES:
+			return luax_insistlove(L, "_modules");
 		default:
 		default:
 			return luaL_error(L, "Attempted to use invalid registry.");
 			return luaL_error(L, "Attempted to use invalid registry.");
 		}
 		}

+ 62 - 25
src/common/runtime.h

@@ -44,31 +44,61 @@ namespace love
 	enum Registry
 	enum Registry
 	{
 	{
 		REGISTRY_GC = 1,
 		REGISTRY_GC = 1,
+		REGISTRY_MODULES,
 	};
 	};
 
 
 	/**
 	/**
 	* This structure wraps all Lua-exposed objects. It exists in the
 	* This structure wraps all Lua-exposed objects. It exists in the
-	* Lua state as a full UserData (so we can catch __gc "events"), 
-	* though the Object it refers to is light UserData in the sense 
+	* Lua state as a full userdata (so we can catch __gc "events"), 
+	* though the Object it refers to is light userdata in the sense 
 	* that it is not allocated by the Lua VM. 
 	* that it is not allocated by the Lua VM. 
 	**/
 	**/
-	struct UserData
+	struct Proxy
 	{
 	{
-		bits flags; // Holds type information (see types.h).
+		// Holds type information (see types.h).
+		bits flags; 
+		
+		// The light userdata.
 		void * data;
 		void * data;
-		bool own; // True if Lua should delete on GC.
+
+		// True if Lua should delete on GC.
+		bool own; 
 	};
 	};
 
 
 	
 	
 	/**
 	/**
 	* Used to store constants in arrays.
 	* Used to store constants in arrays.
 	**/
 	**/
-	struct LuaConstant
+	struct Constant
 	{
 	{
 		const char * name;
 		const char * name;
 		int value;
 		int value;
 	};
 	};
 
 
+	/**
+	* A Module with Lua wrapper functions and other data.
+	**/
+	struct WrappedModule
+	{
+		// The module containing the functions.
+		Module * module;
+
+		// The name for the table to put the functions in, without the 'love'-prefix.
+		const char * name;
+
+		// The type flags of this module.
+		love::bits flags;
+
+		// The functions of the module (last element {0,0}).
+		const luaL_Reg * functions;
+
+		// A list of functions which expose the types of the modules (last element 0).
+		const lua_CFunction * types;
+
+		// A list of constants (last element 0).
+		const Constant * constants;
+	};
+
 	/**
 	/**
 	* Returns a reference to the top stack element (-1) if the value
 	* Returns a reference to the top stack element (-1) if the value
 	* is of the specified type. If the value is incorrect, zero is returned.
 	* is of the specified type. If the value is incorrect, zero is returned.
@@ -134,22 +164,10 @@ namespace love
 	int luax_assert_function(lua_State * L, int idx);
 	int luax_assert_function(lua_State * L, int idx);
 
 
 	/**
 	/**
-	* Register a dummy UserData (full) for a module. This enables us to catch the
-	* call to __gc, and properly call the destructor on the Module in question.
-	* @param L The Lua state.
-	* @param module The Module to register the dummy UserData for.
-	**/
-	int luax_register_gc(lua_State * L, Module * module);
-
-	/**
-	* Register a module in the love table. The love table will created if it does not exist.
+	* Register a module in the love table. The love table will be created if it does not exist.
 	* @param L The Lua state.
 	* @param L The Lua state.
-	* @param f The functions of the module (last element {0,0}).
-	* @param t A list of functions which expose the types of the modules (last element 0).
-	* @param c A list of constants (last element 0).
-	* @param name The name for the table to put the functions in, without the 'love'-prefix.
 	**/
 	**/
-	int luax_register_module(lua_State * L, const luaL_Reg * f, const lua_CFunction * t, const LuaConstant * c, const char * name);
+	int luax_register_module(lua_State * L, const WrappedModule & m);
 	
 	
 	/**
 	/**
 	* Inserts a module with 'name' into the package.preloaded table.
 	* Inserts a module with 'name' into the package.preloaded table.
@@ -164,7 +182,7 @@ namespace love
 	* even from other modules.
 	* even from other modules.
 	* @param f The list of member functions for the type.
 	* @param f The list of member functions for the type.
 	**/
 	**/
-	int luax_register_type(lua_State * L, const char * tname, const luaL_Reg * f);
+	int luax_register_type(lua_State * L, const char * tname, const luaL_Reg * f = 0);
 
 
 	/**
 	/**
 	* Register a new searcher function for package.loaders. This can for instance enable
 	* Register a new searcher function for package.loaders. This can for instance enable
@@ -189,7 +207,7 @@ namespace love
 	* @param L The Lua state.
 	* @param L The Lua state.
 	* @param idx The index on the stack.
 	* @param idx The index on the stack.
 	* @param type The type to check for.
 	* @param type The type to check for.
-	* @return True if the value is UserData of the specified type, false otherwise.
+	* @return True if the value is Proxy of the specified type, false otherwise.
 	**/
 	**/
 	bool luax_istype(lua_State * L, int idx, love::bits type);
 	bool luax_istype(lua_State * L, int idx, love::bits type);
 	
 	
@@ -258,11 +276,11 @@ namespace love
 	template <typename T>
 	template <typename T>
 	T * luax_totype(lua_State * L, int idx, const char * name, love::bits type)
 	T * luax_totype(lua_State * L, int idx, const char * name, love::bits type)
 	{
 	{
-		return (T*)(((UserData *)lua_touserdata(L, idx))->data);
+		return (T*)(((Proxy *)lua_touserdata(L, idx))->data);
 	}
 	}
 
 
 	/**
 	/**
-	* Like luax_totype, but causes an error if the value at idx is not UserData, 
+	* Like luax_totype, but causes an error if the value at idx is not Proxy, 
 	* or is not the specified type.
 	* or is not the specified type.
 	* @param L The Lua state.
 	* @param L The Lua state.
 	* @param idx The index on the stack.
 	* @param idx The index on the stack.
@@ -275,7 +293,7 @@ namespace love
 		if(lua_isuserdata(L, idx) == 0)
 		if(lua_isuserdata(L, idx) == 0)
 			luaL_error(L, "Incorrect parameter type: expected userdata.");
 			luaL_error(L, "Incorrect parameter type: expected userdata.");
 
 
-		UserData * u = (UserData *)lua_touserdata(L, idx);
+		Proxy * u = (Proxy *)lua_touserdata(L, idx);
 
 
 		if((u->flags & type) != type)
 		if((u->flags & type) != type)
 			luaL_error(L, "Incorrect parameter type: expected %s", name);
 			luaL_error(L, "Incorrect parameter type: expected %s", name);
@@ -283,6 +301,25 @@ namespace love
 		return (T *)u->data;	
 		return (T *)u->data;	
 	}
 	}
 
 
+	template <typename T>
+	T * luax_getmodule(lua_State * L, const char * k, love::bits type)
+	{
+		luax_getregistry(L, REGISTRY_MODULES);
+		lua_getfield(L, -1, k);
+		
+		if(!lua_isuserdata(L, -1))
+			luaL_error(L, "Tried to get nonexisting module %s.", k);
+
+		Proxy * u = (Proxy *)lua_touserdata(L, -1);
+
+		if((u->flags & type) != type)
+			luaL_error(L, "Incorrect module %s", k);
+
+		lua_pop(L, 2);
+
+		return (T*)u->data;
+	}
+
 } // love
 } // love
 
 
 #endif // LOVE_RUNTIME_H
 #endif // LOVE_RUNTIME_H

+ 13 - 1
src/common/types.h

@@ -26,11 +26,12 @@
 
 
 namespace love
 namespace love
 {
 {
-	enum
+	enum Type
 	{
 	{
 		// Cross-module types.
 		// Cross-module types.
 		OBJECT_ID = 0,
 		OBJECT_ID = 0,
 		DATA_ID,
 		DATA_ID,
+		MODULE_ID,
 
 
 		// Filesystem.
 		// Filesystem.
 		FILESYSTEM_FILE_ID,
 		FILESYSTEM_FILE_ID,
@@ -79,6 +80,11 @@ namespace love
 		PHYSICS_REVOLUTE_JOINT_ID,
 		PHYSICS_REVOLUTE_JOINT_ID,
 		PHYSICS_PULLEY_JOINT_ID,
 		PHYSICS_PULLEY_JOINT_ID,
 		PHYSICS_GEAR_JOINT_ID,
 		PHYSICS_GEAR_JOINT_ID,
+		
+		// The modules themselves. Only add abstracted modules here. 
+		MODULE_FILESYSTEM_ID,
+		MODULE_IMAGE_ID,
+		MODULE_SOUND_ID,
 
 
 		// Count the number of bits needed.
 		// Count the number of bits needed.
 		BIT_SIZE
 		BIT_SIZE
@@ -88,6 +94,7 @@ namespace love
 
 
 	const bits OBJECT_T = bits(1) << OBJECT_ID;
 	const bits OBJECT_T = bits(1) << OBJECT_ID;
 	const bits DATA_T = (bits(1) << DATA_ID) | OBJECT_T;
 	const bits DATA_T = (bits(1) << DATA_ID) | OBJECT_T;
+	const bits MODULE_T = (bits(1) << MODULE_ID) | OBJECT_T;
 
 
 	// Filesystem. 
 	// Filesystem. 
 	const bits FILESYSTEM_FILE_T = (bits(1) << FILESYSTEM_FILE_ID) | OBJECT_T;
 	const bits FILESYSTEM_FILE_T = (bits(1) << FILESYSTEM_FILE_ID) | OBJECT_T;
@@ -136,6 +143,11 @@ namespace love
 	const bits PHYSICS_PULLEY_JOINT_T = (bits(1) << PHYSICS_PULLEY_JOINT_ID) | PHYSICS_JOINT_T;
 	const bits PHYSICS_PULLEY_JOINT_T = (bits(1) << PHYSICS_PULLEY_JOINT_ID) | PHYSICS_JOINT_T;
 	const bits PHYSICS_GEAR_JOINT_T = (bits(1) << PHYSICS_GEAR_JOINT_ID) | PHYSICS_JOINT_T;
 	const bits PHYSICS_GEAR_JOINT_T = (bits(1) << PHYSICS_GEAR_JOINT_ID) | PHYSICS_JOINT_T;
 
 
+	// Modules.
+	const bits MODULE_FILESYSTEM_T = (bits(1) << MODULE_FILESYSTEM_ID) | MODULE_T;
+	const bits MODULE_IMAGE_T = (bits(1) << MODULE_IMAGE_ID) | MODULE_T;
+	const bits MODULE_SOUND_T = (bits(1) << MODULE_SOUND_ID) | MODULE_T;
+
 } // love
 } // love
 
 
 #endif // LOVE_TYPES_H
 #endif // LOVE_TYPES_H

+ 9 - 3
src/modules/audio/wrap_Audio.cpp

@@ -266,9 +266,15 @@ namespace audio
 		if(instance == 0)
 		if(instance == 0)
 			return luaL_error(L, "Could not open any audio module.");
 			return luaL_error(L, "Could not open any audio module.");
 
 
-		luax_register_gc(L, instance);
-
-		return luax_register_module(L, functions, types, 0, "audio");
+		WrappedModule w;
+		w.module = instance;
+		w.name = "audio";
+		w.flags = MODULE_T;
+		w.functions = functions;
+		w.types = types;
+		w.constants = 0;
+
+		return luax_register_module(L, w);
 	}
 	}
 
 
 } // audio
 } // audio

+ 10 - 4
src/modules/event/sdl/wrap_Event.cpp

@@ -72,7 +72,7 @@ namespace sdl
 	};
 	};
 
 
 	// List of constants.
 	// List of constants.
-	static const LuaConstant constants[] = {
+	static const Constant constants[] = {
 		{ "event_keypressed", Event::EVENT_KEYDOWN },
 		{ "event_keypressed", Event::EVENT_KEYDOWN },
 		{ "event_keyreleased", Event::EVENT_KEYUP },
 		{ "event_keyreleased", Event::EVENT_KEYUP },
 		{ "event_mousepressed", Event::EVENT_MOUSEBUTTONDOWN },
 		{ "event_mousepressed", Event::EVENT_MOUSEBUTTONDOWN },
@@ -97,9 +97,15 @@ namespace sdl
 			}
 			}
 		}
 		}
 
 
-		luax_register_gc(L, instance);
-
-		return luax_register_module(L, functions, 0, constants, "event");
+		WrappedModule w;
+		w.module = instance;
+		w.name = "event";
+		w.flags = MODULE_T;
+		w.functions = functions;
+		w.types = 0;
+		w.constants = constants;
+
+		return luax_register_module(L, w);
 	}
 	}
 
 
 } // sdl
 } // sdl

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

@@ -252,7 +252,7 @@ namespace physfs
 	};
 	};
 
 
 	// List of constants.
 	// List of constants.
-	static const LuaConstant constants[] = {
+	static const Constant constants[] = {
 		{ "file_closed", File::CLOSED },
 		{ "file_closed", File::CLOSED },
 		{ "file_read", File::READ },
 		{ "file_read", File::READ },
 		{ "file_write", File::WRITE },
 		{ "file_write", File::WRITE },
@@ -275,9 +275,15 @@ namespace physfs
 			}
 			}
 		}
 		}
 
 
-		luax_register_gc(L, instance);
+		WrappedModule w;
+		w.module = instance;
+		w.name = "filesystem";
+		w.flags = MODULE_FILESYSTEM_T;
+		w.functions = functions;
+		w.types = types;
+		w.constants = constants;
 
 
-		return luax_register_module(L, functions, types, constants, "filesystem");
+		return luax_register_module(L, w);
 	}
 	}
 
 
 } // physfs
 } // physfs

+ 9 - 3
src/modules/font/freetype/wrap_Font.cpp

@@ -80,9 +80,15 @@ namespace freetype
 			}
 			}
 		}
 		}
 
 
-		luax_register_gc(L, instance);
-
-		return luax_register_module(L, functions, types, 0, "font");
+		WrappedModule w;
+		w.module = instance;
+		w.name = "font";
+		w.flags = MODULE_T;
+		w.functions = functions;
+		w.types = types;
+		w.constants = 0;
+
+		return luax_register_module(L, w);
 	}
 	}
 
 
 } // freetype
 } // freetype

+ 2 - 61
src/modules/graphics/opengl/Graphics.cpp

@@ -22,10 +22,6 @@
 
 
 // LOVE
 // LOVE
 #include <common/config.h>
 #include <common/config.h>
-#include <image/devil/Image.h>
-
-// IL
-#include <IL/ilu.h>
 
 
 namespace love
 namespace love
 {
 {
@@ -1177,70 +1173,15 @@ namespace opengl
 		return 0;
 		return 0;
 	}
 	}
 
 
-	love::image::ImageData * Graphics::newScreenshot(lua_State * L)
+	love::image::ImageData * Graphics::newScreenshot(love::image::Image * image)
 	{
 	{
-		
 		int w = getWidth();
 		int w = getWidth();
 		int h = getHeight();
 		int h = getHeight();
 		
 		
-		love::image::devil::Image * i = new love::image::devil::Image();
-		love::image::ImageData * img = i->newImageData(w, h);
-		
 		GLubyte * pixels = new GLubyte[4*w*h];
 		GLubyte * pixels = new GLubyte[4*w*h];
-		
 		glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
 		glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
-		
-		try {
-			img = i->newImageData(w, h, pixels);
-		} catch (Exception & e) {
-			luaL_error(L, e.what());
-		}
-		
-		// the screenshot is upside down, let's fix this
-		iluFlipImage();
-		
-		delete [] pixels;
-		
-		return img;
-		
-		// TODO: update this.
-		/*
-		int w = getWidth();
-		int h = getHeight();
-
-		// Declare some storage.
-		GLubyte * pixels = new GLubyte[3*w*h];
-		GLubyte * screenshot = new GLubyte[3*w*h];
-		ILuint image;
-
-		// Read the pixels on the screen.
-		glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, pixels);
-
-		ilGenImages(1, &image);
-		ilBindImage(image);
-		ilTexImage(w, h, 1, 3, IL_RGB, IL_UNSIGNED_BYTE, (ILvoid*)pixels);
-
-		delete [] pixels;
-
-		// Create the image.
-		ilSaveL(IL_BMP, screenshot, 3*w*h);
-
-		bool success = true;
-
-		if(file->open())
-		{
-			if(!file->write((const char *)screenshot, 3*w*h))
-				success = false;
-			file->close();
-		}
-		else
-			success = false;
-
-		delete [] screenshot;
-		ilDeleteImages(1, &image);
-		*/
 
 
-		return false;
+		return image->newImageData(w, h, (void*)pixels);
 	}
 	}
 
 
 	void Graphics::push()
 	void Graphics::push()

+ 2 - 1
src/modules/graphics/opengl/Graphics.h

@@ -33,6 +33,7 @@
 // LOVE
 // LOVE
 #include <graphics/Graphics.h>
 #include <graphics/Graphics.h>
 
 
+#include <image/Image.h>
 #include <image/ImageData.h>
 #include <image/ImageData.h>
 
 
 #include "Image.h"
 #include "Image.h"
@@ -518,7 +519,7 @@ namespace opengl
 		* Creates a screenshot of the view and saves it to the default folder.
 		* Creates a screenshot of the view and saves it to the default folder.
 		* @param file The file to write the screenshot to.
 		* @param file The file to write the screenshot to.
 		**/
 		**/
-		love::image::ImageData * newScreenshot(lua_State * L);
+		love::image::ImageData * newScreenshot(love::image::Image * image);
 
 
 		void push();
 		void push();
 		void pop();
 		void pop();

+ 12 - 4
src/modules/graphics/opengl/wrap_Graphics.cpp

@@ -479,7 +479,8 @@ namespace opengl
 	
 	
 	int w_newScreenshot(lua_State * L)
 	int w_newScreenshot(lua_State * L)
 	{
 	{
-		love::image::ImageData * i = instance->newScreenshot(L);
+		love::image::Image * image = luax_getmodule<love::image::Image>(L, "image", MODULE_IMAGE_T);
+		love::image::ImageData * i = instance->newScreenshot(image);
 		luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void *)i);
 		luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void *)i);
 		return 1;
 		return 1;
 	}
 	}
@@ -795,7 +796,7 @@ namespace opengl
 	};
 	};
 
 
 	// List of constants.
 	// List of constants.
-	static const LuaConstant constants[] = {
+	static const Constant constants[] = {
 
 
 		{ "align_left", Graphics::ALIGN_LEFT },
 		{ "align_left", Graphics::ALIGN_LEFT },
 		{ "align_right", Graphics::ALIGN_RIGHT },
 		{ "align_right", Graphics::ALIGN_RIGHT },
@@ -860,8 +861,15 @@ namespace opengl
 			}
 			}
 		}
 		}
 
 
-		luax_register_gc(L, instance);
-		luax_register_module(L, functions, types, constants, "graphics");		
+		WrappedModule w;
+		w.module = instance;
+		w.name = "graphics";
+		w.flags = MODULE_T;
+		w.functions = functions;
+		w.types = types;
+		w.constants = constants;
+
+		luax_register_module(L, w);
 
 
 #		include <scripts/graphics.lua.h>
 #		include <scripts/graphics.lua.h>
 
 

+ 1 - 1
src/modules/image/devil/ImageData.cpp

@@ -99,7 +99,7 @@ namespace devil
 		// Bind the image.
 		// Bind the image.
 		ilBindImage(image);
 		ilBindImage(image);
 		// Try to load the data.
 		// Try to load the data.
-		bool success = ilTexImage(width, height, 1, bpp, IL_RGBA, IL_UNSIGNED_BYTE, data);
+		bool success = (ilTexImage(width, height, 1, bpp, IL_RGBA, IL_UNSIGNED_BYTE, data) == IL_TRUE);
 		int err = ilGetError();
 		int err = ilGetError();
 		if (err != IL_NO_ERROR){
 		if (err != IL_NO_ERROR){
 			switch (err) {
 			switch (err) {

+ 9 - 3
src/modules/image/wrap_Image.cpp

@@ -92,9 +92,15 @@ namespace image
 			}
 			}
 		}
 		}
 
 
-		luax_register_gc(L, instance);
-
-		return luax_register_module(L, functions, types, 0, "image");
+		WrappedModule w;
+		w.module = instance;
+		w.name = "image";
+		w.flags = MODULE_IMAGE_T;
+		w.functions = functions;
+		w.types = types;
+		w.constants = 0;
+
+		return luax_register_module(L, w);
 	}
 	}
 
 
 } // image
 } // image

+ 10 - 3
src/modules/joystick/sdl/wrap_Joystick.cpp

@@ -146,7 +146,7 @@ namespace sdl
 	};
 	};
 
 
 	// List of constants.
 	// List of constants.
-	static const LuaConstant constants[] = {
+	static const Constant constants[] = {
 		{ "joystick_axis_horizontal", Joystick::JOYSTICK_AXIS_HORIZONTAL },
 		{ "joystick_axis_horizontal", Joystick::JOYSTICK_AXIS_HORIZONTAL },
 		{ "joystick_axis_vertical", Joystick::JOYSTICK_AXIS_VERITCAL },
 		{ "joystick_axis_vertical", Joystick::JOYSTICK_AXIS_VERITCAL },
 
 
@@ -176,9 +176,16 @@ namespace sdl
 			}
 			}
 		}
 		}
 
 
-		luax_register_gc(L, instance);
 
 
-		return luax_register_module(L, functions, 0, constants, "joystick");
+		WrappedModule w;
+		w.module = instance;
+		w.name = "joystick";
+		w.flags = MODULE_T;
+		w.functions = functions;
+		w.types = 0;
+		w.constants = constants;
+
+		return luax_register_module(L, w);
 	}
 	}
 
 
 } // sdl
 } // sdl

+ 10 - 4
src/modules/keyboard/sdl/wrap_Keyboard.cpp

@@ -65,7 +65,7 @@ namespace sdl
 	};
 	};
 
 
 	// List of constants.
 	// List of constants.
-	static const LuaConstant constants[] = {
+	static const Constant constants[] = {
 		{ "key_unknown", 0 },
 		{ "key_unknown", 0 },
 		{ "key_first", 0 },
 		{ "key_first", 0 },
 		{ "key_backspace", 8 },
 		{ "key_backspace", 8 },
@@ -232,9 +232,15 @@ namespace sdl
 			}
 			}
 		}
 		}
 
 
-		luax_register_gc(L, instance);
-
-		return luax_register_module(L, functions, 0, constants, "keyboard");
+		WrappedModule w;
+		w.module = instance;
+		w.name = "keyboard";
+		w.flags = MODULE_T;
+		w.functions = functions;
+		w.types = 0;
+		w.constants = constants;
+
+		return luax_register_module(L, w);
 	}
 	}
 
 
 } // sdl
 } // sdl

+ 10 - 4
src/modules/mouse/sdl/wrap_Mouse.cpp

@@ -105,7 +105,7 @@ namespace sdl
 	};
 	};
 
 
 	// List of constants.
 	// List of constants.
-	static const LuaConstant constants[] = {
+	static const Constant constants[] = {
 		{ "mouse_left", Mouse::MOUSE_LEFT },
 		{ "mouse_left", Mouse::MOUSE_LEFT },
 		{ "mouse_middle", Mouse::MOUSE_MIDDLE },
 		{ "mouse_middle", Mouse::MOUSE_MIDDLE },
 		{ "mouse_right", Mouse::MOUSE_RIGHT },
 		{ "mouse_right", Mouse::MOUSE_RIGHT },
@@ -129,9 +129,15 @@ namespace sdl
 			}
 			}
 		}
 		}
 
 
-		luax_register_gc(L, instance);
-
-		return luax_register_module(L, functions, 0, constants, "mouse");
+		WrappedModule w;
+		w.module = instance;
+		w.name = "mouse";
+		w.flags = MODULE_T;
+		w.functions = functions;
+		w.types = 0;
+		w.constants = constants;
+
+		return luax_register_module(L, w);
 	}
 	}
 
 
 } // sdl
 } // sdl

+ 9 - 3
src/modules/native/tcc/wrap_Native.cpp

@@ -137,9 +137,15 @@ namespace tcc
 
 
 		luax_register_searcher(L, searcher);
 		luax_register_searcher(L, searcher);
 
 
-		luax_register_gc(L, instance);
-
-		return luax_register_module(L, functions, 0, 0, "native");
+		WrappedModule w;
+		w.module = instance;
+		w.name = "native";
+		w.flags = MODULE_T;
+		w.functions = functions;
+		w.types = 0;
+		w.constants = 0;
+
+		return luax_register_module(L, w);
 	}
 	}
 
 
 } // tcc
 } // tcc

+ 10 - 2
src/modules/physics/box2d/wrap_Physics.cpp

@@ -237,7 +237,7 @@ namespace box2d
 	};
 	};
 
 
 	// List of constants.
 	// List of constants.
-	static const LuaConstant constants[] = {
+	static const Constant constants[] = {
 		{ "shape_circle", Shape::SHAPE_CIRCLE },
 		{ "shape_circle", Shape::SHAPE_CIRCLE },
 		{ "shape_polygon", Shape::SHAPE_POLYGON },
 		{ "shape_polygon", Shape::SHAPE_POLYGON },
 
 
@@ -264,7 +264,15 @@ namespace box2d
 			}
 			}
 		}
 		}
 
 
-		return luax_register_module(L, functions, types, constants, "physics");
+		WrappedModule w;
+		w.module = instance;
+		w.name = "physics";
+		w.flags = MODULE_T;
+		w.functions = functions;
+		w.types = types;
+		w.constants = constants;
+
+		return luax_register_module(L, w);
 	}
 	}
 
 
 } // box2d
 } // box2d

+ 10 - 3
src/modules/signal/posix/wrap_Signal.cpp

@@ -62,7 +62,7 @@ namespace posix
 		{ 0, 0 }
 		{ 0, 0 }
 	};
 	};
 	
 	
-	static const LuaConstant constants[] = {
+	static const Constant constants[] = {
 		{ "signal_abrt", SIGABRT },
 		{ "signal_abrt", SIGABRT },
 		{ "signal_fpe", SIGFPE },
 		{ "signal_fpe", SIGFPE },
 		{ "signal_ill", SIGILL },
 		{ "signal_ill", SIGILL },
@@ -86,9 +86,16 @@ namespace posix
 			}
 			}
 		}
 		}
 
 
-		luax_register_gc(L, instance);
+
+		WrappedModule w;
+		w.module = instance;
+		w.name = "signal";
+		w.flags = MODULE_T;
+		w.functions = functions;
+		w.types = 0;
+		w.constants = constants;
 
 
-		return luax_register_module(L, functions, 0, constants, "signal");
+		return luax_register_module(L, w);
 	}
 	}
 
 
 } // posix
 } // posix

+ 9 - 2
src/modules/sound/wrap_Sound.cpp

@@ -128,9 +128,16 @@ namespace sound
 			}
 			}
 		}
 		}
 
 
-		luax_register_gc(L, instance);
 
 
-		return luax_register_module(L, functions, types, 0, "sound");
+		WrappedModule w;
+		w.module = instance;
+		w.name = "sound";
+		w.flags = MODULE_SOUND_T;
+		w.functions = functions;
+		w.types = types;
+		w.constants = 0;
+
+		return luax_register_module(L, w);
 	}
 	}
 
 
 } // sound
 } // sound

+ 9 - 3
src/modules/timer/sdl/wrap_Timer.cpp

@@ -85,9 +85,15 @@ namespace sdl
 			}
 			}
 		}
 		}
 
 
-		luax_register_gc(L, instance);
-
-		return luax_register_module(L, functions, 0, 0, "timer");
+		WrappedModule w;
+		w.module = instance;
+		w.name = "timer";
+		w.flags = MODULE_T;
+		w.functions = functions;
+		w.types = 0;
+		w.constants = 0;
+
+		return luax_register_module(L, w);
 	}
 	}
 
 
 } // sdl
 } // sdl