Browse Source

Rearranged love.window.showMessageBox' arguments so the messagebox type is the second-last argument and defaults to "info" (resolves issue #937.)

Alex Szpakowski 11 years ago
parent
commit
d3e1993673

+ 1 - 1
src/modules/window/Window.h

@@ -165,7 +165,7 @@ public:
 
 
 	virtual const void *getHandle() const = 0;
 	virtual const void *getHandle() const = 0;
 
 
-	virtual bool showMessageBox(MessageBoxType type, const std::string &title, const std::string &message, bool attachtowindow) = 0;
+	virtual bool showMessageBox(const std::string &title, const std::string &message, MessageBoxType type, bool attachtowindow) = 0;
 	virtual int showMessageBox(const MessageBoxData &data) = 0;
 	virtual int showMessageBox(const MessageBoxData &data) = 0;
 
 
 	//virtual static Window *createSingleton() = 0;
 	//virtual static Window *createSingleton() = 0;

+ 1 - 1
src/modules/window/sdl/Window.cpp

@@ -773,7 +773,7 @@ SDL_MessageBoxFlags Window::convertMessageBoxType(MessageBoxType type) const
 	}
 	}
 }
 }
 
 
-bool Window::showMessageBox(MessageBoxType type, const std::string &title, const std::string &message, bool attachtowindow)
+bool Window::showMessageBox(const std::string &title, const std::string &message, MessageBoxType type, bool attachtowindow)
 {
 {
 	SDL_MessageBoxFlags flags = convertMessageBoxType(type);
 	SDL_MessageBoxFlags flags = convertMessageBoxType(type);
 	SDL_Window *sdlwindow = attachtowindow ? window : nullptr;
 	SDL_Window *sdlwindow = attachtowindow ? window : nullptr;

+ 1 - 1
src/modules/window/sdl/Window.h

@@ -95,7 +95,7 @@ public:
 
 
 	const void *getHandle() const;
 	const void *getHandle() const;
 
 
-	bool showMessageBox(MessageBoxType type, const std::string &title, const std::string &message, bool attachtowindow);
+	bool showMessageBox(const std::string &title, const std::string &message, MessageBoxType type, bool attachtowindow);
 	int showMessageBox(const MessageBoxData &data);
 	int showMessageBox(const MessageBoxData &data);
 
 
 	static love::window::Window *createSingleton();
 	static love::window::Window *createSingleton();

+ 17 - 12
src/modules/window/wrap_Window.cpp

@@ -421,32 +421,29 @@ int w_minimize(lua_State* /*L*/)
 int w_showMessageBox(lua_State *L)
 int w_showMessageBox(lua_State *L)
 {
 {
 	Window::MessageBoxData data = {};
 	Window::MessageBoxData data = {};
+	data.type = Window::MESSAGEBOX_INFO;
 
 
-	const char *typestr = luaL_checkstring(L, 1);
-	if (!Window::getConstant(typestr, data.type))
-		return luaL_error(L, "Invalid messagebox type: %s", typestr);
-
-	data.title = luaL_checkstring(L, 2);
-	data.message = luaL_checkstring(L, 3);
+	data.title = luaL_checkstring(L, 1);
+	data.message = luaL_checkstring(L, 2);
 
 
 	// If we have a table argument, we assume a list of button names, which
 	// If we have a table argument, we assume a list of button names, which
 	// means we should use the more complex message box API.
 	// means we should use the more complex message box API.
-	if (lua_istable(L, 4))
+	if (lua_istable(L, 3))
 	{
 	{
-		size_t numbuttons = lua_objlen(L, 4);
+		size_t numbuttons = lua_objlen(L, 3);
 		if (numbuttons == 0)
 		if (numbuttons == 0)
 			return luaL_error(L, "Must have at least one messagebox button.");
 			return luaL_error(L, "Must have at least one messagebox button.");
 
 
 		// Array of button names.
 		// Array of button names.
 		for (size_t i = 0; i < numbuttons; i++)
 		for (size_t i = 0; i < numbuttons; i++)
 		{
 		{
-			lua_rawgeti(L, 4, i + 1);
+			lua_rawgeti(L, 3, i + 1);
 			data.buttons.push_back(luax_checkstring(L, -1));
 			data.buttons.push_back(luax_checkstring(L, -1));
 			lua_pop(L, 1);
 			lua_pop(L, 1);
 		}
 		}
 
 
 		// Optional table entry specifying the button to use when enter is pressed.
 		// Optional table entry specifying the button to use when enter is pressed.
-		lua_getfield(L, 4, "enterbutton");
+		lua_getfield(L, 3, "enterbutton");
 		if (!lua_isnoneornil(L, -1))
 		if (!lua_isnoneornil(L, -1))
 			data.enterButtonIndex = luaL_checkint(L, -1) - 1;
 			data.enterButtonIndex = luaL_checkint(L, -1) - 1;
 		else
 		else
@@ -454,13 +451,17 @@ int w_showMessageBox(lua_State *L)
 		lua_pop(L, 1);
 		lua_pop(L, 1);
 
 
 		// Optional table entry specifying the button to use when esc is pressed.
 		// Optional table entry specifying the button to use when esc is pressed.
-		lua_getfield(L, 4, "escapebutton");
+		lua_getfield(L, 3, "escapebutton");
 		if (!lua_isnoneornil(L, -1))
 		if (!lua_isnoneornil(L, -1))
 			data.escapeButtonIndex = luaL_checkint(L, -1) - 1;
 			data.escapeButtonIndex = luaL_checkint(L, -1) - 1;
 		else
 		else
 			data.escapeButtonIndex = (int) data.buttons.size() - 1;
 			data.escapeButtonIndex = (int) data.buttons.size() - 1;
 		lua_pop(L, 1);
 		lua_pop(L, 1);
 
 
+		const char *typestr = lua_isnoneornil(L, 4) ? nullptr : luaL_checkstring(L, 4);
+		if (typestr && !Window::getConstant(typestr, data.type))
+			return luaL_error(L, "Invalid messagebox type: %s", typestr);
+
 		data.attachToWindow = luax_optboolean(L, 5, true);
 		data.attachToWindow = luax_optboolean(L, 5, true);
 
 
 		int pressedbutton = instance()->showMessageBox(data);
 		int pressedbutton = instance()->showMessageBox(data);
@@ -468,10 +469,14 @@ int w_showMessageBox(lua_State *L)
 	}
 	}
 	else
 	else
 	{
 	{
+		const char *typestr = lua_isnoneornil(L, 3) ? nullptr : luaL_checkstring(L, 3);
+		if (typestr && !Window::getConstant(typestr, data.type))
+			return luaL_error(L, "Invalid messagebox type: %s", typestr);
+
 		data.attachToWindow = luax_optboolean(L, 4, true);
 		data.attachToWindow = luax_optboolean(L, 4, true);
 
 
 		// Display a simple message box.
 		// Display a simple message box.
-		bool success = instance()->showMessageBox(data.type, data.title, data.message, data.attachToWindow);
+		bool success = instance()->showMessageBox(data.title, data.message, data.type, data.attachToWindow);
 		luax_pushboolean(L, success);
 		luax_pushboolean(L, success);
 	}
 	}