static int intf_format_list(lua_State* L) { const t_string empty = luaW_checktstring(L, 1); auto values = lua_check<std::vector<t_string>>(L, 2); lua_push(L, (conjunct ? utils::format_conjunct_list : utils::format_disjunct_list)(empty, values)); return 1; }
static int intf_format(lua_State* L) { config cfg = luaW_checkconfig(L, 2); config_variable_set variables(cfg); if(lua_isstring(L, 1)) { std::string str = lua_tostring(L, 1); lua_push(L, utils::interpolate_variables_into_string(str, variables)); return 1; } t_string str = luaW_checktstring(L, 1); lua_push(L, utils::interpolate_variables_into_tstring(str, variables)); return 1; }
/** * Logs a deprecation message. See deprecation.cpp for details * Arg 1: Element to be deprecated. * Arg 2: Deprecation level. * Arg 3: Version when element may be removed. * Arg 4: Additional detail message. */ static int intf_deprecated_message(lua_State* L) { const std::string elem = luaL_checkstring(L, 1); // This could produce an invalid deprecation level, but that possibility is handled in deprecated_message() const DEP_LEVEL level = DEP_LEVEL(luaL_checkinteger(L, 2)); const std::string ver_str = lua_isnoneornil(L, 3) ? "" : luaL_checkstring(L, 3); const std::string detail = luaW_checktstring(L, 4); const version_info ver = ver_str.empty() ? game_config::wesnoth_version.str() : ver_str; const std::string msg = deprecated_message(elem, level, ver, detail); if(level < DEP_LEVEL::INDEFINITE || level >= DEP_LEVEL::REMOVED) { // Invalid deprecation level or level 4 deprecation should raise an interpreter error lua_push(L, msg); return lua_error(L); } return 0; }
/** * Sets the value of a widget on the current dialog. * - Arg 1: scalar. * - Args 2..n: path of strings and integers. */ int intf_set_dialog_value(lua_State *L) { gui2::twidget *w = find_widget(L, 2, false); #ifdef GUI2_EXPERIMENTAL_LISTBOX if (gui2::tlist *l = dynamic_cast<gui2::tlist *>(w)) #else if (gui2::tlistbox *l = dynamic_cast<gui2::tlistbox *>(w)) #endif { int v = luaL_checkinteger(L, 1); int n = l->get_item_count(); if (1 <= v && v <= n) l->select_row(v - 1); else return luaL_argerror(L, 1, "out of bounds"); } else if (gui2::tmulti_page *l = dynamic_cast<gui2::tmulti_page *>(w)) { int v = luaL_checkinteger(L, 1); int n = l->get_page_count(); if (1 <= v && v <= n) l->select_page(v - 1); else return luaL_argerror(L, 1, "out of bounds"); } else if (gui2::tselectable_ *s = dynamic_cast<gui2::tselectable_ *>(w)) { s->set_value(luaW_toboolean(L, 1)); } else if (gui2::ttext_box *t = dynamic_cast<gui2::ttext_box *>(w)) { const t_string& text = luaW_checktstring(L, 1); t->set_value(text.str()); } else if (gui2::tslider *s = dynamic_cast<gui2::tslider *>(w)) { const int v = luaL_checkinteger(L, 1); const int m = s->get_minimum_value(); const int n = s->get_maximum_value(); if (m <= v && v <= n) s->set_value(v); else return luaL_argerror(L, 1, "out of bounds"); } else if (gui2::tprogress_bar *p = dynamic_cast<gui2::tprogress_bar *>(w)) { const int v = luaL_checkinteger(L, 1); if (0 <= v && v <= 100) p->set_percentage(v); else return luaL_argerror(L, 1, "out of bounds"); } else { t_string v = luaW_checktstring(L, 1); gui2::tcontrol *c = dynamic_cast<gui2::tcontrol *>(w); if (!c) return luaL_argerror(L, lua_gettop(L), "unsupported widget"); c->set_label(v); } return 0; }
typename boost::enable_if<typename boost::is_same<T, t_string>::type, t_string>::type lua_check(lua_State *L, int n) { return luaW_checktstring(L, n); }