lua: Fix segfault in messagebox.exec at 'align' and 'default'

- Set default values for 'show_buttons' and 'default_button'
   to the correct value
 - Set Lua api version to 1.60

Signed-off-by: M. Liebmann <tuxcode.bbg@gmail.com>
This commit is contained in:
TangoCash
2016-09-10 18:58:43 +02:00
committed by M. Liebmann
parent aa8a3849f4
commit 24dd6a8c22
2 changed files with 6 additions and 8 deletions

View File

@@ -4,4 +4,4 @@
* to luainstance.h changes * to luainstance.h changes
*/ */
#define LUA_API_VERSION_MAJOR 1 #define LUA_API_VERSION_MAJOR 1
#define LUA_API_VERSION_MINOR 59 #define LUA_API_VERSION_MINOR 60

View File

@@ -66,15 +66,13 @@ int CLuaInstMessagebox::MessageboxExec(lua_State *L)
tableLookup(L, "name", name) || tableLookup(L, "title", name) || tableLookup(L, "caption", name); tableLookup(L, "name", name) || tableLookup(L, "title", name) || tableLookup(L, "caption", name);
tableLookup(L, "text", text); tableLookup(L, "text", text);
tableLookup(L, "icon", icon); tableLookup(L, "icon", icon);
lua_Integer timeout = -1, width = 450, return_default_on_timeout = 0, show_buttons = 0, default_button = 0; lua_Integer timeout = -1, width = 450, return_default_on_timeout = 0, show_buttons = CMessageBox::mbAll, default_button = CMessageBox::mbrYes;
tableLookup(L, "timeout", timeout); tableLookup(L, "timeout", timeout);
tableLookup(L, "width", width); tableLookup(L, "width", width);
tableLookup(L, "return_default_on_timeout", return_default_on_timeout); tableLookup(L, "return_default_on_timeout", return_default_on_timeout);
std::string tmp; std::string tmp;
if (tableLookup(L, "align", tmp)) { if (tableLookup(L, "align", tmp)) {
lua_pushvalue(L, -2);
const char *val = lua_tostring(L, -2);
table_key mb[] = { table_key mb[] = {
{ "center1", CMessageBox::mbBtnAlignCenter1 }, { "center1", CMessageBox::mbBtnAlignCenter1 },
{ "center2", CMessageBox::mbBtnAlignCenter2 }, { "center2", CMessageBox::mbBtnAlignCenter2 },
@@ -82,8 +80,9 @@ int CLuaInstMessagebox::MessageboxExec(lua_State *L)
{ "right", CMessageBox::mbBtnAlignRight }, { "right", CMessageBox::mbBtnAlignRight },
{ NULL, 0 } { NULL, 0 }
}; };
show_buttons = 0;
for (int i = 0; mb[i].name; i++) for (int i = 0; mb[i].name; i++)
if (!strcmp(mb[i].name, val)) { if (!strcmp(mb[i].name, tmp.c_str())) {
show_buttons |= mb[i].code; show_buttons |= mb[i].code;
break; break;
} }
@@ -119,10 +118,9 @@ int CLuaInstMessagebox::MessageboxExec(lua_State *L)
{ NULL, 0 } { NULL, 0 }
}; };
if (tableLookup(L, "default", tmp)) { if (tableLookup(L, "default", tmp)) {
lua_pushvalue(L, -2); default_button = 0;
const char *val = lua_tostring(L, -2);
for (int i = 0; mbr[i].name; i++) for (int i = 0; mbr[i].name; i++)
if (!strcmp(mbr[i].name, val)) { if (!strcmp(mbr[i].name, tmp.c_str())) {
default_button = mbr[i].code; default_button = mbr[i].code;
break; break;
} }