From d3e1993673a16638c757fb3704424cb05478f5f2 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sun, 28 Sep 2014 15:37:56 -0300 Subject: [PATCH] Rearranged love.window.showMessageBox' arguments so the messagebox type is the second-last argument and defaults to "info" (resolves issue #937.) --- src/modules/window/Window.h | 2 +- src/modules/window/sdl/Window.cpp | 2 +- src/modules/window/sdl/Window.h | 2 +- src/modules/window/wrap_Window.cpp | 29 +++++++++++++++++------------ 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/modules/window/Window.h b/src/modules/window/Window.h index ecd7bd368..658974298 100644 --- a/src/modules/window/Window.h +++ b/src/modules/window/Window.h @@ -165,7 +165,7 @@ public: 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 static Window *createSingleton() = 0; diff --git a/src/modules/window/sdl/Window.cpp b/src/modules/window/sdl/Window.cpp index 89bb3a9c9..89cbab918 100644 --- a/src/modules/window/sdl/Window.cpp +++ b/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_Window *sdlwindow = attachtowindow ? window : nullptr; diff --git a/src/modules/window/sdl/Window.h b/src/modules/window/sdl/Window.h index 8f1416f14..7b30e3c9c 100644 --- a/src/modules/window/sdl/Window.h +++ b/src/modules/window/sdl/Window.h @@ -95,7 +95,7 @@ public: 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); static love::window::Window *createSingleton(); diff --git a/src/modules/window/wrap_Window.cpp b/src/modules/window/wrap_Window.cpp index b8418591b..94054be55 100644 --- a/src/modules/window/wrap_Window.cpp +++ b/src/modules/window/wrap_Window.cpp @@ -421,32 +421,29 @@ int w_minimize(lua_State* /*L*/) int w_showMessageBox(lua_State *L) { 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 // 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) return luaL_error(L, "Must have at least one messagebox button."); // Array of button names. 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)); lua_pop(L, 1); } // 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)) data.enterButtonIndex = luaL_checkint(L, -1) - 1; else @@ -454,13 +451,17 @@ int w_showMessageBox(lua_State *L) lua_pop(L, 1); // 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)) data.escapeButtonIndex = luaL_checkint(L, -1) - 1; else data.escapeButtonIndex = (int) data.buttons.size() - 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); int pressedbutton = instance()->showMessageBox(data); @@ -468,10 +469,14 @@ int w_showMessageBox(lua_State *L) } 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); // 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); }