[lua] Add possibility to change dialog title with Dialog:modify{ title=... }

This commit is contained in:
David Capello 2020-04-07 11:14:06 -03:00
parent bb8d0e7a6a
commit 4eefb84cf3

View File

@ -725,8 +725,21 @@ int Dialog_modify(lua_State* L)
id = lua_tostring(L, -1);
lua_pop(L, 1);
if (!id)
return luaL_error(L, "Missing 'id' field in Dialog:modify{ id=... }");
// Modify window itself when no ID is specified
if (id == nullptr) {
// "title" or "text" is the same for dialogs
type = lua_getfield(L, 2, "title");
if (type == LUA_TNIL) {
lua_pop(L, 1);
type = lua_getfield(L, 2, "text");
}
if (const char* s = lua_tostring(L, -1)) {
dlg->window.setText(s);
relayout = true;
}
lua_pop(L, 1);
return 0;
}
// Here we could use dlg->window.findChild(id) but why not use the
// map directly (it should be faster than iterating over all