C lua functions item.name_coloured() (which gives strings like "<lightgreen>a chunk of golden dragon flesh</lightgreen>") and crawl.formatted_mpr().
Could someone commit this to branch for me? Thanks.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@6653 c06c8d41-db1a-0410-9941-cceddc491573
53QXO6XQ6QAKCN6T5ADIKZM6UZCSAOAVKIJBHRN56BUVA653OZFAC
}
static std::string _item_name(lua_State *ls, item_def* item)
{
description_level_type ndesc = DESC_PLAIN;
if (lua_isstring(ls, 2))
ndesc = description_type_by_name(lua_tostring(ls, 2));
else if (lua_isnumber(ls, 2))
ndesc = static_cast<description_level_type>(luaL_checkint(ls, 2));
bool terse = lua_toboolean(ls, 3);
return (item->name(ndesc, terse));
description_level_type ndesc = DESC_PLAIN;
if (lua_isstring(ls, 2))
ndesc = description_type_by_name(lua_tostring(ls, 2));
else if (lua_isnumber(ls, 2))
ndesc = static_cast<description_level_type>(luaL_checkint(ls, 2));
bool terse = lua_toboolean(ls, 3);
lua_pushstring(ls, item->name(ndesc, terse).c_str());
std::string name = _item_name(ls, item);
lua_pushstring(ls, name.c_str());
}
else
lua_pushnil(ls);
return (1);
}
static int l_item_name_coloured(lua_State *ls)
{
LUA_ITEM(item, 1);
if (item)
{
std::string name = _item_name(ls, item);
int col = menu_colour(name, menu_colour_item_prefix(*item));
std::string colstr = colour_to_str(col);
std::ostringstream out;
out << "<" << colstr << ">" << name << "</" << colstr << ">";
lua_pushstring(ls, out.str().c_str());
const char *message = luaL_checkstring(ls, 1);
if (!message)
return (0);
int ch = MSGCH_PLAIN;
if (lua_isnumber(ls, 2))
ch = luaL_checkint(ls, 2);
else
{
const char *channel = lua_tostring(ls, 2);
if (channel)
ch = str_to_channel(channel);
}
if (ch < 0 || ch >= NUM_MESSAGE_CHANNELS)
ch = MSGCH_PLAIN;
formatted_mpr(formatted_string::parse_string(message),
static_cast<msg_channel_type>(ch));
return (0);
}